2022年计算机二级《C++》上机考前冲刺试题(5).docx

上传人:hs****ma 文档编号:560796847 上传时间:2023-10-30 格式:DOCX 页数:9 大小:14.47KB
返回 下载 相关 举报
2022年计算机二级《C++》上机考前冲刺试题(5).docx_第1页
第1页 / 共9页
2022年计算机二级《C++》上机考前冲刺试题(5).docx_第2页
第2页 / 共9页
2022年计算机二级《C++》上机考前冲刺试题(5).docx_第3页
第3页 / 共9页
2022年计算机二级《C++》上机考前冲刺试题(5).docx_第4页
第4页 / 共9页
2022年计算机二级《C++》上机考前冲刺试题(5).docx_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《2022年计算机二级《C++》上机考前冲刺试题(5).docx》由会员分享,可在线阅读,更多相关《2022年计算机二级《C++》上机考前冲刺试题(5).docx(9页珍藏版)》请在金锄头文库上搜索。

1、 2022年计算机二级C+上机考前冲刺试题(5)一、选择题(每题1分,共40分)1、以下有关内联函数的表达中,正确的选项是( )。A内联函数在调用时发生掌握转移B内联函数必需通过关键字inline来定义C内联函数是通过编译器来实现的D内联函数函数体的最终一条语句必需是return语句 2、语句int*P=&k;定义了指针P,与这个语句等效的语句序列是( )。Aint* p;P=&k;Bint * P;P=k;Cint * p;* P=&k;Dint * p;* P=k; 3、有如下程序:#includeusing namespace std;class Apublic:A()coutA表达式可

2、输出字符ABeof()函数可以检测是否到达文件尾C对磁盘文件进展流操作时,必需包含头文件fstreamD以ios_base:0ut模式翻开的文件不存在时,将自动建立一个新文件 17、耦合性和内聚性是对模块独立性度量的两个标准。以下表达中正确的选项是()。 A提高耦合性降低内聚性有利于提高模块的独立性B降低耦合性提高内聚性有利于提高模块的独立性C耦合性是指一个模块内部各个元素间彼此结合的严密程度D内聚性是指模块间相互连接的严密程度 18、 若有如下类声明:Class MyClass publiC:MyClass()Cout1;i一=2) tout=A&(c=C|(z=a)&(cID=ID:Cou

3、rseNum=courseNum:Record=record;int main()Studentlnfo st(Smith”,21,99999,12,970);stshow();return 0; 三、简洁应用题(24分) 42、请使用VC6或使用【答题】菜单翻开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避开二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:801

4、501001留意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。#includeclass vehicleprivate:int MaxSpeed;int Weight;public:/*found*vehicle(int maxspeed,int weight):vehicle();int getMaxSpeed()return MaxSpeed;int getWeight()retum Weight;/*found*class bicycle:public vehicleprivate:int Height;public:bicycle(int

5、 maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height)int getHeight()retum Height;/*found*class motorcar:public vehicleprivate:int SeatNum;public:motorcar(int maxspeed。int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum)int getSeatNum()return SeatNum;/*found*class moto

6、rcycle:public:motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,1);void main()motorcycle a(80,150,100);cout(istream&input,MiniString&8)/重载流提取运算符 char temp100;/用于输入的临时数组temp0=0:/初始为空字符串inputsetw(100)temp;int inLen=strlen(t

7、emp);/输入字符串长度if(inLen!=0)s1ength=inLen;/赋长度if(ssPtr!=0)deletessPtr;/避开内存泄漏ssPtr=Hew chars1ength+1;strcpy(ssPtr,temp);/假如8不是空指针,则复制内容else ssPtr0=0;/假如s是空指针,则为空字符串retum input;void modString(const charstring2)/更改字符串内容if(strin92 1=0)/假如strin92不是空指针,则复制内容if(strlen(strin92)!=length)length=strlen(strin92);

8、deletesPtr;sPtr=new char1ength+1;/安排内存strcpy(sPtr,strin92);else sPtr0=0;/假如string2是空指针,则为空字符串MiniString&operator=f const MiniString&otherString);MiniString(corot char*s=“):lengtll(s!=0)?strlen(s):0)/构造函数sPtT=0:if(1ength=0)setString(S);MiniString()/析构函数deletesPtr;private:int length;/字符串长度char*sPtr;/指

9、向字符串起始位置void setString(const char*string2)/帮助函数sPtr=Dew charstr|en(string2)+1;/安排内存if(stnIl92!=0)strcpy(sPtr,string2);/假如string2不是空指针,则复制内容else slur0=”0”;/假如string2是空指针,则为空字符串;/pwj3cpp#”include#includeusing namespace std;#include”proj3h”MiniString&MiniStrin9:0perator=(const MiniString&otherString)/重载赋值运算符函数。提示:可以调用帮助函数setString/*333* /*666* int main() MiniSu”ing strl(”Heuo!”),str2;void writeToFile(const char*);sir2=strl;/使用重载的赋值运算符str2modString(“Happy new year!“);cout cout writeToFile(“);return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号