Question
im getting a error dont know why Time.h // Fig. 9.5: Time.h // Time class containing a constructor with default arguments. // Member functions defined
im getting a error dont know why
Time.h
// Fig. 9.5: Time.h
// Time class containing a constructor with default arguments.
// Member functions defined in Time.cpp.
#include
// prevent multiple inclusions of header
#ifndef TIME_H
#define TIME_H
// Time class definition
class Time {
public:
Time(int = 0, int = 0, int = 0); // default constructor
// set functions
void setTime(int, int, int); // set hour, minute, second
void setHour(int); // set hour (after validation)
void setMinute(int); // set minute (after validation)
void setSecond(int); // set second (after validation)
// get functions
int getHour(); // return hour
int getMinute(); // return minute
int getSecond(); // return second
void printUniversal();// 24-hour time format string
void printStandard(); // 12-hour time format string
void tick();
private:
int hour{ 0 }; // 0 - 23 (24-hour clock format)
int minute{ 0 }; // 0 - 59
int second{ 0 }; // 0 - 59
};
#endif
Time.cpp
#include
#include
#include
#include
#include
#include "Time.h" // include definition of class Time from Time.h
#include
using namespace std;
// Time constructor initializes each data member
Time::Time(int hour, int minute, int second)
{
setTime(hour, minute, second); // validate and set time
}
// set new Time value using universal time
void Time::setTime(int h, int m, int s) {
setHour(h); // set private field hour
setMinute(m); // set private field minute
setSecond(s); // set private field second
}
// set hour value
void Time::setHour(int h)
{
hour = (h > 0 && h < 24) ? h : 0;
}
// set minute value
void Time::setMinute(int m)
{
minute = (m >= 0 && m < 60) ? m : 0;
}
// set second value
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::printUniversal()
{
cout << " Time in universal format is" << setfill('0') << setw(2) << getHour() << ":" << setfill('0') << setw(2)
<< getMinute() << (":") << setfill('0') << setw(2) << getSecond();
}
void Time::printStandard()
{
cout << "n Time in standard for is " << setfill('0') << setw(2) << ((getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12) <<
":" << setfill('0') << setw(2) << getMinute() << ":" << (getHour() < 12 ? "am" : "pm");
}
void Time::tick()
{
second++;
if (second > 59)
{
minute++;
second = 0;
}
if (minute > 59)
{
hour++;
minute = 0;
}
if (hour > 23)
{
hour = 0;
}
}
Source.cpp(main)
#include "Time.cpp"
#include "Time.h"
#include
int main()
{
Time t;
int h,m,s;
int counter = 0;
t.setTime(23,59,55);
do
{
t.printStandard();
t.tick();
counter++;
}
while (counter < 10);
cout << " Whats the time";
cout << "Enter hours";
cin >> h;
cout << "minutes";
cin >> m;
cout << "seconds";
cin >> s;
t.setTime(h, m, s);
t.printUniversal();
t.printStandard();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started