成人高考C++语言程序设计期末复习题资料知识点复.docx

上传人:b****6 文档编号:16828589 上传时间:2023-07-17 格式:DOCX 页数:18 大小:18.21KB
下载 相关 举报
成人高考C++语言程序设计期末复习题资料知识点复.docx_第1页
第1页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第2页
第2页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第3页
第3页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第4页
第4页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第5页
第5页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第6页
第6页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第7页
第7页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第8页
第8页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第9页
第9页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第10页
第10页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第11页
第11页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第12页
第12页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第13页
第13页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第14页
第14页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第15页
第15页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第16页
第16页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第17页
第17页 / 共18页
成人高考C++语言程序设计期末复习题资料知识点复.docx_第18页
第18页 / 共18页
亲,该文档总共18页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

成人高考C++语言程序设计期末复习题资料知识点复.docx

《成人高考C++语言程序设计期末复习题资料知识点复.docx》由会员分享,可在线阅读,更多相关《成人高考C++语言程序设计期末复习题资料知识点复.docx(18页珍藏版)》请在冰点文库上搜索。

成人高考C++语言程序设计期末复习题资料知识点复.docx

成人高考C++语言程序设计期末复习题资料知识点复

电大C++语言程序设计期末复习题及答案考点归纳总结资料

一、单项选择题

1、面向对象程序设计数据与_____放在一起,作为一个相互依存、不可分割的整体来处理。

A、对数据的操作B、信息C、数据隐藏D、数据抽象

2、已知:

inta=1,b=2,c=3,d=4,则表达式a

a:

c

c:

d的值为_____。

A、1B、2C、3D、4

3、下列while循环的次数是_____。

while(inti=0)i--;

A、0B、1C、5D、无限

4、以下程序的输出结果是_____。

#include

fuc(char*s)

{

char*p=s;

while(*p)

p++;

return(p-s);

}

main()

{

cout<

}

A、3B、6C、8D、0

5、_____的功能是对对象进行初始化。

A、析构函数B、数据成员C、构造函数D、静态成员函数

6、下列引用的定义中,_____是错误的。

A、inti;B、inti;C、floati;D、chard;

int&j=i;int&j;float&j=i;j=i;char&k=d;

7、若类A和类B的定义如下:

classA

{

inti,j;

public:

voidget();

//...

};

classB:

publicA

{

intk;

public:

make();

//...

};

voidB:

:

make()

{

k=i*j;

}

则上述定义中,_____是非法的表达式。

A、voidget();B、intk;C、voidmake();D、k=i*j;

8、以下程序段_____。

intx=-1;

do

{

x=x*x;

}while(!

x);

A、是死循环B、循环执行2次C、循环执行1次D、有语法错误

9、对定义重载函数的下列要求中,_____是错误的。

A、要求参数的个数不同B、要求参数中至少有一个类型不同

C、要求参数个数相同时,参数类型不同D、要求函数的返回值不同

10、一个_____允许用户为类定义一种模式,使得类中的某些数据成员及某些成员函数的返回值能取任意类型。

A、函数模板B、模板函数C、类模板D、模板类

(Key:

1-5:

AAABC6-10:

BDCDC)

二、填空题

1、在C++类中可以包含[]、[]和[]三种具有不同访问控制权的成员。

(Key:

公有或public,保护或protected,私有或private)

2、以下程序的执行结果是_____。

#include

voidfunc(int);

voidfunc(double);

voidmain()

{

doublea=88.18;

func(a);

intb=97;

func(b);

}

voidfunc(intx)

{

cout<

}

voidfunc(doublex)

{

cout<

}

(Key:

88.18,97)

3、类中的数据和成员函数默认访问类型为_____。

(Key:

私有或private)

4、以下程序的执行结果是_____。

#include

usingnamespacestd;

f(intb[],intn)

{

inti,r=1;

for(i=0;i<=n;i++)

r=r*b[i];

returnr;

}

int_tmain()

