以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 C/C++编程思想 』  (http://bbs.xml.org.cn/list.asp?boardid=61)
----  请教一道C++编程题目,不知放在这里合适否,如不行,版主请删除  (http://bbs.xml.org.cn/dispbbs.asp?boardid=61&rootid=&id=126482)


--  作者:ringlord
--  发布时间:6/16/2013 2:22:00 PM

--  请教一道C++编程题目,不知放在这里合适否,如不行,版主请删除

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

问题是如何体现母亲瞒着任何人在外面做小工以补贴家用?有程序是这样的
#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工作了,请大家帮忙看看,非常非常地感谢


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms