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

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

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

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

基本操作题

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

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

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

#include<ios tream>

USing namespace std;

C1ass Score{

public:

Score f 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{returnnormal;} //返回平时成绩

int getMidterm()const{ return midterm;}

//返回期中考试成绩

int getEndOfTerm()const{return end of term;) //返回期末考试成绩

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

private:

const char * course; //课程名称

char student id[12]; //学号

int normal; //平时成绩

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[]=\\

(1)strcpy(student_id,the_id);

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

(3)int Score∷getFinal()eonst{

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

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

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

简单应用题

2.请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两个人的教室也同时得到改变。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:

改换教室前:

学号:0789姓名:张三班级:062113教室:521

学号:0513姓名:李四班级:062113教室:521

改换教室后:

学号:0789姓名:张三班级:062113教室:311

学号:0513姓名:李四班级:062113教室:311

注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。

#include<lostream>

using namespace std;

class class{ //“班级”类

public:

C1ass(const char * id,const char * room){

strcpy(class_id,id);

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

}

const char * getClasSID() const { return class_id;}//

返回班号

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

const char * getClass room()

const{_______} //返回所在教室房号

void changeRoomTo(const char

* new_room) { //改换到另一个指定房号的教室

strcpy(classroom,new_room);

}

private:

char class_id[20];//班号

char classroom[20]; //所在教室房号

};

class Student{ //“学生”类

char my_id[10];//学号

char my_name[20];//姓名

Class &my_class; //所在教室

public:

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

Student(const char * the_id,const char * the_name,Class&the_class):_______{

strcpy(my_id,the_id);

strcpy(my_name,the_ame);

}

const char * getID()const{return my_id;}

const char *getN

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

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

推荐资源

客服

扫码添加客服微信

热线

官方客服

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

电话客服:

客服微信:pujinet

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

公众号

扫码关注微信公众号