{

intx,a[]={2,3,4,5,6,7,8,9};

x=f(a,3);

cout<<"x="<

return0;

}

(Key:

x=120)

5、在类内部定义的_____数据不能被不属于该类的函数来存取,定义为_____的数据则可以在类外部进行存取。

(Key:

private或私有或protected或保护;public或公有)

6、下列程序输出的结果是_____。

#include

usingnamespacestd;

voidsub(chara,charb)

{

charc=a;

a=b;

b=c;

}

voidsub(char*a,charb)

{

charc=*a;

*a=b;

b=c;

}

voidsub(char*a,char*b)

{

charc=*a;

*a=*b;

*b=c;

}

int_tmain()

{

chara='A',b='B';

sub(&a,&b);

cout<

return0;

}

(Key:

BA)

7、下列程序输出的结果是_____。

#include

usingnamespacestd;

voidExchange(int*pFirst,int*pLast)

{

if(pFirst

{

intChange=*pFirst;

*pFirst=*pLast;

*pLast=Change;

Exchange(++pFirst,--pLast);

}

}

voidPrint(intInteger[],intHowMany)

{

for(intIndex=0;Index

cout<

cout<

}

int_tmain()

{

intInteger[]={1,2,3,4};

Exchange(&Integer[0],&Integer[3]);

Print(Integer,4);

return0;

}

(Key:

4321)

8、下列程序输出的结果是_____。

#include

usingnamespacestd;

int_tmain()

{

intnInteger=5,&rInteger=nInteger;

rInteger=nInteger+1;

cout<

return0;

}

(Key:

6,6)

9、___________是一种特殊的成员函数,它主要用来为对象分配内存空间,对类的数据成员进行初始化并进行对象的其他内部管理操作。

(构造函数)

10、下列程序输出的结果是_____。

#include

usingnamespacestd;

int_tmain()

{

intx=2,y=3,z=4;

cout<<((x

z)||(x*y))<

return0;

}

(Key:

1)

三、程序分析:

给出程序运行后的输出结果(每小题5分,共20分)

1、#include

usingnamespacestd;

int_tmain()

{

intx=1,y=2,z=3;

x+=y+=z;

cout<<(x

y:

x)<<",";

cout<<(x

x++:

y++)<<",";

cout<

return0;

}

Key:

6,5,6

2、#include

usingnamespacestd;

voidfunc(intb[]);

voidmain()

{

inta[]={5,6,7,8},i;

func(a);for(i=0;i<4;i++)

cout<

}

voidfunc(intb[])

{

intj;

for(j=0;j<4;j++)

b[j]=2*j;

}

Key:

0246

3、#include

usingnamespacestd;

classCSample

{

inti;

public:

CSample(void);

~CSample(void);

CSample(intval);

voidPrint(void);

};

CSample:

:

CSample(void)

{

cout<<"Constructor1"<

i=0;

}

CSample:

:

CSample(intval)

{

cout<<"Constructor2"<

i=val;

}

voidCSample:

:

Print(void)

{

cout<<"i="<

}

CSample:

:

~CSample(void)

{

cout<<"Destructor"<

}

int_tmain()

{

CSamplea,b(10);

a.Print();

b.Print();

return0;

}

Key:

Constructor1

Constructor2

i=0

i=10

Destructor

Destructor

4、#include

usingnamespacestd;

classCData

{

protected:

intnInteger;

public:

CData(intInteger);

~CData(void);

voidPrint(void);

};

CData:

:

CData(intInteger)

:

nInteger(Integer)

{

cout<<"Constructingadata"<

}

CData:

:

~CData(void)

{

cout<<"Destructingadata"<

}

voidCData:

:

Print(void)

{

cout<<"Thedatais"<

}

classCNumber:

publicCData

{

protected:

doublefNumber;

public:

CNumber(intInteger,doubleNumber);

~CNumber(void);

voidPrint(void);

};

CNumber:

:

CNumber(intInteger,doubleNumber)

:

CData(Integer)

fNumber(Number)

{

cout<<"Constructinganumber"<

}

CNumber:

:

~CNumber(void)

{

cout<<"Destructinganumber"<

}

voidCNumber:

:

Print(void)

{

CData:

:

Print();

cout<<"Thenumberis"<

}

int_tmain()

{

CNumberNumber(1,3.8);

Number.Print();

return0;

}

Key:

Constructingadata

Constructinganumber

Thedatais1

Thenumberis3.8

Destructinganumber

Destructingadata

四、根据要求完成程序

1、完成以下程序,求1!

+2!

+3!

+4!

+5!

+6!

+7!

+8!

+9!

+10!

之和。

#include

usingnamespacestd;

int_tmain()

{

longTerm=________________,Sum=________________;

for(intIndex=1;Index<=________________;Index++)

{

Term*=________________;

Sum+=________________;

}

cout<<"Sumoffactorialfrom1to10is";

cout<

return0;

}

Key:

1010IndexTerm

2、完成下面程序,计算三角形和正方形的面积。

设三角形和正方形的宽为fWidth,高为fHeight,则三角形的面积为fWidth*fHeigth/2。

#include

usingnamespacestd;

classCShape

{

public:

CSquare:

:

CSquare(doubleWidth,doubleHeight)

:

____________________________________

}

doubleCSquare:

:

Area(void)

{

____________________________________;

}

int_tmain()

{

CTriangleTriangle(16,8);

cout<<"Theareaoftriangleis"<

CSquareSquare(13,8);

cout<<"Theareaofsquareis"<

return0;

}

Key:

fWidth(Width)CShape(Width,Height)returnfWidth*fHeight/2

CShape(Width,Height)returnfWidth*fHeight

五、用面向对象方法设计一个阶乘类CFactorial,在CFactorial类的构造函数CFactorial(longInteger)中,将Integer的值赋给nInteger;在主函数int_tmain(),键盘输入任一整数Integer,以Integer的值为实际参数构造一个阶乘对象Factorial,调用对象Factorial的相应成员函数输出nInteger的阶乘值fFactorial。

完成以下函数的代码设计:

(1)、设计构造函数CFactorial(longInteger),求出nInteger的阶乘值fFactorial。

若nInteger没有阶乘值,则fFactorial赋值为0。

(2)、设计CFactorial类的成员函数voidPrint(void),输出nInteger的阶乘值fFactorial。

若nInteger没有阶乘,则输出nInteger没有阶乘的信息。

#include

usingnamespacestd;

classCFactorial

{

public:

CFactorial(longInteger);

protected:

longnInteger;

floatfFactorial;

public:

voidPrint(void);

};

CFactorial:

:

CFactorial(longInteger)

:

nInteger(Integer)

{

//作答处

}

voidCFactorial:

:

Print(void)

{

//作答处

}

int_tmain()

{

longInteger;

cout<<"Enterainteger:

";

cin>>Integer;

CFactorialFactorial(Integer);

Factorial.Print();

return0;

}

Key:

解:

参考程序:

#include

usingnamespacestd;

classCFactorial

{

public:

CFactorial(longInteger);

protected:

longnInteger;

floatfFactorial;

public:

voidPrint(void);

};

CFactorial:

:

CFactorial(longInteger)

:

nInteger(Integer)

{

if(nInteger<0)//1分

fFactorial=0;//1分

else//1分

{

fFactorial=1;//1分

while(Integer>1)//1分

{

fFactorial*=Integer;//1分

Integer--;//1分

}

}

}

voidCFactorial:

:

Print(void)

{

if(fFactorial)//0.5分

cout<<"Thefactorialof"<

//1分

else//0.5分

cout<<"Thereisnotanyfactorialfor"<

}

int_tmain()

{

longInteger;

cout<<"Enterainteger:

";

cin>>Integer;

CFactorialFactorial(Integer);

Factorial.Print();

return0;

}

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

当前位置:首页 > 工程科技 > 能源化工

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

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