ImageVerifierCode 换一换
格式:DOCX , 页数:20 ,大小:21.32KB ,
资源ID:8826377      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8826377.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(东南大学c++第二学期期末复习二含答案.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

东南大学c++第二学期期末复习二含答案.docx

1、东南大学c+第二学期期末复习二含答案一、 选择题:(每题1分,共30分)1 以下程序的输出结果是 C A) 1 B) 7 C) 9 D) 11 #include void fut (int*s,int p23) *s=p11; void main() static int a23=1,3,5,7,9,11;int *p; p=new int; fut(&p,a); cout*pendl; 2 执行以下程序后,y的值是_(B)_ A) 17 B) 18 C) 10 D) 20 #include void main() static int a=2,4,6,8,10; int y=0,x,*p;

2、p=&a1; for(x=0;x3;x+) y+=*(p+x); coutyendl; 3 定义一下类: class X int a ;public: X (int x=0 ) a= x ; ;class Y: public X int b;pub lic :Y( int x=0 , int y=0 ) : X (y) b = x ; ; 在下列选项的说明语句中,存在语法错误的是 (C) 。 AX *pa = new Y(1 , 2 ) B X a1 = Y( 1,3 ) ;CX b2 ( 2 ,3 ) ; Y &a2 = b2 ; DY b3 ( 10 ) ; X a3 ( b3 ) ;4

3、下列关于虚函数描述中正确的是 (B) 。A虚函数可以是一个static类型的静态成员B虚函数可以是一个非静态成员C虚函数实现静态多态性D基类中采用virtual说明一个虚函数后,派生类中定义相同的原型的虚函数时,可不必加virtual说明5 若磁盘上已存在某个文本文件,其全路径文件名为: d:dir,下列语句中能以”读文本文件”的方式打开该文件的是(B)。 A ifstream file(“d:dir”); Bfstream file(“d:dir”); Cfstream file(ios:in); (“d:dir”); Difstream * file=new ifstream(“d:dir

4、”);6 定义如下变量和数组: int i; int x33=1,2,3,4,5,6,7,8,9;则以下语句的输出结果是 (C) 。 for(i=0 ;i3;i+) coutxi2-i;A159 B147 C357 D3697 void g(void*)(int,int,int), int, int)的参数个数是 (A) 。A. 3个 B. 5个 C. 1个 D. 无法确定8 现需要对list类对象使用的逻辑运算符“”重载,以下函数声明(28)是正确的。.list & list:operator=(const list &a);.list list:operator=(const list &

5、a);.bool & list:operator=(const list &a);.bool list:operator=(const list &a);9 若有说明:int t32,*p=t0; 能正确表示t21的一组表达式是_(D)_ A) *(t+2)+1,*(p0+5),*t+3 B) *(t+2+1),*p21,*(t2+1) C) *(t+2)+1,*p5,*(t0+2)+1 D) *(*(t+2)+1),p5,*(t2+1)10 若有说明:int t32,*p=t0; 能正确表示t0的一组表达式是_(27)_ A)*(t+0),p B)*t,*p C)p0,*t D)*t+0,*

6、p011 若有说明:int t32; 则表达式:&t0+1表示_(B)_A)第1行的行指针,一级指针 B) 第1行的行指针,二级指针C)元素t01的地址 D) 元素t10的地址12 设有说明:int *p,*q,*t,x=5; 运行以下程序段,输出结果是_(C)_A) 5 随机数 B) 随机数 5 C) 出错 D) 5 5 p=new int; q=&x; t=p;p=q;q=t; delete p; cout*pt*qendl;二、 阅读程序题1. 以下程序运行后,输出结果是 (1)(2)(3)(4)。(8分)4*24*4*24*#include int f(int a,int b) if(

7、ab) return b+a; else coutb*f(+a,-b)*n; return a*f(a,b);void main()int n; n=f(1,3); coutnn;2. 程序#include void fun(int *s,int n) int f=10;15x=25 if(n=1|n=2) *s=1; else fun(&f,n-2); *s=f*5; coutfn; void main() int x=20; fun(&x,5); coutx=xn;程序输出的第一行是 4 ,第二行是 5 ,第三行是 6 。3. 程序#include #include Double x,u,

