四川大学C++面向对象程序设计模拟试地的题目7.docx

上传人:b****1 文档编号:254174 上传时间:2023-04-28 格式:DOCX 页数:16 大小:18.53KB
下载 相关 举报
四川大学C++面向对象程序设计模拟试地的题目7.docx_第1页
第1页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第2页
第2页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第3页
第3页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第4页
第4页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第5页
第5页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第6页
第6页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第7页
第7页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第8页
第8页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第9页
第9页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第10页
第10页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第11页
第11页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第12页
第12页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第13页
第13页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第14页
第14页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第15页
第15页 / 共16页
四川大学C++面向对象程序设计模拟试地的题目7.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

四川大学C++面向对象程序设计模拟试地的题目7.docx

《四川大学C++面向对象程序设计模拟试地的题目7.docx》由会员分享,可在线阅读,更多相关《四川大学C++面向对象程序设计模拟试地的题目7.docx(16页珍藏版)》请在冰点文库上搜索。

四川大学C++面向对象程序设计模拟试地的题目7.docx

四川大学C++面向对象程序设计模拟试地的题目7

C++面向对象程序设计模拟试题七

一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。

错选、多选或未选均无分。

1.下列语句中,错误的是()。

A)constintbuffer=168;B)constintnum;

C)constdouble*p;D)double*constp=newdouble;

2.C++中的模板包括()。

A)对象模板和函数模板B)对象模板和类模板

C)函数模板和类模板D)变量模板和对象模板

3.对于常对象,C++遵循()。

A)通过常对象可以调用常成员函数

B)通过常对象可以所有成员函数

C)常对象的成员都是常成员

D)通过常对象可以调用任何不改变对象值的成员函数

4.以下关键字不能用来声明类的访问权限的是()。

A)publicB)staticC)protectedD)private

5.下列关于this指针的叙述中,正确的是()。

A)与类相关的所有函数都含有this指针

B)所有类的成员函数都有this指针

C)所有函数都有this指针

D)只有类的非静态成员函数才有this指针

6.派生类的成员函数不能直接访问基类的()。

A)保护成员B)公有成员

C)私有成员D)前面各选项都正确

7.在下列函数原型中,可以作为类Test构造函数的是()。

A)voidTest(int);B)intTest();

C)~Test(int);D)Test(int);

8.在下面4个关键字中,用于说明虚基类的是()。

A)virtualB)public

C)protectedD)private

9.在C++中,用于实现编译时多态性的是()。

A)友元函数B)重载函数

C)静态成员函数D)虚函数

10.下列关于C++函数的说明中,正确的是()。

A)内置函数就是定义在另一个函数体内部的函数

B)函数体的最后一条语句必须是return语句

C)C++标准要求在调用一个函数之前,如果没定义函数,则必须先声明其原型

D)编译器会根据函数的返回值类型和参数表来区分函数的不同重载形式

二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。

错填或不填均无分。

1.一个函数名为Show,返回值类型为void,没有参数的纯虚常成员函数可以声明为()。

2.若将一个二元运算符重载为类的友员函数,其形参个数应该是()个。

3.采用struct定义的类中数据成员和成员函数的默认访问权限是()。

4.在面向对象方法中,()描述的是具有相同属性与操作的一组对象。

5.模板类型形参表使用的关键字为()。

三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。

1.阅读下面程序,写出输出结果。

#include

usingnamespacestd;

classTest

{

private:

intn;

public:

Test(inti=16){n=i;}

intGet(){returnn;}

intGet()const{returnn-2;}

};

intmain()

{

Testa;

constTestb(18);

cout<

return0;

}

上面程序的输出结果为:

 

2.阅读下面程序,写出输出结果。

#include

usingnamespacestd;

classA

