Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

II (20 points) Write a COMPLETE C++ program (including comments!) that asks the

ID: 3891830 • Letter: I

Question

II (20 points) Write a COMPLETE C++ program (including comments!) that asks the user to input the number of total hours it took for the computer to process the result of a complicated program. The program then prints the duration of the job in a nicer form; i.e. it prints out the number of total weeks, then (for the part left over) days and (for the part left) hours that the job took. For example, if the user types in 362 for the hours, the output will be: 2 weeks (s) and 1 day(s) and 2 hours (s)

Explanation / Answer

Program

#include <iostream>

int main()
{
using namespace std;

int tothours,weeks,days,rem,hours;

cout << "Enter the total hours : ";
cin >> tothours;
//1 week = 7 days = 7 × 24 hours = 168 hours.There are 168 hours in a week.
weeks=tothours/168;
//Left over is tothours%168.There are 24 hours in a day.
days=(tothours%168)/24;
//Left over is tothours%168
hours=(tothours%168)%24;
cout <<" Duration of the job is "<<weeks<<" week(s) "<<days<<" day(s) "<<hours<<" hour(s) ";
return 0;
}

Output

Enter the total hours : 362
Duration of the job is 2 week(s) 1 day(s) 2 hour(s)