Modularity using functions-Returning multiples values: A: Write a function named
ID: 3677502 • Letter: M
Question
Modularity using functions-Returning multiples values:
A: Write a function named time( ) that has an integer parameter named seconds and three integer reference parameters named hours, mins, and secs. The function is to convert the passed number of seconds into an equivalent number of hours, minutes, and seconds. Using the references, the function should directly alter the respective actual arguments in the calling function.
the Q&A posted in Chegg don't work. Please give me the correct answer, so the program can be runned and give an answer.
Explanation / Answer
Solution.cpp
#include <iostream>//input output function header file
using namespace std;//using namespace std; tells the compiler to use the std namespace.
void time(int, int*, int*, int*);//function declaration with one integer parameter and three ref parameters
int main()
{
int secs, hrs, min, sec;//variable declarations
cout << "Enter the time in seconds: " ;
cin >> secs;
time(secs, &hrs, &min, &sec);//calling functions
cout << "The changed time is => ";
cout << hrs << " hrs: " << min << " mins: " << sec<<"secs";
cout << endl;
cout << endl;
cout << " no of hours is: " << hrs;
cout << endl;
cout << " no of minutes is: " << min;
cout << endl;
cout << "no of seconds is: " << sec << " ";
return 0;
}
void time(int secnds, int *hrs, int *min, int *sec)
{//function time definitions
int temp;
*hrs = secnds/3600;//converting no of secs into hrs
temp = secnds%3600;
*min =temp/60;
*sec = temp%60;
}
output
Enter the time in seconds: 4567
The changed time is => 1 hrs:16 mins: 7secs
no of hours is: 1
no of minutes is: 16
no of seconds is: 7
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.