(Calculating Number of Seconds) Write a function that takes the time as three integer ar- guments (hours, minutes and seconds) and returns the number of seconds since the last time the clock “struck 12.” Use this function to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock.
What will be an ideal response?
```
// Calculate amount of time in seconds between two times.
#include
#include
using namespace std;
unsigned seconds( unsigned, unsigned, unsigned ); // function prototype
int main()
{
unsigned hours; // current time's hours
unsigned minutes; // current time's minutes
unsigned secs; // current time's seconds
double first; // first time, in seconds
double second; // second time, in seconds
double difference; // difference between two times, in seconds
cout << "Enter the first time as three integers: ";
cin >> hours >> minutes >> secs;
first = seconds( hours, minutes, secs ); // calculate first time
cout << "Enter the second time as three integers: ";
cin >> hours >> minutes >> secs;
second = seconds( hours, minutes, secs ); // calculate second time
difference = fabs( first - second ); // calculate difference
// display difference
cout << "The difference between the times is "
<< difference << " seconds" << endl;
} // end main
// seconds returns number of seconds since clock "struck 12"
// given input time as hours h, minutes m, seconds s
unsigned seconds( unsigned h, unsigned m, unsigned s )
{
return 3600 * ( h >= 12 ? h - 12 : h ) + 60 * m + s;
} // end function seconds
```
You might also like to view...
An advantage to using ________ is that you avoid repeatedly copying the data
Fill in the blank(s) with correct word
What type of network device keeps a table of the MAC addresses of the devices connected to it?
A. hub B. router C. NIC D. switch
What is a value that can be used to ensure that plaintext, when hashed, will not consistently result in the same digest?
A. salt B. initialization vector C. counter D. nonce
Which type of storage is used if data is saved to an SD card?
A. Internal B. Shared preferences C. External D. Network connection