1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
// This program calls the Time class.
#include <iostream>
#include <iomanip>
#include "time.h"
using namespace std;
Time::Time() // Default constructer, initializes hour and minute to 00
{
hour = 00;
minute = 00;
}
Time::Time(int phour, int pmin) //calls the setTime setter
{
setTime(phour, pmin);
}
void Time::setTime(int phour, int pmin) //Checks to see if the hour or minute are over 23/59 respectively, and sets them to 0 if they are
{
if (phour < 0 || phour > 23 || pmin < 0 || pmin > 59)
{
hour = 0; // Hour getting set to 0
minute = 0; // Minute getting set to 0
}
else
{
hour = phour; // If the hour is between 0 and 23 it sets the hour to that time
minute = pmin; // If the minute is between 0 and 59 it sets the minute to that time
}
}
int Time::getHour() // Function getHour, which returns hour as an int
{
return hour;
}
void Time::addOneMinute() //Function addOneMinute, which adds one minute
{
minute++; //Minute being incremented
if (minute == 60) // If minute is 60 then minute goes back to 0 and hour gets incremented one
{
minute = 0;
hour++;
if (hour == 24) //If hour is 24 it gets set back to 0
hour = 0;
}
}
void Time::showmealtime() // Function showmealtime, which displays breakfast, lunch, dinner, or No meal, depending on the time
{
if (hour == 7)
cout << "Breakfast" << endl;
else if (hour == 12)
cout << "Lunch" << endl;
else if (hour == 17)
cout << "Dinner" << endl;
else
cout << "No Meal" << endl;
}
void Time::display() // Functoin display, which displays the time
{
cout << hour << ":" << setw(2) << setfill('0') << minute << endl;
}
Time Time::operator++() //Overloads the++ operator. The operation will add one minute to the time object.
{
minute++;
if (minute == 60)
{
minute = 00;
hour++;
}
return *this
}
Time Time::operator+(int Rval){
Time Tobj;
int temphour;
int tempmin;
temphour = this.hour + Rval;
tempmin = this.minute + Rval;
}
int Time::operator-(Time & Robj){
Time Tobj;
int temphour;
int tempmin;
temphour = this.hour - Robj;
tempmin = this.minute - Robj;
}
bool Time::operator>(Time & Robj){
if (this.hour > Robj.gethour()){
return true;
}
else if (this.hour < Robj.gethour()){
return false;
}
else if (this.hour == Robj.gethour()){
if (this.minutes > Robj.getminutes()){
return true;
}
else if (this.minutes < Robj.getminutes()){
return false;
}
else{
return false;
}
}
}
bool Time::operator==(Time & Robj){
bool hourMatch, MinMatch;
if (this.hour == Robj.gethour()){
hourMatch = true;
}
if (this.minute == Robj.gethour()){
MinMatch = true;
}
return (hourMatch && MinMatch);
}
ostream &operator<< (ostream &output, Time & Robj){
output << this.hours;
output << ":" << this.minutes;
return output;
}
istream &operator>> (istream &input, Time & Robj){
in >> Robj.hours;
in.ignore();
in >> Robj.mintues;
in.ignore();
return in;
}
|