...

/

Solution Review: Event Data

Solution Review: Event Data

This program is an example of composition. The Event class holds Date and Time objects that have no utility or lifetime outside of the Event object that contains them. Let’s look at the implementation:

C++
Files
#include <iostream>
#include <string>
#include "date.h"
#include "time.h"
class Event {
private:
std::string title;
Date d;
Time t;
public:
Event(std::string title, unsigned int month, unsigned int day, unsigned int year, unsigned int hours, unsigned int minutes, unsigned int seconds) {
Event::title = title;
d.setDate(month, day, year);
t.setTime(hours, minutes, seconds);
}
void display() {
std::string date, time;
d.toString(date);
t.toString(time);
std::cout << title + " occurs on " + date + " at " + time << std::endl;
}
};

The file ...