Help complete C Code Create the following classes Date dom i
Help complete C++ Code:
Create the following classes:
Date
dom (int)
month (int)
year (int)
Event
date (Date)
description (string)
constructor of the form Event(string, int, int, int)
use a constructor initialization list
constructor of the form Event(string, Date)
use a constructor initialization list
Use the class in main
prompt the user for:
event name
day, month, year
instantiate two Event objects and initialize with the data provided
each instance should use a different constructor
use overloaded << operator to display information for both objects
ie. cout << event1 << endl;
cout << event2 << endl;
Current code:
#include<iostream>
#include<string>
using namespace std;
class Date
{
private:
int dom, month, year;
public:
Date::Date(int d, int m, int y)
:dom(d), month(m), year(y) {}
int Date::getdom()
{
return dom;
}
int Date::getmonth()
{
return month;
}
int Date::getyear()
{
return year;
}
};
class Event
{
private:
Date date;
string description;
public:
Event::Event(string e, int d, int m, int y)
:date(d, m, y), description(e){}
Event::Event(string e, Date d)
:description(e), date(d){}
int Event::getDateday()
{
return date.getdom;
}
int Event::getDatemonth()
{
return date.getmonth;
}
int Event::getDateyear()
{
return date.getyear;
}
friend ostream& operator << (ostream& os, Date &d)
{
os << e.description << \": \" << d.getmonth << \" \" << d.getdom << \", \" << d.getyear;
return os;
}
};
int main()
{
string event;
int day, month, year;
cout << \"Please enter the Event name, the day, the month, and year seperated with a space: \";
cin >> event >> day >> month >> year;
Date date(day, month, year);
Event event1(event, day, month, year);
Event event2(event, date);
cout << event1 << endl;
cout << event2 << endl;
}
Solution
SOURCE CODE:
#include<iostream>
#include<string>
using namespace std;
class Date
{
private:
int dom, month, year;
public:
Date(int d, int m, int y)
:dom(d), month(m), year(y) {}
int getdom()
{
return dom;
}
int getmonth()
{
return month;
}
int getyear()
{
return year;
}
};
class Event
{
private:
Date date;
string description;
public:
Event(string e, int d, int m, int y)
:date(d, m, y), description(e){}
Event(string e, Date d)
:description(e), date(d){}
int getDateday()
{
return date.getdom();
}
int getDatemonth()
{
return date.getmonth();
}
int getDateyear()
{
return date.getyear();
}
string getDescription()
{
return description;
}
friend ostream& operator << (ostream& os, Event &e)
{
os << e.getDescription() << \": \" << e.getDatemonth() << \", \" << e.getDateday()<< \", \" << e.getDateyear();
return os;
}
};
int main()
{
string event;
int day, month, year;
cout << \"Please enter the Event name, the day, the month, and year seperated with a space: \";
cin >> event >> day >> month >> year;
Date date(day, month, year);
Event event1(event, day, month, year);
Event event2(event, date);
cout << event1 << endl;
cout << event2 << endl;
}
OUTPUT:
Please enter the Event name, the day, the month, and year separated with a space: Birthday 08 08 1991
Birthday: 8, 8, 1991
Birthday: 8, 8, 1991
--------------------------------



