




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
电大c+语言程序设计期末复习题及答案考点归纳总结资料一、单项选择题1、 面向对象程序设计数据与_放在一起,作为一个相互依存、不可分割的整体来处理。a、对数据的操作b、信息c、数据隐藏d、数据抽象2、 已知:int a=1,b=2,c=3,d=4,则表达式ab?a:cd?c:d 的值为_。a、1b、2c、3d、43、下列while循环的次数是_。while( int i=0 ) i- -;a、0b、1c、5d、无限4、以下程序的输出结果是_。#include fuc( char* s) char* p=s; while( *p) p+; return (p-s);main() coutfuc(abcdef); a、3b、6c、8d、05、_的功能是对对象进行初始化。a、析构函数b、数据成员c、构造函数d、静态成员函数6、下列引用的定义中,_是错误的。a、int i;b、int i;c、float i;d、char d;int& j=i; int &j; float& j=i;j=i; char &k=d;7、若类a和类b的定义如下:class a int i,j;public: void get(); /.;class b:public a int k;public: make(); /.;void b:make() k=i*j;则上述定义中,_是非法的表达式。a、void get();b、int k;c、void make();d、k=i*j;8、以下程序段_。int x = -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 void func( int );void func( double );void main( ) double a=88.18; func(a); int b=97; func(b); void func( int x ) coutxendl;void func( double x ) coutx,;(key: 88.18,97)3、类中的数据和成员函数默认访问类型为_。(key:私有或private)4、以下程序的执行结果是_。#include using namespace std;f(int b,int n)int i,r=1;for( i=0;i=n;i+ )r=r*bi;return r;int _tmain()int x,a = 2,3,4,5,6,7,8,9;x=f(a,3);coutx=xendl;return 0;(key: x=120)5、在类内部定义的_数据不能被不属于该类的函数来存取,定义为_的数据则可以在类外部进行存取。(key:private或 私有 或 protected 或 保护;public 或 公有)6、下列程序输出的结果是_。#include using namespace std;void sub( char a,char b )char c=a;a=b;b=c;void sub( char* a,char b )char c=*a;*a=b;b=c;void sub( char* a,char* b )char c=*a;*a=*b;*b=c;int _tmain() char a=a,b=b;sub(&a,&b);coutabendl;return 0;(key: ba)7、下列程序输出的结果是_。#include using namespace std;void exchange( int* pfirst,int* plast )if( pfirstplast )int change = *pfirst;*pfirst = *plast;*plast = change;exchange(+pfirst,-plast);void print( int integer,int howmany)for( int index=0; indexhowmany; index+ )coutintegerindex ;coutendl;int _tmain()int integer = 1,2,3,4;exchange(&integer0,&integer3);print(integer,4);return 0;(key: 4 3 2 1)8、下列程序输出的结果是_。#include using namespace std;int _tmain()int ninteger = 5, &rinteger = ninteger;rinteger = ninteger+1;coutninteger,rintegerendl;return 0;(key: 6,6)9、_是一种特殊的成员函数,它主要用来为对象分配内存空间,对类的数据成员进行初始化并进行对象的其他内部管理操作。(构造函数)10、下列程序输出的结果是_。#include using namespace std;int _tmain()int x=2,y=3,z=4;cout( xy ) & ( !z ) | (x*y) )endl;return 0;(key:1)三、程序分析:给出程序运行后的输出结果(每小题5分,共20分)1、#include using namespace std;int _tmain() int x=1,y=2,z=3; x+=y+=z; cout(xy?y:x),; cout(xy?x+:y+),; coutyendl; return 0;key: 6,5,6 2、#include using namespace std;void func( int b );void main() int a = 5,6,7,8 ,i; func(a); for( i=0;i4;i+ ) coutai ;void func( int b ) int j; for( j=0;j4;j+ ) bj = 2*j;key: 0 2 4 63、#include using namespace std;class csampleint i;public:csample(void);csample(void);csample(int val);void print(void);csample:csample(void)coutconstructor1endl;i=0;csample:csample(int val)coutconstructor2endl;i=val;void csample:print(void)couti=iendl;csample:csample(void)coutdestructorendl;int _tmain() csample a,b(10);a.print();b.print();return 0;key: constructor1constructor2i=0i=10destructordestructor4、#include using namespace std;class cdataprotected:int ninteger;public:cdata( int integer );cdata( void );void print(void);cdata:cdata( int integer ): ninteger(integer)coutconstructing a dataendl;cdata:cdata( void )coutdestructing a dataendl;void cdata:print(void)coutthe data is nintegerendl;class cnumber :public cdataprotected:double fnumber;public:cnumber(int integer,double number);cnumber(void);void print(void);cnumber:cnumber( int integer,double number ): cdata( integer ), fnumber(number)coutconstructing a numberendl;cnumber:cnumber( void )coutdestructing a numberendl;void cnumber:print(void)cdata:print();coutthe number is fnumberendl;int _tmain()cnumber number(1,3.8);number.print();return 0;key: constructing a dataconstructing a numberthe data is 1the number is 3.8destructing a numberdestructing a data四、根据要求完成程序1、完成以下程序,求1!+2!+3!+4!+5!+6!+7!+8!+9!+10!之和。#include using namespace std;int _tmain() long term=_ ,sum=_;for( int index=1;index=_;index+)term *=_;sum +=_;coutsum of factorial from 1 to 10 is ; coutsumendl;return 0; key:1 0 10 index term2、完成下面程序,计算三角形和正方形的面积。设三角形和正方形的宽为fwidth,高为fheight,则三角形的面积为fwidth*fheigth/2。#include using namespace std;class cshapepublic:csquare:csquare(double width,double height):_double csquare:area(void)_;int _tmain() ctriangle triangle(16,8); coutthe area of triangle is triangle.area()endl; csquare square(13,8); coutthe area of square is square.area()endl; return 0; key: fwidth(width) cshape(width,height) return fwidth*fheight/2 cshape(width,height) return fwidth*fheight五、用面向对象方法设计一个阶乘类cfactorial,在cfactorial类的构造函数cfactorial(long integer)中,将integer的值赋给ninteger;在主函数int _tmain(),键盘输入任一整数integer,以integer的值为实际参数构造一个阶乘对象factorial,调用对象factorial的相应成员函数输出ninteger的阶乘值ffactorial。完成以下函数的代码设计:(1)、设计构造函数cfactorial(long integer),求出ninteger的阶乘值ffactorial。若ninteger没有阶乘值,则ffactorial赋值为0。(2)、设计cfactorial类的成员函数void print(void),输出ninteger的阶乘值ffactorial。若ninteger没有阶乘,则输出ninteger没有阶乘的信息。#include using namespace std;class cfactorialpublic:cfactorial(long integer);protected:long ninteger;float ffactorial;public:void print(void);cfactorial:cfactorial(long integer) : ninteger(integer)/作答处void cfactorial:print(void)/作答处int _tmain()long integer;coutinteger; cfactorial factorial(integer);factorial.print();return 0; key: 解:参考程序:#include using namespace std;class cfactorialpublic:cfactorial(long integer);protected:long ninteger;float ffactorial;public:void print(void);cfactorial:cfactorial(long integer) : ninteger(integer)if( ninteger1 )
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年消防安全知识培训考试题库:消防安全管理体系现场管理实战演练试题
- 2025年高压电工技师理论考试:高压继电保护原理难点试题解析
- 2025年专升本艺术概论模拟试卷:艺术批评理论与实践跨文化比较试题
- 202年初中学业水平考试地理模拟卷及答案(自然地理专项)-地理知识在环境保护中的应用试题卷
- 2025年消防执业资格考试题库:消防救援队伍管理法规政策解析题库
- 养老服务考试试题及答案
- 机务检修考试试题及答案
- 大学官网考试试题及答案
- 课程标准考试试题及答案
- 2025年四川省广安市岳池县中考数学二诊试卷
- 2025年重庆市中考物理模拟试卷(一)(含解析)
- 《服务营销双主动》课件
- 公司法公章管理制度
- 演出经纪人员资格备考资料2025
- 希尔顿管理制度
- 成都交通投资集团有限公司招聘考试真题2024
- (二模)嘉兴市2025年高三教学测试语文试卷(含答案)
- 湖北省宜昌二中2025年高考化学考前最后一卷预测卷含解析
- 医院不良事件上报制度
- MTK安全架构研究-全面剖析
- 餐饮食堂消防安全培训
评论
0/150
提交评论