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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

东南大学C++第二学期期末复习二含问题详解文档格式.docx

1、dirtest.txt,下列语句中能以”读文本文件”的方式打开该文件的是(B)。 A ifstream file(“d:dirtest.txt”); Bfstream file(“d:dirtest.txt”); Cfstream file(ios:in); file.open(“d: Difstream * file=new ifstream(“d: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*

2、)(int,int,int), int, int)的参数个数是 (A) 。A. 3个 B. 5个 C. 1个 D. 无法确定8 现需要对list类对象使用的逻辑运算符“”重载,以下函数声明(28)是正确的。.list & list:operator=(const list &a);.list list:.bool &.bool list: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)

3、+1),p5,*(t2+1)10 若有说明: 能正确表示t0的一组表达式是_(27)_ A)*(t+0),p B)*t,*p C)p0,*t D)*t+0,*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 q=&x; t=p;p=q;q=t; delete p;t*q二、 阅读程序题1. 以下程序运行后,输出结果是 (1

4、)(2)(3)(4)。(8分)4*24*#include b) return b+a; else coutb*f(+a,-b)*n; return a*f(a,b);void main()int n; n=f(1,3);n2. 程序#include iostream.hvoid 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;fDouble x,u,v,f(double),g(double),t(double,double (*)(double); x=4.0; u=t(x,f); v=t

5、(x,g);u=setw(4)uv=vdouble t(double a,double (*f)(double) return (*f) (a*a);double f(double x ) return x+2.0;double g(double x) return x-2.0;程序输出的前2行分别是:_ 7 , 8 u=18 v=144. 程序class base int i; base(int I=0):i(I) virtual int sum()return i;class D: public base int j; D(int I=0,int J=0):base(I),j(J) int

6、 sum()return base:sum()+j;void call(base b)coutsum=b.sum()void main()sum=10 base b(10),* pb; D d(10,47); pb=&d; call(b); call(d); call(*pb);程度输出的第一行 9 ,是第二行是 10 第三行是 11 。5. 37程序#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;10; if(i=f(i)

7、cout程序运行后输出的第一行是 12 第二行是 13 第三行是 14 。6. 程度void f(int j) if(!j) coutj; return; if(j%2) f(j/10);j%10; else coutf(j/10); f(0);cout f(1357); f(2468);程序运行后输出的第一行是 第二行是 第三行是 7. 程序class X void virtual f()coutX:11 void virtual g()cout22B:554422class A:public X void f()coutA:33class B:public A44 void g(int i

8、=10)coutf();px-g();程序输出的第一行是 ,第二行是 ,第三行是 _。8. 程序class Ax=1 A_1A_22 A3 A4 A int x; public: A(int a) x=a;A_1 A(A &s) x=s.x+1;A_2 A()coutA A f1(1), f2(f1); f2=A(f1); f1=A(f2);程序共输出 行,第一行是 ,第四行是 ,第六行是 。9. 程序x=4, y=10x=4, y=16x=4, y=6i=34x=8, y=7class Aint y;static int x; operator int()return x+y; A oper

9、ator +(int)return A(x+,y+); A(int x=2,int y=3)A:x=x+x;y=y+y; void print()cout,ty=int A:x=23;A a(30,5),b(10,8),c;a.print();b.print();c.print();int i=a+b;i=c+;程序输出的第一行是 ,第二行是 ,第三行是 ,第四行是 ,第五行是 。10. #include int i=1;int fac(int n) static int f=1;66,6 f=f*n; return(f); int i,p=0; for(i=1;=3;i+)p=fac(i);

10、p p=0;i+)p=p+:i+; / A, p=1;i+)p=p*-:i; / B问题1:该程序的第一行输出为( ,第二行输出为 11. 下列程序的输出结果是 。int a=100;void fun(int i,int j,int *k) j+=i; *k=j-i;void main() int a,b,c; fun(17,18,& fun(19,a,&b);18,18 ,18 fun(a,b,&c);abc12. 以下程序运行后,输出结果是 。 insert A n virtual void print()coutprint(); pb- pa=& pa-三、 完善程序1. 1. 下面程序

11、的功能是:先输入一行字符串,并从输入的字符串中找到最小的字符(其ASCII值最小),用min保存该字符。然后将该字符前的所有字符顺序向后移动一个字符的位置。最后,将保存的字符放在该字符串的第0个位置上。例如:设输入的字符串为“bcdfae”,其中字母a为最小字符,经移动处理后,输出的字符串为“abcdfe”。void fun( ) / char *strchar mun,*q,*p; ; / p=q=strmin = *p+;while(*p!=0)if( )min = *p; q = p ; / *pstr /p-,q-*q = min;char str80;cin.getline(str,

12、80);fun(str);str static int i; char *ps; A(char ) /*s ps=new charstrlen(s)+1; strcpy( ,s); /ps A() if( ) coutThe end /i=0at this time of day!n if(ps) deleteps; i+; A & operator=(A &b) if(b.ps) ps=new charstrlen( )+1; / b.ps strcpy(ps,b.ps); else ps=0; return ; /*this A s1(programming),s2(C+ languge)

13、;s2.ps void ;if(search(str,c) fp=dele; /(*p)(char *,char) else fp=add; fp( ); / (str,c)4. 班主任根据全班n个学生某课程的考试成绩建立一个链表,每个节点包括学号、成绩和该成绩在全班的名次。最后按排名顺序输出学号和成绩。程序10分struct node int grade,n; long num; node *point;node *trans(node *h,int n) /建立含报名者的档案链表 node *p; p=new node;p-numgrade; p-n=0; / node *h=p for(

14、int i=0;n-1;i+)point=new node; ; /p=p-point; cin p-point=NULL; return h;node *sort(node *head,int n) /按成绩排名次并输出 node *p,*q; int t=0,k=1; p=head; while(kt) /p-n=0 t=p- q=p; p=p- else p=p- q-n=k; ; /k+; /t=0;q-numgrade return head;node *student; int n;student=NULL;n; student=trans(student,n);nnumber:g

15、rade:排名:n student=sort(student,n);5. 以下程序定义了一个二维坐标点类Point,派生矩形类Square。矩形左下角坐标从基类继承,矩形类只定义右上角坐标,还定义表示颜色的字符串。执行下面的主程序将得到结果:矩形s1: x=1 y=3 width=5 , high=6 , color = red 矩形s2: x=1 y=3 width=5 , high=6 , color = redYellowclass Pointprivate:double x,y; Point(double xv=0,double yv=0)x=xv;y=yv; double getx(

16、)return x; double gety()return y; void Show()cout y=y;/输出对象信息class Square:public Point /带颜色的矩形(square)类 double hx,hy; char *color; 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=rr.hx;hy=rr.hy; color =new charstrlen( )+6; /rr.color strcat(strcpy( ), /color, rr.color /Yellow void Show();void Square:Show() /输出矩形的左下角坐标、宽度、高度和颜色 Point:

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

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