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
|
#include <iostream>
using namespace std;
#include <string>
class Event
{
public:
void setEventData(string eventName, int hour, int minute, int month, int day, int year);
void printEventData() const;
Event(string EventName = "Generic Event", int hour = 0, int minute = 0,
int month = 1, int day = 1, int year = 2000);
private:
string EventName;
Time eventTime;
Date eventDate;
};
class Time
{
public:
void setTime (int hr, int min);
void getTime(int &hr, int &min);
void printTime();
Time(int hr, int min);
Time();
private:
int hour;
int minute;
};
class Date
{
public:
void setDate(int = 1, int = 1, int = 2000);
void getDate(int &m, int &d, int &y);
void printDate();
Date (int month, int day, int year);
Date();
private:
int month;
int day;
int year;
};
Date::Date(int m, int d, int yr)
{
int month = m;
int day = d;
int year = yr;
}
Date::Date()
{
month = day = 1;
year = 2000;
}
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() const
{
cout << EventName << " occurs ";
eventDate.printDate();
cout << "at ";
eventTime.printTime();
}
Event::Event(string name, int hour, int minute, int month, int day, int year)
: eventTime(hour,minute), eventDate(month,day,year)
{
EventName = name;
}
int main()
{
Event event("New Year's Day", 0,1,1,1,2008);
event.printEventData();
cout << endl;
event.setEventData("Valentine's Day", 12, 15,2, 14, 2010);
event.printEventData();
cout << endl;
return 0;
}
|