| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1157 人关注过本帖
标题:请教一个编程题目,就是三口之家的那个问题
取消只看楼主 加入收藏
ringlord
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2009-5-30
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:0 
请教一个编程题目,就是三口之家的那个问题
一个三口之家,大家知道父亲会开车,母亲会唱歌。但其父亲还会修电视机,只有家里人知道。小孩既会开车又会唱歌,甚至也会修电视机。母亲瞒着任何人在外面做小工以补贴家用。此外小孩还会打大乒乓球。
编写程序输出这三口之家从事一天的活动:先是父亲出去开车,然后母亲出去工作(唱歌),母亲下班后去做两个小时的小工。小孩在俱乐部打球,在父亲回家后,开车玩,后又高兴地唱歌。晚上,小孩和父亲一起修电视机。

问题是如何体现母亲瞒着任何人在外面做小工以补贴家用?有程序是这样的
#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工作了,请大家帮忙看看,非常非常地感谢
搜索更多相关主题的帖子: 编写程序 include 乒乓球 public 俱乐部 
2013-06-16 11:14
快速回复:请教一个编程题目,就是三口之家的那个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011821 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved