Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am creating a class 'Event' that will take four data members: string description; string location; Date date ; Time time . The event constructor

I am creating a class 'Event' that will take four data members: string description; string location; Date date; Time time. The event constructor will take two strings, a time, and a date as input. The first is the description, the second is the location, third is time, fourth is date. The function hasPassed will return True if the event has passed. It will take a date and a time as input.

EVENT.CPP //Default Constructor //hasPassed function EVENT.H TIME.CPP #include "Time.h" #include  //Default Constructor Time::Time() { hour = minute = second = 0; } //Constructor with parameters Time::Time(int h, int m, int s) { hour = h; minute = m; second = s; if(h>23 || h<0) { h = 0; } if(m>59 || m<0) { m = 0; } if(s>59 || s<0) { s = 0; } } int Time::getHour() const { return hour; } int Time::getMinute() const { return minute; } int Time::getSecond() const { return second; } void Time::setHour(int h) { hour = h; } void Time::setMinute(int m) { minute = m; } void Time::setSecond(int s) { second = s; } int Time::timeToSeconds() const { return (getSecond() + getMinute() * 60 + getHour() * 3600); } const Time Time::secondsToTime(int s) const { int resultS = s % 60; s /= 60; int resultM = s % 60; s /= 60; int resultH = s % 24; return Time(resultH, resultM, resultS); } //toString string Time::toString() const { string s = to_string(hour); s = s+":"+to_string(minute); s = s+":"+to_string(second); return s; } // + const Time Time::operator+(const Time &other) const{ Time t; t.second = second+other.second; t.minute = t.second/60; t.second = t.second%60; t.minute += minute+other.minute; t.hour=t.minute/60; t.minute = t.minute%60; t.hour += hour+other.hour; t.hour = t.hour%24; return t; } // - const Time Time::operator-(const Time &other) const{ Time t; t.hour = hour-other.hour; t.minute = minute-other.minute; t.second = second-other.second; return t; } // < bool Time::operator<(const Time &other) const{ if(hour < other.hour) return true; else if (hour>other.hour) return false; else{ if(minuteother.minute) return false; else{ if(secondother.second) return false; else{ return false; } } } } // > bool Time::operator>(const Time &other) const{ if(hour>other.hour) { return true; } else if(hourother.minute) { return true; } else if(minuteother.second) { return true; } else if(second using namespace std; class Time { private: int hour; int minute; int second; int timeToSeconds() const; const Time secondsToTime(int s) const; public: Time(); Time(int h, int m, int s); string toString() const; int getHour() const; void setHour(int h); int getMinute() const; void setMinute(int m); int getSecond() const; void setSecond(int s); const Time operator+(const Time &other) const; const Time operator-(const Time &other) const; bool operator<(const Time &other) const; bool operator>(const Time &other) const; bool operator==(const Time &other) const; }; #endif OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO DATE.CPP #include "Date.h" //Default Constructor Date::Date() { setDay(1); setMonth(1); setYear(0); } //Constructor with parameters Date::Date(int d, int m, int y) { if (d <= 0 || d > 31) setDay(0); else setDay(d); if (m <= 0 || m > 12) setMonth(0); else setMonth(m); if (y < 0) setYear(0); else setYear(y); } int Date::getDay() const { return day; } int Date::getMonth() const { return month; } int Date::getYear() const { return year; } void Date::setDay(int h) { day = h; } void Date::setMonth(int m) { month = m; } void Date::setYear(int s) { year = s; } //dateToDays int Date::dateToDays() const { int days; // calculate number of days from 1/1/0 days = getYear()*372 + (getMonth()-1)*31 + getDay(); return days; } //daysToDate const Date Date::daysToDate(int ndays) const { Date date; int Year; int Month; int Day; if ((ndays%372)%31 == 0) { date.setDay(31); } else { date.setDay((ndays%372)%31); } if ((ndays%372)%31 == 0) { date.setMonth((ndays%372)/31); } else { date.setMonth((ndays%372)/31 + 1); } if ((ndays%372) == 0) { date.setYear((ndays/372) - 1); date.setMonth(12); } else { date.setYear(ndays/372); } if (date.getYear() < 0) { date.setDay(1); date.setMonth(1); date.setYear(0); } return date; } //toString string Date::toString() const { string s = to_string(year); s = s+"/"+to_string(month); s = s+"/"+to_string(day); return s; } /*string Time::toString() const { string s = to_string(hour); s = s+":"+to_string(minute); s = s+":"+to_string(second); return s;*/ // + const Date Date::operator+(int ndays) const { Date newDate; int days; days = dateToDays() + ndays; newDate = daysToDate(days); return newDate; } // - const Date Date::operator-(int ndays) const { Date newDate; int days; days = dateToDays() - ndays; newDate = daysToDate(days); return newDate; } // < bool Date::operator<(const Date &other) const { if (dateToDays() < other.dateToDays()) return true; return false; } // > bool Date::operator>(const Date &other) const { if (dateToDays() > other.dateToDays()) return true; return false; } // == bool Date::operator==(const Date &other) const { if (dateToDays() == other.dateToDays()) return true; return false; } OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO DATE.H #ifndef DATE #define DATE #include  using namespace std; class Date { private: int day; int month; int year; int dateToDays() const; const Date daysToDate(int ndays) const; public: Date(); Date(int d, int m, int y); string toString() const; int getDay() const; void setDay(int d); int getMonth() const; void setMonth(int m); int getYear() const; void setYear(int y); const Date operator+(int ndays) const; const Date operator-(int ndays) const; bool operator<(const Date &other) const; bool operator>(const Date &other) const; bool operator==(const Date &other) const; }; #endif

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

Step: 3

blur-text-image

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions