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

Write a C++ program that allows the user to enter time using hours and minutes.

ID: 3873172 • Letter: W

Question

Write a C++ program that allows the user to enter time using hours and minutes. (NOTE: Hours are to be between 1 and 12 while minutes are to be between 0 and 59.) Next ask the user how much time is to be added to the original time. Then display the new time. Finally, ask the user how much time to subtract and display the final time. The program needs to have a time class that is able to add and subtract the times using overloaded + and - operators to calculate the new time when the user adds or subtracts time from the original time and get functions to retrieve the hours and the minutes. Here is how the program should work. Ask the user for the hours and for the minutes. Create an object with the hours and minutes passed to it. Then ask the user how many hours to add and how many minutes to add. Create a second object with these new values. Also, create a third object without any values passed to it. Use the overloaded + operator to add the two objects together and place the result in the third object (ie. third first + second). Next call the get functions to display the hours and the minutes in the third object. Now ask the user how much time to subtract and (after creating a fourth object with the time to be subtracted and a fifth object without any values) use the overloaded operator to subtract the time from the third object (ie. fifth third -fourth) Finally, call get functions to display the hours and the minutes in the fifth object ake sure to have your class be in a separate file from your main Pogram and you must use overloaded + and - operators in your class for adding and subtracting time. Also, turn in a UML diagram Don't forgot to document your program

Explanation / Answer

#include<iostram.h>

#include<stdio.h>

using namespace std;

//all functions call be reference to allow them to modify variables

void input(int&, int&, char&);

void convert(int&, int&, char&);

void output(int&, int&, char&);

int main()

{

int hours, minutes;

char ampm;

char again;

//loop to re-run program

do

{

input(hours,minutes,ampm);

convert(hours,minutes,ampm);

output(hours,minutes,ampm);

cout<<endl << Enter Y to run again";

cin>> again;

}

while(again=='y' || again=='y');

return 0;

}

void input(int& hours, int& minutes, char& ampm)

\this loop make value entered legal

do

{

cout<<" Enter hours;

cin>> hours;

if(hours>12) cout<<" please enter value between 0 and 12";

}

while(hours>12);

//this loop make sure minutes value is between 0 and 59

do

{

cout<<"Enter minutes";

cin>>minutes;

if(minue>59)

cout<<"please enter a value between 0 and 59";

}

while( minute59);

}

void convert( int& hours, int& minutes, char& ampm)

{

if(hours>12)

{

hours=hours-12;

ampm='p';

}

else if(hours==12) ampm='p';

else ampm='a';

}

void output(int& hours, int& minutes, char& ampm)

{

if(ampm=='p')

{

if(minutes<10) cout<< hours<":0"<< minutes<<"P.M";

else cout << hours << ":" << minutes << " P.M.";

}

else

{

if(minutes<10) cout<< hours<":0"<< minutes<<"A.M";

else cout << hours << ":" << minutes << " A.M.";

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote