Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Enter hours, minutes and seconds Testing tick Starting at 11:59:59PM Tick 0:00:00PM 24:00:00 //this is my output Enter hours, minutes and seconds Testing tick Starting

Enter hours, minutes and seconds Testing tick Starting at 11:59:59PM Tick 0:00:00PM 24:00:00 //this is my output

Enter hours, minutes and seconds Testing tick Starting at 11:59:59PM Tick 12:00:00AM 00:00:00 //This is what i want it to look like

#include #include using namespace std;

//this is the class declaration which will normally go in a separate header file class Time{ public: Time(int = 0, int = 0, int = 0); //constructor with default argumens void setTime(int, int, int); //sets the private data void setHour(int); void setMinute(int); void setSecond(int);

//get functions return the object's data values int getHour(); int getMinute(); int getSecond();

void output24Hour(); //outputs 24 hour time void output12Hour(); //outputs 12 hr AM/PM time void tick();

private: int hour; //0-23 int minute; //0-29 int second; //O-59 }; //end class Time

//This is the class implementation file. It is normally placed in its own file. //Time.cpp defines the member functions for the Time class

Time::Time(int h, int m, int s) { setTime(h, m, s); }

//sets private data hours, minutes and seconds to valid values or to 0 //h is 0..23, m and s are 0..59 void Time::setTime(int h, int m, int s) { if(h >= 0 && h < 24 ) hour = h; else hour = 0;

minute = (m >= 0 && m < 60 ) ? m : 0; second = (s >= 0 && s < 60 ) ? s : 0; }

void Time::setHour(int h) { if(h >= 0 && h < 24 ) hour = h; else hour = 0; }

void Time::setMinute(int m) { minute = (m >= 0 && m < 60 ) ? m : 0; }

void Time::setSecond(int s) { second = (s >= 0 && s < 60 ) ? s : 0; }

int Time::getHour() { return hour; }

int Time::getMinute() { return minute; }

int Time::getSecond() { return second; }

void Time::output24Hour() { cout << setfill('0') << setw(2) << hour << ":" << setw(2) << minute << ":" << setw(2) << second; }

void Time::output12Hour() { cout <<( (hour == 0 || hour == 12 ) ? 12: hour %12 ) << ":" << setfill('0') << setw(2) << minute << ":" << setw(2) << second << ((hour < 12 ) ? "AM" : "PM" ); }

void Time::tick() //adds one to the seconds and adjust minutes and hours as necessary { //write me if (second == 59) { setSecond(0); if (minute == 59) { setMinute(0); if (hour == 12) { setHour(0); } else hour++; } else minute++; } else second++; }

//This is the test main function. It normally is placed in its own file and //includes Time.h as in #include "Time.h" int main() { int hour, minute, second; cout << "Enter hours, minutes and seconds "; cin >> hour; cin >> minute; cin >> second; cout << endl; Time t(hour,minute,second); cout << "Testing tick "<

return 0; }

//^^ this is the code

Thanks in advance :)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

How can predictive analytics improve the speed of hiring?

Answered: 1 week ago