收藏 分销(赏)

面向对象程序设计样卷.doc

上传人:w****g 文档编号:2647148 上传时间:2024-06-03 格式:DOC 页数:6 大小:38KB 下载积分:6 金币
下载 相关 举报
面向对象程序设计样卷.doc_第1页
第1页 / 共6页
面向对象程序设计样卷.doc_第2页
第2页 / 共6页


点击查看更多>>
资源描述
面向对象程序设计样卷 一、选择题(本大题共10小题,每题2分,共20分) 4.在下列定义的引用中,( B )是错误的。 A. int i; B. int i; int &j = i; float &j=i; C. float i; D. char d; float &j = i; char &e = d; 5. 假定BB为一个类,则执行BB y;语句时将自动调用该类的( B ) A. 有参构造函数 B. 无参构造函数 C. 拷贝构造函数 D. 赋值重载函数 7.下列对派生类的描述中,( C )是错误的。 A. 一个派生类可以作为另一个派生类的基类 B.派生类至少应有一个基类 C. 基类中成员访问权限继承到派生类中都保持不变 D.派生类成员除了自己定义的成员外,还包含了它的基类成员 10.控制输出格式的控制符中,( D )是设置输出宽度的。 A.ws B.ends C. setfill() D.setw()矚慫润厲钐瘗睞枥庑赖。 二、填空题(本大题共10小题,每题2分,共20分) 1. 以/*开始,以*/结束,在/*和*/之间的部分即为 注释 。 2.重载函数在参数类型或参数个数上不同,但函数名和类名_相同。 3. 假如一个类的名称为MyClass,使用这个类的一个对象初始化该类的另一个对象时,可以调用__拷贝______构造函数来完成此功能。聞創沟燴鐺險爱氇谴净。 4.当删除对象时,程序自动调用 析构函数 。 5. 对于每一个类的非静态成员函数,都有一个隐含的_this_______指针。 8. 抽象类是指 类里有一个函数,是纯嘘函数 。 三、改错题(下面程序或程序段中有一处错误,请用注释标明错误所在行的出错原因。本大题共5小题,每题2分,共10分)残骛楼諍锩瀨濟溆塹籟。 1. #include<iostream> using namespace std; int main() { cout<<"This is a program."<<endl; return 0; } 2. #include<iostream> using namespace std; int main() { x=3; int y=x*x; cout<<"y="<<y<<"\n"; return 0; } 3. #include<iostream> using namespace std; class Aa { public: Aa(int i=0){a=i; cout<<"Constructor "<<a<<endl; } ~Aa(){ cout<<"Destructor "<<a<<endl; } void print( ){cout<<a<<endl;} private: int a; }; int main() { Aa al(1),a2(2); al.print(); cout<<a2.a<<endl; return 0; } 4.class A { int a,b; public: A(int aa,int bb=78){a=aa;b=bb;} }; int main() { A x(2), y(4,9); return 0; } 5. #include<iostream> using namespace std; class Test { public: static int x; }; int Test :: x=20; int main() { cout<<Test::x; return 0; } 四、程序分析题(分析程序,写出运行结果。本大题共4小题,每题5分,共20分) 1. #include<iostream> using namespace std; class Test { private: int num; public: Test(); Test(int n); ~ Test(){cout<<”dst ”<<num<<endl;} }; Test::Test() { cout<<”Init defa”<<endl; num=0; } Test::Test(int n) { cout <<”Init”<<” “<<n<<endl; num=n; } int main() { Test xx(10); Test yy[2]; return 0; } 2. #include<iostream> using namespace std; class My { public: My(int aa) { A=aa; B-=aa; } static void fun(My m); private: int A; static int B; }; void My::fun(My m) { cout<<"A="<<m.A<<endl; cout<<"B="<<B<<endl; } int My::B=100; int main( ) { My P(8),Q(6); My::fun(P); Q.fun(Q); return 0; } 3. #include<iostream> using namespace std; int main( ) { void fun(int&,int); int a,b; fun(a,2); fun(b,4); cout<<"a+b="<<a+b<<endl; return 0; } void fun(int &m,int n) { m=n+4; } 4. #include<iostream> using namespace std; class big { private: int a; public: big(int i) { a=i;cout<<"cst big a=" <<a<<endl;} ~big(){ cout<<"dst big a=" <<a<<endl;} }; class small:public big { private: int d; public: small(int i,int j); ~small() {cout<<"dst small d="<<d<<endl;} }; small::small(int i,int j):big(i) { d=10*j; cout<<"cst small d="<<d<<endl; } int main() { small x(18,19); return 0; } 五、简答题(阅读程序,回答问题。本大题共2小题,每题9分,共18分) 1. #include<iostream> using namespace std; const double PI=3.14; class Figure { public: Figure(){}; virtual double circumference()=0; }; class Circle : public Figure { public: Circle(double myr){R=myr;} double circumference(){return 2*PI*R;} protected: double R; }; class Rectangle : public Figure { public: Rectangle (double myl,double myw){L=myl;W=myw;} double circumference(){return 2*(L+W);} private: double L,W; }; void func(Figure &p) { cout<<p.circumference()<<endl; } int main() { Circle c(3.0); cout<<"Circumference of circle is "; func(c); Rectangle rec(4.0,5.0); cout<<"Circumference of rectangle is "; func(rec); return 0; } (1)每个类的作用是什么? (2)写出程序的运行结果。 (3)如果将Figure类中的virtual double circumference ()=0;改为酽锕极額閉镇桧猪訣锥。 double circumference (){return 0.0;}, 程序的运行结果如何变化? 2. #include<iostream> using namespace std; #include<cmath> class Myclass { public: Myclass(double i=0){ x=y=i;} Myclass(double i,double j){x=i;y=j;} friend double distance(Myclass &a,Myclass &b); private: double x,y; }; double distance(Myclass &a,Myclass &b) { double dx=a.x-b.x; double dy=a.y-b.y; return sqrt(dx*dx+dy*dy); } int main() { Myclass ml,m2(5),m3(3,4); cout<<"The distance1: "<<distance(ml,m3)<<endl; cout<<"The distance2: "<<distance(m2,m3)<<endl; cout<<"The distance4: "<<distance(ml,m2)<<endl; } (1)指出重载的构造函数。 (2)指出设置默认参数的构造函数。 (3)指出友元函数,它的作用是什么? 六、程序设计题(4个大题每个十分) 1.老师留的与类相关的编程作业题。 2.设计table桌子类,设计成员变量和成员函数,注意构造函数 3.设计food食物类,并设计其子类pie ,注意构造函数
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服