c++面向对象程序设计试题和答案经典题目.doc

上传人:h**** 文档编号:893630 上传时间:2018-11-05 格式:DOC 页数:11 大小:82.50KB
下载 相关 举报
c++面向对象程序设计试题和答案经典题目.doc_第1页
第1页 / 共11页
c++面向对象程序设计试题和答案经典题目.doc_第2页
第2页 / 共11页
c++面向对象程序设计试题和答案经典题目.doc_第3页
第3页 / 共11页
c++面向对象程序设计试题和答案经典题目.doc_第4页
第4页 / 共11页
c++面向对象程序设计试题和答案经典题目.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、系名_班级_姓名_学号_密封线内不答题一、 填空题(每空 1 分,共 14 分)1、 观看以下程序:class pointpublic: void show() coutclass Base public: void fun()coutfun();16、执行下面的程序将输出( ) #include class BASEchar c;public:BASE(char n):c(n)virtual BASE()coutclass MyClass public: MyClass(int i)member=i; void SetMember(int m)member=m; int GetMember(

2、)constreturn menber; void print()contcout class Sample int n; public: Sample(int i)n=i; friend int add(Sample ; int add(Sample void main() Sample s1(10),s2(20); cout int add(int x,int y) return x+y+1; double add(double x,double y) return x+y-1; void main() int a=2,b=4; double c=2.6,d=7.4; cout class

3、 A public: int n; ; class B:virtual public A; class C:virtual public A; class D:public B,public C int getn()return B:n; ; void main() D d; 系名_班级_姓名_学号_密封线内不答题d.B:n=10; d.C:n=20; coutclass myclass int a,b;static int s; public:myclass(int x,int y)a=x;b=y;s+;void print()coutshow() (2)公有、私有、保护 (3)class

4、(4)抽象类 (5)成员函数、不是 (6)friend (7)11、11 (8)动态申请内存空间、释放由 new 申请的空间 二、 选择题(每小题 1.5 分,共 30 分)1、D 2、B 3、C 4、D 5、D 6、B 7、B 8、C 9、C 10、A 11、D 12、C 13、D 14、B 15、C 16、A 17、B 18、C 19、C 20、A三、 改错题(每错 2 分,共 6 分)MyClass obj1(0); obj1.SetMember(5); obj2.SetMember(10);四、 写出下列程序的执行结果(每小题 5 分,共 20 分)(1)30 (5 分)(2)7 9

5、(每个 2.5 分)(3)20 20 (每个 2.5 分)(4)3(2 分)3(2 分)3(1 分)五、 编程题(每题 10 分、共 30 分)1、#include #include 系名_班级_姓名_学号_密封线内不答题class rectangle /(2 分)private:int x1,y1,x2,y2; / (2 分)public:rectangle(int xx1,int yy1,int xx2,int yy2) /(1 分)x1=xx1;y1=yy1;x2=xx2;y2=yy2;int getarea() /(2 分)return abs(x2-x1)*(y1-y2);void

6、main()rectangle rect1(3,7,8,5); (2 分)coutclass car;(1 分)class boat private:int weight; /(1 分)public:boat(int w):weight(w) /(1 分)friend int totalweight(boat b1,car c1); /(2 分);class car /(1 分)private:int weight; (1 分)public:car(int w):weight(w);friend int totalweight(boat b1,car c1); (1 分);int totalw

7、eight(boat b1,car c1) /(1 分)return b1.weight+c1.weight;第 10 页void main()car c1(1000);boat b1(2000);cout class vehicle / 定义汽车类 (3 分) protected: int wheels; / 车轮数 float weight; / 重量 public: vehicle(int wheels,float weight); int get_wheels(); float get_weight(); float wheel_load(); void show(); ; class

8、 car:public vehicle / 定义小车类 (3 分) int passenger_load; / 载人数 public: car(int wheels,float weight,int passengers=4); int get_passengers(); void show(); ; vehicle:vehicle(int wheels1,float weight1) /(1 分) wheels=wheels1; weight=weight1; int vehicle:get_wheels() return wheels; float vehicle:get_weight()

展开阅读全文
相关资源
相关搜索
资源标签

当前位置:首页 > 教育教学资料库 > 参考答案

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。