Question: Modify in C++, c plus plus, cpp, the Time project below so that: 1) The Time fields hour minute and second can only be initialized
Modify in C++, c plus plus, cpp, the Time project below so that:
1) The Time fields hour minute and second can only be initialized to valid values.
2) The printStandardTime() and printUniversalTime() display time correctly for any valid time (am or pm).
//Main
#include
int main(int argc, char** argv) { Time mTime; mTime.setTime(18,12,30); mTime.printStandard(); mTime.printUniversal(); return 0; }
//Time.cpp
#include
// constructor Time::Time(){ hour = minute = second = 0; }
void Time::setTime(int h, int m, int s){ hour = h; minute = m; second = s; }
void Time::printStandard(){ cout << " " << hour << ":" << minute << ":" << second << endl; }
void Time::printUniversal(){ cout << " " << hour << ":" << minute << ":" << second << endl; }
//Time.h
#ifndef TIME_H #define TIME_H
class Time{ public: Time(); void setTime(int, int, int); void printUniversal(); void printStandard(); private: int hour; int minute; int second; }; #endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
