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()