{

public:

A(){cout<<"A"<

~A(){cout<<"~A"<

};

classB:

A

{

public:

B(){cout<<"B"<

~B(){cout<<"~B"<

};

intmain()

{

Bobj;

return0;

}

上面程序的输出结果为:

 

3.阅读下面程序,写出输出结果。

#include

usingnamespacestd;

intf(inta){returna*a+8;}

template

Tf(constT&a){returna*a;}

intmain()

{

cout<

(1)<<","<

return0;

}

上面程序的输出结果为:

 

4.阅读下面程序,写出输出结果。

#include

usingnamespacestd;

namespacens

{

intx=18;

}

intx=5;

intmain()

{

intx=10;

cout<

:

x<<""<

:

x<

return0;

}

上面程序的输出结果为:

 

5.阅读下面程序,写出输出结果。

#include

usingnamespacestd;

classA

{

public:

virtualvoidShow()const{cout<<"A:

:

Show()"<

};

classB:

publicA

{

public:

voidShow()const{cout<<"B:

:

Show()"<

};

voidRefers(constA&obj)

{

obj.Show();

}

intmain()

{

Aobj1;

Bobj2;

Refers(obj1);

Refers(obj2);

return0;

}

上面程序的输出结果为:

 

6.阅读下面程序,写出输出结果。

#include

usingnamespacestd;

classA

{

protected:

inta;

public:

A(intx):

a(x){}

voidShow()const{cout<

};

classB:

publicA

{

protected:

intb;

public:

B(intx,inty):

A(x),b(y){}

voidShow()const{cout<

};

intmain()

{

Bobj(18,5);

obj.Show();

obj.A:

:

Show();

return0;

}

上面程序的输出结果为:

 

四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。

1.将如下程序补充完整。

#include

usingnamespacestd;

classInteger

{

private:

intn;

public:

Integer(intn):

n(n){}

Integer&[1]{--n;return*this;}//重载前缀--运算符

voidShow()const{cout<

};

intmain()

{

Integeri(168);

--i;

i.Show();

return0;

}

2.将如下程序补充完整。

#include

usingnamespacestd;

classA

{

private:

inta;

public:

A(intm=0):

a(m){}

[2]//类型转换函数,A类对象转转成int型量

{returna;}

};

intmain()

{

Aa=8.14;

cout<

return0;

}

3.将如下程序补充完整。

#include

usingnamespacestd;

classA

{

private:

intm;

public:

A(inta):

m(a){}

virtualvoidShow()const{cout<

};

classB:

publicA

{

private:

intn;

public:

B(inta,intb):

A(a){n=b;}

voidShow()const{cout<

};

intmain()

{

Bobj(158,98);

[2]Show();//调用基类的Show()

return0;

}

4.将如下程序补充完整。

#include

usingnamespacestd;

classComplex

{

private:

doublerealPart;

doubleimagePart;

public:

Complex(doublereal=0,doubleimage=0):

realPart(real),imagePart(image){}

Complex[3](constComplex&a)const//重载减法运算符+

{returnComplex(realPart-a.realPart,imagePart-a.imagePart);}

voidShow()const{cout<

};

intmain()

{

Complexa(2,9),b(1,1),c;

c=a-b;

cout<<"a=";a.Show();

cout<<"b=";b.Show();

cout<<"c=";c.Show();

return0;

}

五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)

1.试使用函数模板实现求一个数组各元素的积,要求编写测试程序。

函数模板声明如下:

template

TypeMul(Typea[],intn);//求数组a各元素的积

2.设计一个日期类Date,,要求:

(1)包含年(year)、月(month)和日(day)私有数据成员。

(2)包含构造函数,重载输出运算符“<<”与重载输入运算符“>>”。

要求编写测试程序。

 

C++面向对象程序设计模拟试题七参考答案

一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。

错选、多选或未选均无分。

1.B)2.C)3.A)4.B)5.D)

6.C)7.D)8.A)9.B)10.C)

二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。

错填或不填均无分。

1.参考答案:

virtualvoidShow()const=0;

2.参考答案:

2

3.参考答案:

public或公有

4.参考答案:

5.参考答案:

class

三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。

1.参考答案:

16,16

2.参考答案:

A

B

~B

~A

3.参考答案:

9,1

4.参考答案:

10518

5.参考答案:

A:

:

Show()

B:

:

Show()

6.参考答案:

5

18

四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。

1.参考答案:

[1]operator--()

2.参考答案:

[2]operatorint()const或operatorint()

3.参考答案:

[3]obj.A:

:

4.参考答案:

[4]operator-

五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)

1.参考程序:

#include

usingnamespacestd;

template

TypeMul(Typea[],intn)//求数组a各元素的积

{

Typet=1;

for(inti=0;i

t*=a[i];

returnt;

}

intmain()

{

inta[]={1,2,3,4,5,6,7,8,9};

cout<

return0;

}

2.参考程序:

#include

usingnamespacestd;

classDate

{

private:

intyear;

intmonth;

intday;

public:

Date(inty=2010,intm=1,intd=1):

year(y),month(m),day(d){}

voidSetYear(inty){year=y;}

voidSetMonth(intm){month=m;}

voidSetDay(intd){day=d;}

intGetYear()const{returnyear;}

intGetMonth()const{returnmonth;}

intGetDay()const{returnday;}

};

istream&operator>>(istream&in,Date&dt)

{

inty,m,d;

cout<<"输入年:

";

in>>y;

cout<<"输入月:

";

in>>m;

cout<<"输入日:

";

in>>d;

dt.SetYear(y);

dt.SetMonth(m);

dt.SetDay(d);

returnin;

}

ostream&operator<<(ostream&out,constDate&dt)

{

cout<

returnout;

}

intmain()

{

Dated;

cin>>d;

cout<

return0;

}

 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2