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 / jay

#include<iostream>
using namespace std;
int hms_to_sec(int hr,int min, int sec);
int main()
{
int hr,min,sec;


int result =hms_to_sec(hr,min,sec);
cout << "result = " << result;
return 0;
}

int hms_to_sec(int hr,int min, int sec)
{
int seconds =0;
cout << "please enter hr" << endl;
cin >> hr;
cout << "please enter min" << endl;
cin >> min;
cout << "please enter sec" << endl;
cin >> sec;

seconds = (hr*60*60)+(min*60)+sec;
return seconds;

}

Is This Answer Correct ?    20 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

if p is a string contained in a string?

1637


What is a lvalue

883


Give me the code of in-order recursive and non-recursive.

1153


Can a pointer be null?

785


Are comments included during the compilation stage and placed in the EXE file as well?

896


What is string function c?

805


console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above

879


What does static variable mean in c?

883


what is the height of tree if leaf node is at level 3. please explain

1863


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

1217


In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.

2907


What is optimization in c?

767


differentiate built-in functions and user – defined functions.

886


What are the features of c languages?

844


How do we print only part of a string in c?

827