77范文网 - 专业文章范例文档资料分享平台

c++面向对象复习题答案版(2)

来源:网络收集 时间:2019-06-05 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

第 6 页 共 22 页

35.为了使类中的某个成员不能被类的对象通过成员操作符访问,则不能把该成员的访问

权限定义为(A,B,C )。

A.public B. protected C.private D. static 36.派生类的对象对它的( A,B,D )是可以访问的。

A.公有继承的基类的公有成员 B. 公有继承的基类的保护成员 C. 公有继承的基类的私有成员 D. 保护继承的基类的公有成员 37.多继承派生类构造函数构造对象时,(B )被最先调用。

A.派生类自己的构造函数 B.虚基类的构造函数

C.非虚基类的构造函数 D.派生类中子对象类的构造函数 38.C++类体系中,不能被派生类继承的有(C )。

A.构造函数 B.虚函数 C.静态成员函数 D.赋值操作函数 39.编译时的多态性可以通过使用(A,D )获得。

A.虚函数和指针 B.重载函数和析构函数 C.虚函数和对象 D.虚函数和引用 40.下列描述中,( A )是抽象类的特征。

A.可以说明虚函数 B.可以进行构造函数重载 C.可以定义友元函数 D.不能说明其对象

三、指出并改正下列程序段中的语法错误。

题目 1. float x=3.26f; int &ref1=x;// float 2. int d1=3, d2=2; int * const dp=&d1; dp=&d2; *dp=5; 3.类型不一致 1.类型不一致 答案 2.常指针 3. //Nums为已定义的类 Nums *fp; fp=new int[4]; 4. void func(int first, int 2_secnd); 5. void Pixel::operator=(Pixel &p1, Pixel &p2); 4.标识符得字母开头 5.“=”运算符重载函数返回类型不对 第 7 页 共 22 页

6.//Pixel有两个整型成员x和y Pixel Pixel::operator+=(Pixle&p)const { x+=p.x;y+=p.y; return *this; } 2、指出并改正下列程序段中的语法错误。

题目 1. int x=13; const int &ref=x; ref=10; 2. double *fp; fp=new int(3); 6.在这里this是指向常量的常指针 答案 1.常引用不能赋值了 2.类型不一致 3. void func( first, int secnd); 4. //Pixel有两个整型成员x和y,其拷//贝构造函数定义如下: void Pixel(const Pixle& p); 3. first不是类型说明 4.不能有“void” 5. 5.不能定义友元函数,只能是成员函数。 friend Pixel & operator=(Pixel &p1, Pixel&p2); 6. //Pixel有两个整型成员x和y Pixel Pixel::operator++(int) { Pixel temp; temp=*this; x++; y++; return *this;temp; } 四、程序填空

1.编写函数将字符串按逆序存放。 #include #include #include void main() { int i,n;

6. 第 8 页 共 22 页

}

char s[100],temp;

cout<<\ (1) get(s); n= (2) strlen(s); for(i=0;i

{ temp=s[i];s[i]=s[n-i-1]; s[n-i-1]=temp; } cout<<\puts(s);

2.下列程序定义了类Pixel,请完成前置++和后置++的运算符函数的定义。 class Pixel{ };

Pixel Pixel::operator ++() { }

Pixel Pixel::operator ++(int) { }

void Pixel::display() { }

3. 根据给定的程序执行结果,将下列程序补充完整。 #include class Base{ public:

( 6 )Base(){ cout<<” Delete Derived”<

( 4 )Pixel temp=*this; x++;

y++;

return ( 5 ) temp;

x++; y++;

return (3) *this int x,y;

Pixel(int xx=0,int yy=0){ x=xx; y=yy; } Pixel operator ++(); Pixel operator ++(int); void display(); public:

第 9 页 共 22 页

};

class Derived:public Base{ public: }; void main() { }

程序的执行结果如下: Delete Derived Delete Base

4.定义一个字符串类String,有两个私有数据成员:char* content和int len;要求

1)在构造函数中提示用户输入字符串,;

2) 用户能提取和显示字符串;(分别由两个函数完成) 3)实现对字符串中所有小写字母变成大写,并显示。 注意内存的分配与释放。

类定义的部分代码如下,请补充代码使类的定义完整。 #include #include #include class String{ };

String::String(){

char ch[50];//?

cout<<\cin>>ch; char* content; int len; String(); Base *p1= ( 8 )new Derived ; delete p1;

( 7 )Derived (){cout<<” Delete Base”<

public:

~String(){ ( 1 ) delete content[]; } void display(); void upper_str();

char* get_str() const{ ( 2 ) return content; } 第 10 页 共 22 页

}

len=strlen(ch); content= ( 3 )new char[50]; if(!content) { }

cout<<\exit(1);

strcpy(content,ch);

cout<

void String::display(){ void String::upper_str(){ }

for (int i=0;i

if ( 4 )(’a’<= content[i]&& content[i] <=’z’) content[i]= ( 5 ) content[i]+32; 5. 下列程序定义了类Point,请完成前置--和后置--的运算符函数的定义。 class Point{ };

Point Point::operator --() { }

Point Point::operator --(int) { }

void Point::display() {

cout<<\

( 7 ) Point temp;temp=*this; x--;

y=y--;

( 8 )return temp; x--;

y--;

return ( 6 )*this; float x,y;

Point(float xx=0,float yy=0){ x=xx; y=yy; } Point operator --(); Point operator --(int); void display(); public:

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库c++面向对象复习题答案版(2)在线全文阅读。

c++面向对象复习题答案版(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/649086.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: