Birthday.h
=========
#ifndef BIRTHDAY_H
#define BIRTHDAY_H
class Birthday
{
public:
Birthday(int m, int d, int y);
void printDate();
private:
int month;
int day;
int year;
};
#endif // BIRTHDAY_H
Birthday.cpp
==========
#include "Birthday.h"
#include <iostream>
using namespace std;
Birthday::Birthday(int m, int d, int y)
: month(m), day(d), year(y)
{ }
void Birthday::printDate()
{
cout<<month<<"/"<<day <<"/"<<year<<endl;
}
Person.h
======
#ifndef PERSON_H
#define PERSON_H
#include <string>
#include "Birthday.h"
using namespace std;
class Person
{
public:
Person(string n, Birthday b);
void printInfo();
private:
string name;
Birthday bd;
};
#endif // PERSON_H
Person.cpp
==========
#include "Person.h"
#include <iostream>
using namespace std;
Person::Person(string n, Birthday b)
: name(n), bd(b)
{ }
void Person::printInfo()
{
cout << name << endl;
bd.printDate();
}
main.cpp
========
#include <iostream>
#include "Person.h"
using namespace std;
int main() {
Birthday bd(2, 21, 1985);
Person p("David", bd);
p.printInfo();
}