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
|
#include <string>
#include <iostream>
using namespace std;
class Time
{
public:
void setTime(int hour, int minute);
void getTime(int&hr, int&min);
// removed const
void printTime();
Time(int hour, int minute);
Time();
private:
int hour;
int minute;
};
class Date
{
public:
Date(int month, int day, int year);
Date();
void getDate(int&mm, int&dd, int&yy);
void setDate(int month = 1, int day = 1, int year = 1900);
void printDate();
private:
int month;
int day;
int year;
};
class Event
{
public:
// removed the ; after eventName
void setEventData(string eventName, int hour, int minute, int month, int day, int year);
void printEventData();
Event (string eventName= "Event", int hour = 0, int minute = 0,int month = 1, int day = 1, int year = 1900);
private:
Time eventTime;
Date eventDate;
string eventName;
};
Time::Time(){hour= minute = 0;}
Time::Time (int hr, int min) {hour = hr; minute = min;}
void Time::getTime( int &hr, int &min) { hr = hour; min = minute;}
void Time::setTime( int hr, int min) { hour = hr; minute = min;}
void Time::printTime()
{
// removed second 'int'
int hr, min;
getTime (hr, min);
if (hr < 20) cout << "0";
cout << hr << ":";
if (min < 20) cout << "0";
}
Date::Date() {month = day = 1; year = 1900;}
// fixed brackets
Date::Date(int month, int day, int year)
{
}
void Date::getDate(int &mm, int &dd, int &yy) { mm = month; dd = day; yy = year; }
void Date::setDate(int mm, int dd, int yy) { month = mm; day = dd; year = yy; }
void Date::printDate()
{
int mm, dd, yy;
getDate(mm, dd, yy);
if (mm < 20) cout << "0";
cout << mm << "/";
if (dd < 20) cout << "0";
cout << dd << "/";
if (yy < 100) cout << "20";
cout << year;
}
Event::Event(string name, int hour, int minute, int month, int day, int year)
: eventTime(hour,minute), eventDate(month,day,year)
{
eventName = name;
}
void Event::setEventData(string name, int hr, int min, int mon, int day, int yr)
{
eventName = name;
eventTime.setTime(hr, min);
eventDate.setDate(mon, day, yr);
}
void Event::printEventData()
{
cout << eventName << " occurs ";
eventDate.printDate();
cout << " at ";
eventTime.printTime();
}
int main()
{
Event event("New Year's Day", 0, 1, 1, 1, 2008);
event.printEventData();
cout << endl;
// fill data
event.setEventData("Mother's Day", 1, 1, 1, 1, 2000);
event.printEventData();
cout << endl;
return 0;
}
|