2. 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..
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.
Answer Posted / htoo cherry
#include <iostream >
Using namespace std ;
long hms_to_secs (int, int, int) ;
int main ()
{int hrs, min, sec;
cout <<"Enter hours" <<endl ;cin>>hrs;
cout <<"Enter minutes " <<endl ;cin>>min;
cout <<"Enter seconds" <<endl ;cin <<sec;
cout <<hrs<<":" <<min<<":" <<sec<<":" <<endl ;
cout <<The time in seconds<<hms_to_secs (int hrs, int min, int sec) ;
}
long hms_to_secs (int h, int m, int s)
return( h*3600+m*60+s);
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
Explain data types & how many data types supported by c?
what will be maximum number of comparisons when number of elements are given?
What is void c?
What do the functions atoi(), itoa() and gcvt() do?
How do you convert strings to numbers in C?
What are near, far and huge pointers?
What is the difference between volatile and const volatile?
What does the format %10.2 mean when included in a printf statement?
What is assert and when would I use it?
Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.
What is class and object in c?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
What is calloc in c?
What does typedef struct mean?
Why do we use null pointer?