《面向对象程序设计》综合复习题集(杨永斌整理)(15)
class Goods {
private:
char gd_name[20]; //商品名称 int weight; //商品重量
static int totalweight; //同类商品总重量 public:
Goods (char*str,int w){ //构造函数 strcpy(gd_name,str); weight=w;
totalweight+=weight; }
~ Goods (){totalweight -= weight;}
char* GetN(){___(1)___;} //返回商品名称 int GetW(){return weight;}
___(2)___ GetTotal_Weight() { //定义静态成员函数返回总重量 ___(3)___; } }
(1) (2) (3)
38. class Point {
private: int x, y; public:
Point(){x=y=0;}
Point(int x0,int y0) {x=x0;y=y0;} int GetX() { return x; } int GetY() { return y; }
void Print(){cout<<\ ___(1)___; //友元函数声明 ___(2)___; //友元函数声明 };
Point operator+(Point& pt,int dd)
//加号操作符重载函数,实现Point类对象与整数加法 {
Point temp=pt; temp.x+=dd; temp.y+=dd; return temp; }
Point operator+(Point& pt1,Point& pt2)
//加号操作符重载函数,实现两个Point类对象的加法
{
Point temp=pt1; temp.x+=pt2.x; ___(3)___; return temp; }
(1) (2) (3)
39. 在下面一段类定义中, Derived类是由直接基类Base 1和Base 2所派生的,Derived类包含有两个间接基类BaseBase,在初始化函数Init中,需要把x1和x2的值分别赋给属于基类Base1的x成员和属于基类Base2的x成员。 class BaseBase { protected: int x; public:
BaseBase(){ x = 1;} };
class Base1: public BaseBase { public: Base1(){} };
class Base2: public BaseBase { public: Base2(){} };
class Derived: ___(1)___ {
public:
Derived() {}
void Init(int x1, int x2) { ___(2)___; ___(3)___; }
void output() {cout< (1) (2) (3) 40. 在下面一段类定义中, Derived类公有继承了基类Base。需要填充的函数由注释内容给出了功能。 class Base { private: int mem1,mem2; //基类的数据成员 public: Base(int m1,int m2) { mem1=m1; mem2=m2; } void output(){cout< class Derived: public Base { private: int mem3; //派生类本身的数据成员 public: //构造函数,由m1和m2分别初始化mem1和mem2,由m3初始化mem3 Derived(int m1,int m2, int m3); //输出mem1,mem2和mem3数据成员的值 void output(){ ___(1)___; cout< Derived::Derived(int m1,int m2, int m3): ___(2)___ {___(3)___;} (1) (2) (3) 41. 在下面一段类的定义中,需要填充的函数由注释内容给出了功能。 class Point //定义坐标点类 { public: int x,y; //点的横坐标和纵坐标 Point(){x=0;y=0;} Point(int x0,int y0) {x=x0; y=y0;} int X(){return x;} int Y(){return y;} void PrintP(){cout<<\}; class Line: public Point //利用坐标点类定义直线类 { private: class Point pt1,pt2; //直线的两个端点 public: Line(Point pts, Point pte); //构造函数,分别用参数初始化对应的端点 double Dx(){return pt2.x-pt1.x;} double Dy(){return pt2.y-pt1.y;} double Length(){ //计算直线的长度 return sqrt(___(1)___); }; void PrintL(); //输出直线的两个端点和直线长度 }; Line::Line(Point pts, Point pte) ___(2)___ void Line::PrintL() { cout<<\ pt1.PrintP(); cout<<\ pt2.PrintP(); cout<<\} (1) (2) (3) 42. 在下面一段类的定义中,自行车类的虚基类为车辆类,机动车类的虚基类也为车辆类,摩托车类的基类为自行车类和机动车类,类之间均为公有继承。 class vehicle //车辆类 { private: int MaxSpeed; //最大车速 int Weight; //车重 public: vehicle(){MaxSpeed=0; Weight=0;}; virtual void Run() {cout<<\}; class bicycle : ___(1)___ //自行车类 { private: int Height; //车高 public: bicycle(){}; void Run() {cout<<\}; class motorcar : ___(2)___ //机动车类 { private: int SeatNum; //乘人数 public: motorcar(){}; void Run() {cout << \}; class motorcycle: ___(3)___ //摩托车类 { public: motorcycle (){}; void Run() {cout<<\}; (1) (2) (3) 五、读程序写出运行结果 1. #include int a[8]={25,48,32,85,64,18,48,29}; int max,min; max=min=a[0]; for(int i=0; i<8; i++) { if(x>a[i]) max=a[i]; if(x cout<<\ cout<<\ } 2. #include int a,b; for(a=1,b=2; b<50;) { cout< cout< cout< 3. #include int i,j,s=0; for(i=1;i<=M;i++) for(j=1;j<=N;j++) s+=i*j; cout<<”s=”< 4. #include
相关推荐:
- [基础教育]2016-2022年中国钢芯铝绞线市场现状调
- [基础教育]语文部编版初一语文下册练习题 句式变
- [基础教育]南京继续教育参考答案--深入学习贯彻习
- [基础教育]国旗下讲话稿——珍惜时间好读书
- [基础教育]北师大版六年级数学下册圆锥的体积教学
- [基础教育]人教版-音乐-四年级下册-四年级下册音
- [基础教育]乔布斯2019年斯坦福大学毕业典礼致辞.d
- [基础教育]2015年加油站安全知识竞赛试题及答案
- [基础教育]2020年教师年度考核个人工作总结
- [基础教育]2019年中考历史试题-2019年大庆市初中
- [基础教育]初三仁爱英语第一轮总复习教案
- [基础教育]SG-A094电气配管安装工程隐蔽验收记录
- [基础教育]冀教版小学数学三年级下册第六单元教材
- [基础教育]青岛版(五制)小学科学二年级下册16《制
- [基础教育]2018-2019年初中科学初一中考真卷测试
- [基础教育]幼儿园大班期末简短评语精选
- [基础教育]2018云南临沧公务员考试申论技巧:这样
- [基础教育]学校食堂经营管理方案
- [基础教育]新中国砥砺奋进的七十年原文
- [基础教育]真空泵的选型及常用计算公式
- 高职田径课程教学现状与对策
- 全髋关节置换术在老年股骨颈骨折患者中
- 青人社厅函〔2016〕576号(附件)工资
- cp101-07砂子检验作业指导书 - secret
- 微观经济学 第八章 博弈论 习题
- 2014高考真题(词语运用)汇编及答案
- 2018年人教版七年级语文下册《第三单元
- 苏教版数学四年级上册第一单元试题 - M
- 四川大学新闻与传播考研2000-2010年真
- 浙江万里学院英语专业四年制本科教学计
- 最新2018马年事业祝福语-范文word版(2
- 最全模具行业术语英文翻译
- 皮亚杰的发展心理学理论
- 64篇高考情景式默写 练习题及答案
- 仿写(学生稿)
- 《SQL Server数据库技术》试卷A
- 第七章作业答案
- 江苏省赣榆县海头高级中学高中语文必修
- 浙江省2001年10月自考正常人体解剖学答
- 2012英语重点短语




