收藏 分销(赏)

面向对象程序设计试题样例.doc

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


点击查看更多>>
资源描述
一、单项选择题(本大题共10小题) 1. 关于面向对象的程序设计必需具备的关键要素,以下说法最正确的是( ) A. 抽象和封装 B. 抽象和多态性 C. 抽象、封装和继承性 D. 抽象、封装、继承和多态性 2.在下列成对的表达式中,运算符“+”的意义不相同的一对是( ) A. 5.0+2.0和5.0+2 B. 5.0+2.0和5+2.0 C. 5.0+2.0和5+2 D. 5+2.0和5.0+2 二、填空题(本大题共10小题) 3.在已经定义了整型指针ip后,为了得到一个包括10个整数的动态数组并由ip指向这个数组,应使用语句_______________。ip=new int[10];矚慫润厲钐瘗睞枥庑赖。 4.在函数头与函数体之间加_____________关键字可以防止覆盖函数改变数据成员的值。 三、改错题(本大题共5小题) 5. 用横线标出下面main函数中的错误,说明错误原因并改正。 #include <iostream> using namespace std; class Base0 { //定义基类Base0 public: int var0; void fun0() { cout << "Member of Base0" << endl; } }; class Base1: public Base0 { //定义派生类Base1 public: //新增外部接口 int var1; }; class Base2: public Base0 { //定义派生类Base2 public: //新增外部接口 int var2; }; class Derived: public Base1, public Base2 { //定义派生类Derived聞創沟燴鐺險爱氇谴净。 public: //新增外部接口 int var; void fun() { cout << "Member of Derived" << endl; }残骛楼諍锩瀨濟溆塹籟。 }; int main() { //程序主函数 Derived d; //定义Derived类对象d d.var0=1; d.fun0(); return 0; } 6.下面的程序类B的定义中有一处错误,请用下横线标出错误并说明错误原因。 # include<iostream> # include<string> class A { public: A(const char *nm){strcpy(name,nm);} private: char name[80]; }; class B:public A { public: B(const char *nm):A(nm){ } void PrintName( )const; }; void B::PrintName( )const { cout<<“name:”<<name<<endl; } 四、完成程序题(本大题共5小题)。 7.完成下面类中的成员函数的定义。 class Point { //Point 类的定义 public: //外部接口 Point(int xx = 0, int yy = 0) { //构造函数 x = xx; _______________; } Point(Point &p); //拷贝构造函数 private: //私有数据 int x, y; }; //成员函数的实现 Point::Point(Point &p) { x = p.x; _______________ cout << "Calling the copy constructor" << endl; } 8.根据注释在空白处填写适当内容。 class Location{ private: int X,Y; public: void init(int initX,int initY); int GetX( ); int GetY( ); }; void Location::init(int initX,int initY) { X=initX; Y=initY; } int Location::GetX( ) { reutrn X; } int Location::GetY( ) { reutrn Y; } # include<iostream > void main( ) { Location A1; A1.init(20,90); ①____________________ //定义一个指向A1的引用rA1 ② ____________________ //用rA1在屏幕上输出对象A1的数据成员X和Y的值 } 五、程序分析题(本大题共5小题) 9.写出下面程序的输出结果: # include<iostream> using namespace std; class FunArray { int *pa; //指向一个数组空间 int size; //数组元素个数 public: FunArray(int a[ ],int thesize):pa(a),size(thesize){ } 酽锕极額閉镇桧猪訣锥。 int Size( ){return size;} int& operator[ ](int index){return pa[index-1];} }; void main( ) { int s[ ]={3,7,2,1,5,4}; FunArray ma(s,sizeof(s)/sizeof(int)); ma[3]=9; for(int i=1;i<=ma.Size( );i++) cout<<ma[i]<<’,’; } 10.写出下面程序的输出结果: # include<iostream> using namespace std; template<class T> class Tclass{ T x,y; public: Tclass(T a,T b):x(a){y=b;} Tclass(T a){y=(T)0,x=a;} void pr( ){ char c; c=(y>=(T)0? " + " : " - " ); cout<<x<<c<<(y>(T)0? y:-y)<< " i " <<endl; } }; void main( ){ Tclass<double>a(10.5,-5.8); a.pr( ); Tclass<int>b(10); b.pr( ); } 六、程序编写(10分) 5
展开阅读全文

开通  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 

客服