首页 > 全部 > 二级C++ > 国家二级C++机试(操作题)模拟试卷369

国家二级C++机试(操作题)模拟试卷369

本单篇文档共9010字,内容预览3600字,预览为有答案版,源文件无水印,下载后包含无答案空白卷版和有答案版,同时也有计算机类NCRE全国计算机二级整科真题模拟题,讲义课件,思维导图,易错高频题等下载。
二级C++ 章节练习 7152人下载
价格: 1.00 原价:¥9.00
收藏

国家二级C++机试(操作题)模拟试卷369

基本操作题

1.请使用VC6或使用【答题】菜单打开考生文件夹prog1下的工程prog1。此工程中包含程序文件main.cpp,其中有类Score(“成绩”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:

学号:12345678 课程:英语 总评成绩:85

注意:只修改每个“//ERROR****found****”下的一行,不要改动程序中的其他内容。

#include

using namespace std;

class Score{

public:

Score(const char*the course,

const char*the id,int the normal,

int the midterm,int the end of term)

:course(the course),normal(the

normal),midterm(the midterm),end

of term(the end of term){

//ERROR**********found**********

strcpy(the id,student_id);

}

const char*getCourse()const{return course;)//返回课程名称

//ERROR**********found**********

const char*getID()const{return

&student id;) //返回学号

int getNormal()const { return normal;) //返回平时成绩

int getMidterm()const f return mid

term;}

//返回期中考试成绩

int getEnd0fTerm《)const{return

end_of_term;) //返回期末考试成绩

int getFinal()const;//返回总评成绩

private:

const char*course;//课程名称

char student id[12]; //学号

int normal;//4时成绩

int midterm; //期中考试成绩

int end of term; //期末考试成绩

};

//总评成绩中平时成绩占20%,期中考试占

30%,期末考试占50%,最后结果四舍五入为

一个整数

//ERROR**********found**********

int getFinal()const{

return normal*0.2+midterm*0.3+

end_of_term*0.5+0.5;

}

int main(){

char English[]=”英语”;

Score score(English,”12345678”,

68,83,92);

cout<<”学号:”<<score.getID()<<\\

(1)strcpy(student_id,the_id);

(2)const char*getID()const{retum student_id;}

(3)int Score::getFinal()const{

解析:(1)主要考查考生对strcpy()函数的掌握情况,strcpy(参数一,参数二)函数的功能是将参数二的字符串复制给参数一,因此在这里student_id应该位于参数一的位置,即strcpy(student_id,the_id);。

(2)主要考查考生对函数返回值的掌握情况,根据注释:返回学号可知学号应该由一个字符串组成。再看函数要返回的类型:const char*,可知要返回一个char型指针,也就是一个char型数组,而&student_id是一个char型数组指针,因此直接写student_id即可。

(3)主要考查考生对类的成员函数的掌握情况,因为getFinal函数是Score类的成员函数,所以在定义时要加上类名和作用域符,即Score::。

简单应用题

2.请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程中含有一个源程序文件proj2.epp。函数char*GetNum(char*src,char*buf)从src开始扫描下一个数字字符序列,并将其作为一个字符串取出放人字符串空间buf中。函数返回扫描的终止位置,如果返回NULL表示没有扫描到数字字符序列。

运行程序时,如果输入的一行字符序列是

ABC012XYZ378MN274WS

则输出为:

Digit string 1 is 012

Digit string 2 is 378

Digit string 3 is 274

注意:只在横线处编写适当代码,不要删除或移动

“//****found****”.

//proj2.cpp

#include

using namespace std;

char*GetNum(char*see,char*bur)

{

while(*src!=’\0’)

{

if(isdigit(*src))break;

SrC++;

}

if(*src==’\0’)

//*******found********

_______;

while(*src!=’\0’&& isdigit(*src))

{

//******** found********

_______;

bur++;

src++;

}

*bur=’\0’;

return srC;

}

int main()

{

char str[1 00],digits[20];

cin.getline(str,1 00);

char*P=str;

int i=1;

while((p=GetNum(p,digits))!=NULL)

{

tout<<”Digit string”<<i<<”

is”<<digits<<endl;

//********found********

_________;

}

return 0;

}

(1)retum NULL

(2)*buf=*arc

(3)i++

解析:(1)主

本文档预览:3600字符,共9010字符,源文件无水印,下载后包含无答案版和有答案版,查看完整word版点下载

剩余未完,查看全文
收藏
国家二级C++机试(操作题)模拟试卷369

推荐资源

客服

扫码添加客服微信

热线

官方客服

如遇问题,请联系客服为您解决

电话客服:

客服微信:pujinet

工作时间:9:00-18:00,节假日休息

公众号

扫码关注微信公众号