Write a function called hms_to_sec() that takes three int values – for hours, minutes, and seconds as arguments, and return the equivalents 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 the seconds it returns.
1
Expert's answer
2018-05-09T07:23:35-0400
#include <iostream> #include <stdio.h>
using namespace std;
//--------------------------------------------------------------------------- // Write a function called hms_to_sec() that takes three int values – // for hours, minutes, and seconds as arguments, and return the equivalents 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 the seconds it returns. //---------------------------------------------------------------------------
long hms_to_sec(int hours, int minutes, int seconds) { return (hours*60 + minutes) * 60 + seconds; }
main() { cout << "Input time value in hours, minutes and seconds (format 12:59:59)" << endl; cout << ">> "; char s[20]; cin >> s; cout << endl; int hours, minutes, seconds; sscanf(s,"%2d:%2d:%2d", &hours, &minutes, &seconds); cout << "Time is " << hours << ":" << minutes << ":" << seconds << endl; cout << "Number of the seconds is " << hms_to_sec(hours, minutes, seconds) << endl;
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments