




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、 选择题:(每题1分,共30分)1 定义一下类: 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 ; ; 在下列选项的说明语句中,存在语法错误的是 。 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 ) ;2 下列关于虚函数描述中正确的是 。A虚函数可以是一个static类型的静态成员B虚函数可以是一个非静态成员C虚函数实现静态多态性D基类中采用virtual说明一个虚函数后,派生类中定义相同的原型的虚函数时,可不必加virtual说明3 若磁盘上已存在某个文本文件,其全路径文件名为: d:dirtest.txt,下列语句中能以”读文本文件”的方式打开该文件的是。 A ifstream file(“d:dirtest.txt”); Bfstream file(“d:dirtest.txt”); Cfstream file(ios:in); file.open(“d:dirtest.txt”); Difstream * file=new ifstream(“d:dirtest.txt”);4 void g(void*)(int,int,int), int, int)的参数个数是 。A. 3个 B. 5个 C. 1个 D. 无法确定5 现需要对list类对象使用的逻辑运算符“”重载,以下函数声明是正确的。.list & list:operator=(const list &a);.list list:operator=(const list &a);.bool & list:operator=(const list &a);.bool list:operator=(const list &a);6.有如下类定义:class Pointint x_,y_;public:Point(): x_(0), y_(0)Point(int x, int y=0): x_(x), y_(y) ;若执行语句: Point a(2),b2,*c2;则Point 类构造函数被调用的次数是:A) 3次B)4次C)5次D) 6次二、 阅读程序题1. 程序#include iostream.hvoid fun(int *s,int n)int f=10;if(n=1|n=2) *s=1;elsefun(&f,n-2);*s=f*5;coutfn;void main()int x=20;fun(&x,5);coutx=xn;程序输出的第一行是 ,第二行是 ,第三行是 。2. 程序#include #include Double x,u,v,f(double),g(double),t(double,double (*)(double);void main()x=4.0;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+2.0;double g(double x) return x-2.0;程序输出的前2行分别是:_ , 3. 程序#include iostream.hclass baseint i;public:base(int I=0):i(I)virtual int sum()return i;class D: public baseint j;public:D(int I=0,int J=0):base(I),j(J)int sum()return base:sum()+j;void call(base b)coutsum=b.sum()endl;void main()base b(10),* pb;D d(10,47);pb=&d;call(b);call(d);call(*pb);程度输出的第一行 ,是第二行是 第三行是 。4. 程序#includeclass Xpublic:void virtual f()coutX:11endl;void virtual g()coutX:22endl;class A:public Xpublic:void f()coutA:33endl;class B:public Apublic:void f()coutB:44endl;void g(int i=10)coutB:55f(); px-g();程序输出的第一行是 ,第二行是 ,第三行是 _。5. 程序#includeclass A int x; public: A(int a) x=a; coutx=xtA_1n; A(A &s) x=s.x+1; coutA_2n; A()coutxtAn;void main(void) A f1(1), f2(f1); f2=A(f1); f1=A(f2); f2=A(f1);程序共输出 行,第一行是 ,第四行是 ,第六行是 。6. 程序 #includeclass Aint y;static 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;a.print();b.print();c.print();int i=a+b; couti=iendl;c+;c.print();程序输出的第一行是 ,第二行是 ,第三行是 ,第四行是 ,第五行是 。7. 以下程序运行后,输出结果是 。#includeclass Apublic:int i;void print()couti insert A n;class B:public Apublic:virtual void print()couti insert B n;class C:public Bpublic:C( )A:i=10;int i;void print()couti insert C n;coutiprint();pb=&c;pb-print();pa=&c;pa-print();三、 完善程序1.1. 下面程序的功能是:先输入一行字符串,并从输入的字符串中找到最小的字符(其ASCII值最小),用min保存该字符。然后将该字符前的所有字符顺序向后移动一个字符的位置。最后,将保存的字符放在该字符串的第0个位置上。例如:设输入的字符串为“bcdfae”,其中字母a为最小字符,经移动处理后,输出的字符串为“abcdef”。#includevoid fun( 1 ) char mun,*q,*p; 2 ;min = *p+;while(*p!=0)if( 3 )min = *p; q = p ; p+;p = q;While( 4 ) *p = *(p-1); 5 ; *q = min;void main()char str80;cin.getline(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 6 )ps=new charstrlen(s)+1;strcpy( 7 ,s);A()if( 8 ) coutThe end;else coutat this time of day!n ;if(ps) deleteps;i+; A & operator=(A &b)if(b.ps)ps=new charstrlen( 9 )+1; strcpy(ps,b.ps);else ps=0;return 10 ; ;int A:i;void main()A s1(programming),s2(C+ languge);couts2.pst;s2=s1;couts2.psn;3. 以下程序功能是:从一个字符串str中删除或添加一个指定的字符,若指定的字符c出现在str中,则从str中删除第一个值为c的字符;否则把字符c添加到str的尾部。在程序中,函数dele()从字符串中删除一个字符;函数add()添加一个字符到字符尾部;函数search()用于查找指定的字符是否在字符串中,若在,则返回所在位置,否则返回0。 #include #includechar *sercher(char *s,char ch)while(*s)if(*s+=ch) return 11 ;return 0;void dele(char *s,char ch)char *p1=search(s,ch),*p2=p1+1;while(*p2) *p1+= 12 *p1=0;void add(char *s,char ch)while(*s) s+; 13 =ch;*s=0;void main()char str80=abc12123,c;coutstrn;coutc;void 14 ;if(search(str,c) fp=dele;else fp=add;fp( 15 );coutstrn;4. 班主任根据全班n个学生某课程的考试成绩建立一个链表,每个节点包括学号、成绩和该成绩在全班的名次。最后按排名顺序输出学号和成绩。程序10分#includestruct node int grade,n; long num; node *point;node *trans(node *h,int n) /建立含报名者的档案链表 node *p; p=new node; cinp-nump-grade; p-n=0; 16 ; for(int i=0;ipoint=new node; 17 ; 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)t=p-grade; q=p; p=p-point;else p=p-point;q-n=k; 19 ; 20 ;coutnumtgradetnn; student=trans(student,n); coutnnumber:tgrade:t排名:n; student=sort(student,n); 5. 以下程序定义了一个二维坐标点类Point,派生矩形类Square。矩形左下角坐标从基类继承,矩形类只定义右上角坐标,还定义表示颜色的字符串。执行下面的主程序将得到结果:矩形s1: x=1 y=3 width=6 , high=9 , color = red 矩形s2: x=1 y=3 width=6 , high=9 , 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;public:Square()hx=0;hy=0;Square(double xv,double yv,double hxv,double hyv,char *s): (21)hx=hxv;hy=hyv;color=new char9;strcpy(color,s);Square( 22 ):Point(rr) /
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 办公设备承包合同范本
- 3.2氮及其重要化合物教学设计高中化学沪科版2020必修第一册-沪科版2020
- 2025版大学生实习协议合同示例
- 2025企业补充养老保险基金托管合同样本
- 第20课《谈创造性思维》教学设计-2023-2024学年统编版语文九年级上册
- 水陆联运货物运单(GF-91-0407)货物运输责任合同
- 浙江国企招聘2025中国邮政速递物流股份有限公司舟山市普陀区分公司招聘笔试参考题库附带答案详解
- 初中英语听力专项测试题库
- 2025年租赁合同(CF-2000-0601)租赁合同签订时间
- 2025年国企消防安全职称考试题及答案
- 光伏电站施工规范及注意事项
- 水果采购协议样本
- 中职英语(高教版2021基础模块1)Part01-Unit2-Transportation
- 哲学与人生 第二课 树立科学的世界观2.1
- 2024-2030年中国止痛药品市场供需形势及未来前景动态研究研究报告
- 风电110KV升压站土建工程施工方案
- 2018低压电力线高速载波通信互联互通技术规范第3部分:检验方法
- 房屋漏水维修合同书范文
- 超声科医院感染管理:培训与演练
- 中药草乌课件
- DL-T 892-2021 电站汽轮机技术条件
评论
0/150
提交评论