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

Help me with designing this program. Thank you. Design and implement a Time user

ID: 3545142 • Letter: H

Question

Help me with designing this program. Thank you.


Design and implement a Time user-defined data type using a class. The class should be capable of storing the number of hours (in the precision of minutes) a person works in an office. For example, the user should be able to: Initialize the time object to zero or some initial value Add specified number of minutes Add specified number of hours Reset the time Sum the current object with the value contained in another time object Display the current time Create a library for your Time data structure by providing header files and implementation files separately. Include the library in your main program and demonstrate all the features of the time library.

Explanation / Answer

#include <iostream>


class Time {

private:

int hours;

int minutes;


public:

Time(int hrs, int mins) {

hours = hrs;

minutes = mins;

}


void addHours(int addhrs) {

hours += addhrs;

}


void addMinutes(int addmins) {

minutes += addmins;

if (minutes > 60) {

hours += (minutes/60);

minutes = minutes%60;

}

}


void resetTime(int hrs, int mins) {

hours = hrs;

minutes = mins;

}


void addTime(Time* time) {

hours += time->hours;

minutes += time->minutes;

}


void display() {

cout << " Current time is " << hours << " hours and " << minutes << " minutes" << endl;

}

}


int main() {

Time* t = new Time(0, 0);

t->addHours(2);

t->display();

t->addMinutes(70);

t->display();

t->resetTime(3, 40);

t->display();


Time* t2 = new Time(2, 10);

t->addTime(t2);

t->display();

return 0;

}