




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、高级语句程序设计() 一、单项选择题 、在一个程序中,main 函数的位置() 。 必须在程序的开头 必须在程序的后面 可以在程序的任何地方 必须在其它函数中间 、程序基本单位是() 。 数据 字符 函数 语句 、执行语句 int i=10,*p=后,下面描述错误的是() 。 p 的值为 10 p 指向整型变量 i *p 表示变量 i 的值 p 的值是变量 i 的地址 、执行语句 int a=5,b=10,c;int *p1=后,下面不正确的赋值语句是 () 。 *p2=b; p1=a; p2=p1; c=*p1(*p2); 、设 i=1,j=2,则表达式 i+ +j 的值为() 。 1 2
2、3 4 、设 i=1,j=2,则表达式+i+j 的值为() 。 1 2 3 4 、执行下列语句后,x 的值是() ,y 的值是() 。 int x,y; x=y=1;+x|+y; 不确定 0 1 2 、已知 x=5,则执行语句x+=x-=xx; 后,x 的值为() 。 25 40 -40 20 、已知 a=4,b=6,c=8,d=9,则“(a+,ba+ char c=A; x=(a 执行该程序段后,x 的值为() 。 ture false 0 1 11、下面程序的输出结果是() 。 #include using namespace std; int main( ) int a=6,b=6; i
3、f(a5) a-=1; b+=1; else a+=1; b-=1; cout”a=”aendl; cout”b”b5) a-=1; b+=1; else a+=1; b-=1; cout”a=”aendl; cout”b”bendl; return 0; 57 a=5b=7 a=5b=6 a=6b=5 13、下面程序的输出结果是() #include using namespace std; int main( ) int x=6,y=8; if(x+6) cout+y6) cout -yendl; else couty+endl; return 0; 8 7 9 编译时出错 14、下面程序
4、的输出结果是() #include using namespace std; int main( ) int x=6,y=8; if(+x6) cout+yendl; else couty+6) cout -yendl; return 0; 8 8 9 7 7 8 编译时出错 15、下面程序的输出结果是() #include using namespace std; f(int a) int b=0; static int c=3; b+;c+; return (a+b+c); int main( ) int a=2,i; for(i=0;i3;i+) coutf(a)endl; return
5、 0; 7 8 9 7 7 7 7 10 13 7 9 11 16、下面程序的输出结果是() #include using namespace std; void fun(int x,int y,int z) z=xx+yy; int main( ) int z=68; fun(5,2,z); coutz; return 0; 0 29 68 无定值 17、下面程序的输出结果是() #include using namespace std; int fun(int a,int b) return (+ab+); int main( ) int x=3,y=4,z=5,r; r=fun(fun(
6、x,y),z); coutrxy2) return (fib(n-1)+fib(n-2); else return (n); int main( ) int i; couti; coutendl; coutfib(i)endl; return 0; 5 1 4 2 5 2 6 2 19、下面程序的输出结果为() #include using namespace std; unsigned func(unsigned num) unsigned d=1,k; do k=num%10; num/=10; while(num); return (k); int main( ) unsigned n=
7、26; coutfunc (n); return 0; 2 4 6 5 20、下面程序的输出结果为() #include using namespace std; func (int a,int b) int c; c=ab; return (c ); int main( ) int x=6,y=7,z=8,r; r=func(x-,y,xy),z-); coutr; return 0; 294 245 280 416 21、下面程序的输出结果为() #include using namespace std; int main( ) int a33=1,2,3,4,5; int s=0; fo
8、r (int i=1;i3;i+) for(int j=0;j=i;j+) s+=aij; coutsendl; return 0; 12 14 15 13 22、下面程序的输出结果是() #include using namespace std; void fun(int *x,int *y) cout*x” “*y” “; x=3;y=4; int main( ) int x=1,y=2; fun( coutx” “y; return 0; 2 1 4 3 1 2 1 2 2 1 1 2 1 2 3 4 23、下面程序的输出结果是() #include using namespace st
9、d; int main( ) int a10=9,8,7,6,5,4,3,2,1,0,*p=a+5; coutp=5; a1.*p=5; *a1.p=5; 38、已知类 A 中一个成员函数说明如下: void Set(A(A) CSample;(B) public: CSample(int val);(C) CSample;(D) ; 40、下面程序的输出结果是() #include using namespace std; class point public: void poi(int px=10,int py=10) x=px; y=py; getpx( ) return x; getp
10、y( ) return y; private: int x,y; ; int main( ) point p,q; p.poi(); q.poi(15,15); cout“p 点的坐标是: ”p.getpx( )“, ” ; coutp.getpy( )endl; cout“q 点的坐标是: ”q.getpx( )“, ” ; coutq.getpy( )endl; return 0; p 点的坐标是:10,10 p 点的坐标是:0,0 q 点的坐标是:15,15q 点的坐标是:15,15 p 点的坐标是:0,0 p 点的坐标是:10,10 q 点的坐标是:0,0q 点的坐标是:10,10 答
11、案 1.(3)2. (3)3. (1)4. (2)5. (3)6. (4)7. (4) (3)8. (3)9. (4)10. (4) 11. (4)12. (4)13. (3)14. (1)15.(1)16.(3)17.(1)18.(3)19.(1)20.(3) 21.(1)22.(1)23.(3)24.(3)25(3) 26(4) 27(1) 28(4) 29(2) 30(3) 31(2)32(4)33(1)34(1) 35(3) 36(2) 37(3) 38(3)39 (A)40(1) 二、判断题 、任何字符常量与一个任意大小的整型数进行加减都是有意义的。 () 、在命名标识符中,大小写字
12、母是不加区分的。 () 、引用是某个变量的别名。对引用的操作,实质上就是对被引用的变量的操作。 () 、typedef 类型定义是原来定义一些中所没有的新类型。() 、枚举变量的取值收到该枚举变量所对应的枚举表中枚举常量的局限。 () 、已知:int a(5);表达式(a=7)+a 具有二义性。 () 、预处理命令是在进行编译时首先执行的,然后再进行正常编译。 () 、条件编译命令只在编译时才有用。 () 、开关语句不可以嵌套,在开关语句的语句序列中不能再有开关语句。 () 10、switch 语句中必须有 break 语句,否则无法退出 switch 语句。 () 11、while 循环语句
13、的循环体最少执行一次。 () 12、只有 for 循环的循环体可以是空语句,其它种类循环的循环体不能用空语句。 () 13、当循环体为空语句时,说明该循环体不做任何工作,只起延时作用。 () 14、在多重循环中,内重循环的循环变量引用的次数比外重的多。() 15、在中,说明函数时要用函数原型,即定义函数时的函数头部分。 () 16、如果一个函数没有返回值,定义时需用 void 说明。 () 17、使用内置函数是以增大空间开销为代价的。 () 18、返回值类型、参数个数和类型都相同的函数也可以重载。 () 19、在设置了参数默认值后,调用函数的对应实参就必须省略。 () 20、函数形参的作用域是
14、该函数的函数体。 () 21、定义外部变量时,不用存储类说明符 extern,而声明外部变量时用它。 () 22、内部静态类变量与自动类变量作用域相同,但是生存期不同。 (.) 23、静态类标识符在它的作用域之外是不存在的。 () 24、使用关键字 class 定义的类中默认的访问权限是私有的(private) 。 ( ) 25、指向对象的指针和指向类的成员的指针在表达形式上是不相同的。 () 26、一维对象指针数组的每个元素应该是某个类的对象的地址值。 () 27、一个类的构造函数中可以不包含对其子对象的初始化。 () 28、派生类是从基类派生出来,它不能再生成新的派生类。 () 29、在公
15、有继承中,基类中的公有成员和私有成员在派生类中都是可见的。 ( ) 30、单继承情况下,派生类中对基类成员的访问也会出现二义性。 () 31、构造函数可以被继承。 () 32、析构函数不能被继承。 () 33、解决多继承情况下出现二义性的方法之一是使用成员名限定法。 () 34、子类型是不可逆的。 () 答案 1.2.3.4.5.6.7.8.9.10.11.12.13.14. 15.16.17.18.19.20.21.22.23.242526 2728293031323334 三、填空题 、下面程序是计算 110 之间偶数之和,请填空: #include using namespace std
16、; int main( ) int a,b,i; a=0;b=0; for(i=0;i=10;i+) a+=i; ; ; cout”偶数之和为:”aendl; return 0; 、下面程序是输出 100 内能被 3 整除且个位数是 6 的所有整数,请填空: #include using namespace std; int main( ) int i,j; for(i=0;i10;i+) j=i10+6; if(j%3!=0 ) continue; else; coutjendl; ; return 0; 、结构体类型与数组不同,数组中的数据的类型是相同 的,结构体的成员的数据类型 是不同,
17、共用体类似于结构体,但是共用体的部分成员是公用部分内存空间,枚举 类型是整型常量的集合。 、常量与变量的区别是:常量在程序运行中值不变,因此它的值在编译时便进 行初始化; 而变量的值是可以改变的, 指针类型的变量存储的是变量的 地址,不是变量的值。 、 函数的形参在未被调用前不分配空间, 函数的形参的类型及数量要和实参相同。 若类型不同,则按一般规则转换,若数量不同,则出错。 、函数的递归分为直接递归,间接递归,递归由递归方式、递归终止条件 两部分组成。一般说,一个问题的解决要依靠另一问题的解决,而另一个问题的解决方法与 上一问题的解决方法相同,则可用递归方法处理。 、下面程序的功能是:求 a
18、 的 b 次方,并输出,请填空。 #include using namespace std; double fun (double a,int b) int i; double z; for(i=1,z=1;i=b;i+) z=z*a; return(z); int main( ) double a; int b; couta; coutendl; coutb; coutendl; coutfun(a,b); cout=a) else i=3; ; int main( ) int i; coutch; i=fun(ch); if (i=1) cout”是小写字母:”chendl; else i
19、f (i=2) cout”是大写字母:”chendl; else cout”是其它字符:”chendl; return 0; 、下面是字符串拷贝程序,请填空。 void ccopy( ) char ch1=”good morning!”,ch220; int i=0,j=0; while(ch1i) ch2j= ch1i+; j+; Ch2j=0; 10、下面函数是寻找二维数组中每一行的最大值,请填空。 #define N 5 #define M 5 void max (int aNM) int i,j,p; for (i=0;iN;i+) p=0; for (j=1;jM;j+) if (a
20、ipaij) p=j; couti”:”pendl; 11、下面程序是将字符逆序化,请填空。 #include using namespace std; char ch; int main( ) char ch=”hello,boy!”; char c; int i=0,j=strlen(ch); for(;istrlen(ch)/2;i+,j-) c=chi; chi=chj-1; chj-1=c; coutch; return 0; 12、下面程序的功能是将矩阵转置,请填空。 #include using namespace std; #define I 3 #define J 4 voi
21、d invert(int aIJ) int i,j; int bJI; cout”array a:”endl; for(i=0;iI;i+) for(j=0;jJ;j+) coutaij” “; ; coutendl; cout”array b:”endl; for(i=0;iJ;i+=) for(j=0;jI;j+) coutbij” “; coutendl; int main() int aIJ=1,2,3,4,5,6,7,8,1,3,5,7; ; return 0; 答案 1. i=10 i11 b+=i+1 2. ia cinb cout=A) int func(int a,int b
22、) static int m=0;int i=2; i+=m+1; m=i+a+b; return (m); int main( ) int k=4,m=1,p; p=func(k,m); coutp; p=func(k,m); coutpendl; return 0; 、下面程序的输出结果是() #include using namespace std; int d=1; fun (int p) static int d=5; d+=p; coutd; return (d); int main( ) int a=3; coutfun(a+fun(d)endl; return 0; 、下面程序
23、的执行结果是() #include using namespace std; char ch=”hello,boy!”; void fun2(int i); void fun1(int i) coutchi; if(i3) i+=2; fun2(i); void fun2(int i) coutchi; if (i3) i+=2; fun1(i); int main( ) int i=0; fun1(i); coutendl; return 0; 、下面程序的执行结果是() #include using namespace std; int main( ) int a10=0,1,2 int
24、j; for(j=2;j6;j+) aj+1=aj+2aj-1aj-2; cout”The array is:”endl; for(j=0;j6;j+) cout”a“j” is”*p+; cout*(p-1); return 0; 、下面程序的输出结果是() #include using namespace std; void func (int *a,int b) b0=*a+6; int main( ) int a,b5; a=0;b0=3; func( coutb0; return 0; 、下列程序的输出结果是() #include using namespace std; int b
25、=2; int func(int *a) b+=*a; return (b); int main( ) int a=2,res=2; res+=func( coutres; return 0; 、下面程序的输出结果是() #include using namespace std; int w=3; int fun(int); int main( ) int w=10; coutfun(5)wendl; return 0; int fun(int k) if(k=0) return w; return (fun(k-1)k); 、下面程序的输出结果是() #include using names
26、pace std; int f(int); int main( ) int a=2,j; for(j=0;j3;j+) coutf(a)” “; coutendl; return 0; int f(int a) int b=0; static int c=3; b+;c+; return (a+b+c); 10、分析下列程序的输出结果(注:除了给出结果外,还要进行简单分析) #include using namespace std; class L public: void InitL(int x,int y)X=x;Y=y; void Move(int x,int y)X+=x;Y+=y;
27、int GetX()return X; int GetY()return Y; private: int X,Y; ; class R:public L public: void InitR(int x,int y,int w,int h) InitL(x,y); W=w; H=h; int GetW()return W; int GetH()return H; private: int W,H; ; class V:public R public: void fun()Move(3,2); ; int main() V v; v.InitR(10,20,30,40); v.fun(); co
28、ut”“v.GetX()”,”v.GetY()”,”v.GetW”,”v.GetH()”endl; return 0; 11、分析下列程序的输出结果(注:除了给出结果外,还要进行简单分析) #include using namespace std; class B public: B() B(int i)b=i; virtual void virfun() cout”B:virfun() called.n”; private: int b; ; class D:public B public: D() D(int i,int j):B(i)d=j; private: int d; void v
29、irfun() coutvirfun(); int main() D *pd=new D; fun(pd); return 0; 12、分析下列程序的输出结果 #include using namespace std; classA public: A(int i,int j)a=i;b=j; void Move(int x,int y)a+=x;b+=y; void Show()cout”(“a”,”b”)”endl; private: int a,b; ; class B”public A public: B(int i,int j,int k,int l):A(i,j),x(k),y(l) void Show()coutx”,”yb();是否有二义性? (3) pc-f();是否有二义性? (4) pc-f(10); 是否有二义性? (5) pc-g();是否有二义性? 答案 1.8 162. 6 15 153. hlo4. a0 is 0a1 is 1a2 is 2a3 is 2a4 is 6a5 is 14 5. 1 2 36. 67. 68. 36009. 7 8 9 10. 13,22,30,40 分析: 该程序中有 3 个类:L、R 和 V。其中,R 类公有继承 L 类,V 类又公有继承 R 类。因 此,V 类的对象可以
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版车库租赁与停车场安全管理合同
- 二零二五年城市广场草坪铺设与绿化景观设计合同
- 2025版智能工厂设备资产转让协议示范文本
- 二零二五年度城市绿化安装工程劳务合同范本
- 2025版智慧小区保安与家政保洁服务全面合作协议
- 2025版家庭关系巩固不离婚协议执行标准
- 2025版新媒体VI视觉形象设计合作协议
- 2025版新能源汽车充电站场地租赁与管理合同
- 二零二五年度班组施工退场工程款结算合同
- 二零二五年度个人创业担保贷款合同范本
- 2025年多重耐药菌培训知识试题及答案
- 2025至2030中国航空球轴承行业项目调研及市场前景预测评估报告
- 2025年湖北省中考语文试卷真题(含标准答案及解析)
- 2025至2030中国牙科氧化锆块行业发展趋势分析与未来投资战略咨询研究报告
- 《中华人民共和国职业分类大典》(2022年版)各行业职业表格统计版(含数字职业)
- 医院检验科实验室生物安全程序文件SOP
- 华南农业大学2023年840兽医传染病学考研真题(回忆版)
- 城市道路无障碍设施课件
- 品质意识,品质基础知识培训
- 教师政审个人现实表现材料范文(通用5篇)
- QC降低矿山法围岩隧道爆破超挖量
评论
0/150
提交评论