level 3
萧炎xy123
楼主
#include <iostream>
using namespace std;
class Father{ public:
void DoWork(){ DriveACar(); }
void DoMannulWork(){ RepairTV(); }
void DriveACar() { cout <<&typeid(*this).name()[6] <<" Drive a car.\n"; }
protected:
void RepairTV() { cout <<&typeid(*this).name()[6] <<" Repair a TV set.\n"; }
};
class Mother{ public:
void SingASong() { cout <<&typeid(*this).name()[6] <<" Sing a song.\n"; }
void DoWork(){ SingASong(); } //正式工
void DoMannulWork() { cout <<&typeid(*this).name()[6] <<" Do mannul work.\n"; } //小工
};
class Boy : public Father, public Mother{ public:
void RepairTV(){ cout <<"boy "; Father::RepairTV(); }
void SingASong(){ cout <<"boy "; Mother::SingASong(); }
void PlayPingPong() { cout <<&typeid(*this).name()[6] <<" Play pingpong.\n"; };
};
void main()
{
Father father;
Mother mother;
Boy boy;
father.DoWork();
mother.DoWork();
mother.DoMannulWork();
boy.PlayPingPong();
boy.DriveACar();
boy.SingASong();
father.DoMannulWork();
boy.RepairTV();
}
2017年10月12日 09点10分
1
using namespace std;
class Father{ public:
void DoWork(){ DriveACar(); }
void DoMannulWork(){ RepairTV(); }
void DriveACar() { cout <<&typeid(*this).name()[6] <<" Drive a car.\n"; }
protected:
void RepairTV() { cout <<&typeid(*this).name()[6] <<" Repair a TV set.\n"; }
};
class Mother{ public:
void SingASong() { cout <<&typeid(*this).name()[6] <<" Sing a song.\n"; }
void DoWork(){ SingASong(); } //正式工
void DoMannulWork() { cout <<&typeid(*this).name()[6] <<" Do mannul work.\n"; } //小工
};
class Boy : public Father, public Mother{ public:
void RepairTV(){ cout <<"boy "; Father::RepairTV(); }
void SingASong(){ cout <<"boy "; Mother::SingASong(); }
void PlayPingPong() { cout <<&typeid(*this).name()[6] <<" Play pingpong.\n"; };
};
void main()
{
Father father;
Mother mother;
Boy boy;
father.DoWork();
mother.DoWork();
mother.DoMannulWork();
boy.PlayPingPong();
boy.DriveACar();
boy.SingASong();
father.DoMannulWork();
boy.RepairTV();
}