练习.txt
来自「钱能主编 C++程序设计教程(第一版) 该书习题的答案代码」· 文本 代码 · 共 52 行
TXT
52 行
//************************
//** main.cpp **
//************************
#include <iostream.h>
#include "famo.h"
void main()
{
Father fa;
Mother mo;
Child ch;
cout<<"a new day start..."<<endl;
cout<<"father:"; fa.Drive();
cout<<"mother:"; mo.Sing(); mo.PJ();
cout<<"child:"; ch.PlayBall();
cout<<endl<<"then father drive back..."<<endl;
cout<<"child:"; ch.Drive(); ch.Sing();
cout<<endl<<"in the evening..."<<endl;
cout<<"father:"; fa.Mend();
cout<<"child:"; ch.Mend();
}
//**********************
//** famo.h **
//**********************
#include <iostream.h>
class Father
{
public:
void Drive() {cout<<"driving car."<<endl;}
void Mend() {MendTV();}
protected:
void MendTV() {cout<<"repair TV."<<endl;}
};
class Mother
{
public:
void Sing() {cout<<"singing."<<endl;}
void PJ() {PartJob();}
private:
void PartJob() {cout<<"doing parttime job."<<endl;}
};
class Child:public Father,public Mother
{
public:
void PlayBall() {cout<<"playing ball."<<endl;}
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?