1. main.cpp
#include <iostream>
#include "People.h"
#include "Birthday.h"
using namespace std;
int main()
{
Birthday bithObj(12, 28, 198);
People buckyRoberts("Bucky the King", bithObj);
buckyRoberts.printInfo();
system("pause");
}
2. 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
3. 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;
}
4. People.h
#ifndef PEOPLE_H
#define PEOPLE_H
#include <string>
#include "Birthday.h"
using namespace std;
class People
{
public:
People(string x,Birthday bo);
void printInfo();
private:
string name;
Birthday dateOfBirth;
};
#endif
5. People.cpp
#include "People.h"
#include "Birthday.h"
#include <iostream>
using namespace std;
People::People(string x, Birthday bo):name(x),dateOfBirth(bo)
{
}
void People::printInfo()
{
cout << name << " was born on ";
dateOfBirth.printDate();
}
47 - Composition Part 2
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- [机器学习入门] 李宏毅机器学习笔记-27(Structured SVM part 2;结构化支持向量机 part...
- [机器学习入门] 李宏毅机器学习笔记-35(Ensemble;集成方法) 上接part 1 Ensemble En...
- [机器学习入门] 李宏毅机器学习笔记-30 (Sequence Labeling Problem part 2 ;...
- [机器学习入门] 李宏毅机器学习笔记-22(Transfer Learning part 2;迁移学习 part ...
- [机器学习入门] 李宏毅机器学习笔记-33 (Recurrent Neural Network part 2;循环...