Anda di halaman 1dari 2

lab 3

1- Write a function called hms_to_secs() that takes three int values for hours,
minutes, and seconds—as arguments, and returns the equivalent time in
seconds (type long).Create a program that exercises this function by
repeatedly obtaining a time value in hours, minutes, and seconds from the
user (format 12:59:59), calling the function, and displaying the value of
seconds it returns.

2- Write a function called circarea() that finds the area of a circle. It should take an
argument of type float and return an argument of the same type. Write a main()
function that gets a radius value from the user, calls circarea(), and displays the
result.

3- Write a function, reverseDigit, that takes an integer as a parameter and returns


the number with its digits reversed. For example, the value of
reverseDigit(12345) is 54321; the value of reverseDigit(5600) is 65; the value of
reverseDigit(7008) is 8007; and the value of reverseDigit(-532) is -235.

4- Write a function that swaps the contents of two integer variables.

5- Write a recursive function to calculate the factorial of an integer number.

6- Write a C++ function, smallestIndex, that takes as parameters an int array and
its size and returns the index of the first occurrence of the smallest element in
the array.

7- Write a recursive function to search for an element in an array, the function


should take the array, the size of the array, and the element to search for as
parameters. The function should return the index of the element in the array if
found, and -1 otherwise.

8- Write a recursive Function to find the GCD. Write a test program that computes
gcd(24, 16) and gcd(255, 25).
9- Create a structure called employee that contains two
members: an employee number (type int) and the employee’s
compensation (in dollars; type float). Ask the user to fill in this
data for three employees, store it in three variables of type
struct employee, and then display the information for each
employee.

10- Create a structure called time. Its three members, all type int,
should be called hours, minutes, and seconds. Write a
program that prompts the user to enter a time value in hours,
minutes, and seconds. The program should then store the time
in a variable of type struct time, and finally print out the total
number of seconds represented by this time value:
long totalsecs = t1.hours*3600 + t1.minutes*60 + t1.seconds.

11- Use the time structure from Q2, and write a program that
obtains two time values from the user in 12:59:59 format,
stores them in struct time variables, converts each one to
seconds (type int), adds these quantities, converts the result
back to hours-minutes-seconds,
stores the result in a time structure, and finally displays the
result in 12:59:59 format.
12- Use the employee structure from Q1, Write a program that
sort an array in ascending order based on the employee’s
compensation.

13- Use the time structure from Q2, Write a function that take 2-
time as a parameter and return the summation of them.
Note: the same of Q3 using function.

Anda mungkin juga menyukai