8、v,f(double),g(double),t(double,double (*)(double);void main() x=; u=t(x,f); v=t(x,g); coutu=setw(4)uendl; coutv=setw(4)vendl;double t(double a,double (*f)(double) return (*f) (a*a); double f(double x ) return x+;double g(double x) return ;程序输出的前2行分别是:_ 7 , 8 u=18 v=144. 程序#include class base int i;p

9、ublic: base(int I=0):i(I) virtual int sum()return i;class D: public base int j;public: D(int I=0,int J=0):base(I),j(J) int sum()return base:sum()+j;void call(base b)coutsum=()endl;void main()sum=10sum=10sum=10 base b(10),* pb; D d(10,47); pb=&d; call(b); call(d); call(*pb);程度输出的第一行 9 ,是第二行是 10 第三行是

10、11 。5. 357程序#includeint f(int x) int s=0; for(int j=2;j=x;j+) if(x%j=0) x/=j; s+=j; return s;void main(void) for(int i=3;i10;i+) if(i=f(i) coutiendl;程序运行后输出的第一行是 12 第二行是 13 第三行是 14 。6. 程度#include void f(int j) if(!j) coutj; return; if(j%2) f(j/10); coutj%10; else coutj%10;f(j/10);void main() f(0);co

11、utn; f(1357);coutn; f(2468);coutn;程序运行后输出的第一行是 第二行是 第三行是 7. 程序#includeclass Xpublic: void virtual f()coutX:11endl; void virtual g()coutX:22endl;B:55B:44X:22class A:public Xpublic: void f()coutA:33endl;class B:public Apublic: void f()coutB:44endl; void g(int i=10)coutB:55f(); px-g();程序输出的第一行是 ,第二行是 ,

12、第三行是 _。8. 程序#includeclass Ax=1 A_1A_2A_22 AA_23 AA_24 A4 A3 A int x; public: A(int a) x=a; coutx=xtA_1n; A(A &s) x=+1; coutA_2n; A()coutxtAn;void main(void) A f1(1), f2(f1); f2=A(f1); f1=A(f2); f2=A(f1);程序共输出 行,第一行是 ,第四行是 ,第六行是 。9. 程序x=4, y=10x=4, y=16x=4, y=6i=34x=8, y=7 #includeclass Aint y;static

13、 int x;public: operator int()return x+y; A operator +(int)return A(x+,y+); A(int x=2,int y=3)A:x=x+x;A:y=y+y; void print()coutx=x,ty=yendl;int A:x=23;void main(void)A a(30,5),b(10,8),c;();();();int i=a+b; couti=iendl;c+;();程序输出的第一行是 ,第二行是 ,第三行是 ,第四行是 ,第五行是 。10. #include int i=1;int fac(int n) static

14、 int f=1;66,6 f=f*n; return(f);void main() int i,p=0; for(i=1;i=3;i+)p=fac(i); coutpendl; p=0; for(i=1;i=3;i+)p=p+:i+; / A coutp,; p=1; for(i=1;i=3;i+)p=p*-:i; / B coutpendl;问题1:该程序的第一行输出为( ,第二行输出为 11. 下列程序的输出结果是 。#include int a=100;void fun(int i,int j,int *k) j+=i; *k=j-i;void main() int a,b,c; fu

15、n(17,18,&a); fun(19,a,&b);18,18 ,18 fun(a,b,&c); couta,b,cendl;12. 以下程序运行后,输出结果是 。#includeclass Apublic: int i; void print()couti insert A n;class B:public Apublic: virtual void print()couti insert B n;class C:public B3 insert C3 insert A:i3 insert C3 insert A:i10 insert Apublic: C( )A:i=10; int i;

16、void print() couti insert C n; coutiprint(); pb=&c; pb-print(); pa=&c; pa-print();三、 完善程序1. 1. 下面程序的功能是:先输入一行字符串,并从输入的字符串中找到最小的字符(其ASCII值最小),用min保存该字符。然后将该字符前的所有字符顺序向后移动一个字符的位置。最后,将保存的字符放在该字符串的第0个位置上。例如:设输入的字符串为“bcdfae”,其中字母a为最小字符,经移动处理后,输出的字符串为“abcdfe”。#includevoid fun( ) / char *strchar mun,*q,*p;

17、 ; / p=q=strmin = *p+; while(*p!=0)if( )min = *p; q = p ; / *pstr /p-,q-*q = min;void main()char str80;(str,80);fun(str); coutstrn;2. 本程序被完善后输出以下结果。C+ languge programmingThe end at this time of day!#include#includeclass Apublic: static int i; char *ps; A(char ) /*s ps=new charstrlen(s)+1; strcpy( ,s

18、); /ps A() if( ) coutThe end; /i=0else coutat this time of day!n ; if(ps) deleteps; i+; A & operator=(A &b) if ps=new charstrlen( )+1; / strcpy(ps,; else ps=0; return ; /*this ;int A:i;void main() A s1(programming),s2(C+ languge); coutt; s2=s1; coutn;3. 以下程序功能是:从一个字符串str中删除或添加一个指定的字符,若指定的字符c出现在str中,

19、则从str中删除第一个值为c的字符;否则把字符c添加到str的尾部。在程序中,函数dele()从字符串中删除一个字符;函数add()添加一个字符到字符尾部;函数search()用于查找指定的字符是否在字符串中,若在,则返回所在位置,否则返回0。 #include #includechar *sercher(char *s,char ch) while(*s) if(*s+=ch) return ; /s-1 return 0;void dele(char *s,char ch) char *p1=search(s,ch),*p2=p1+1; while(*p2) *p1+= /*p2+ *p1

20、=0;void add(char *s,char ch) while(*s) s+; =ch;*s=0; /*s+void main() char str80=abc12123,c; coutstrn;coutc; void ;if(search(str,c) fp=dele; /(*p)(char *,char) else fp=add; fp( );coutstrn; / (str,c)4. 班主任根据全班n个学生某课程的考试成绩建立一个链表,每个节点包括学号、成绩和该成绩在全班的名次。最后按排名顺序输出学号和成绩。程序10分#includestruct node int grade,n;

21、 long num; node *point;node *trans(node *h,int n) /建立含报名者的档案链表 node *p; p=new node; cinp-nump-grade; p-n=0; ; / node *h=p for(int i=0;ipoint=new node; ; /p=p-point; cinp-nump-grade; p-n=0; p-point=NULL; return h;node *sort(node *head,int n) /按成绩排名次并输出 node *p,*q; int t=0,k=1; p=head; while(kgradet)

22、/p-n=0 t=p-grade; q=p; p=p-point; else p=p-point; q-n=k; ; /k+; ; /t=0; coutnumtgradetnn; student=trans(student,n); coutnnumber:tgrade:t排名:n; student=sort(student,n); 5. 以下程序定义了一个二维坐标点类Point,派生矩形类Square。矩形左下角坐标从基类继承,矩形类只定义右上角坐标,还定义表示颜色的字符串。执行下面的主程序将得到结果:矩形s1: x=1 y=3 width=5 , high=6 , color = red 矩

23、形s2: x=1 y=3 width=5 , high=6 , color = redYellow程序10分#include#includeclass Pointprivate:double x,y;public: Point(double xv=0,double yv=0)x=xv;y=yv; double getx()return x; double gety()return y; void Show()coutx=x y=y;/输出对象信息;class Square:public Point /带颜色的矩形(square)类 double hx,hy; char *color;publi

24、c: Square()hx=0;hy=0; Square(double xv,double yv,double hxv,double hyv,char *s): (11) hx=hxv;hy=hyv; color=new char9; strcpy(color,s); Square( ):Point(rr) /拷贝构造函数 / Square&rr hx=;hy=; color =new charstrlen( )+6; / strcat(strcpy( ), ); /color, /Yellow void Show();void Square:Show() /输出矩形的左下角坐标、宽度、高度和颜色 Point: ; /Show() couttwidth=hx,high=hy; cout,color=colorn;void main() Square s1(1,3,6,9,red),s2(s1); cout矩形s1:t; (); cout矩形s2:t; ();6. 以下程序实现一个由动态数组构成的线性表的类,在该类的线性表中存放若干个实数。通过重载运算符实现两个线性对应元素间的赋值,重载提取运算符完成线性表的输入,重载插入运算符完成线性表的输出。程序10分#includeclass List int size;/表示动态线性

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1