注册 登录
编程论坛 C++教室

请教一个编程题目,就是三口之家的那个问题

ringlord 发布于 2013-06-16 11:14, 1157 次点击
一个三口之家,大家知道父亲会开车,母亲会唱歌。但其父亲还会修电视机,只有家里人知道。小孩既会开车又会唱歌,甚至也会修电视机。母亲瞒着任何人在外面做小工以补贴家用。此外小孩还会打大乒乓球。
编写程序输出这三口之家从事一天的活动:先是父亲出去开车,然后母亲出去工作(唱歌),母亲下班后去做两个小时的小工。小孩在俱乐部打球,在父亲回家后,开车玩,后又高兴地唱歌。晚上,小孩和父亲一起修电视机。

问题是如何体现母亲瞒着任何人在外面做小工以补贴家用?有程序是这样的
#include <iostream.h>
class Father
{
public:
void access_father()
{
repair_tv();
}
void driving( )
{
cout<<"father is driving!"<<endl;
}
protected:
void  repair_tv()
{
cout<<"father is repairing  TV!"<<endl;
}
friend class Mother;
};
class Mother
{
public:
void access_mother()
{
take_jobs();
}
void  singing()
{
cout<<"Mother is singing!"<<endl;
}
private:
void  take_jobs()
{
cout<<"Mother  is  working!"<<endl;
}
};
class Child:public Father,public Mother
{
public:
void repair_tv()
{
cout<<"the child is repair_tv!"<<endl;
}
void  playing_pingpong()
{
cout<<"The child  is  playing pingpong!"<<endl;
}
};
void main()
{
Father F;
Mother M;
Child C;
F.driving();
M.singing();
M.access_mother();
C.playing_pingpong();
C.driving();
C.singing();
C.repair_tv();
F.access_father();
}


但是如果在主程序里,运行C.access_monther(),结果也显示了Monther is working ,那岂不是小孩也知道了monther工作了,请大家帮忙看看,非常非常地感谢
3 回复
#2
我有我梦2013-06-16 11:42
你的这个问题,我还是不太懂!不好理解!
#3
hpshuaia2013-06-21 08:11
是啊。 这是干嘛呢?
#4
peach54602013-06-21 08:45
面向对象的封装?
1