[计算机类试卷]国家二级C++机试(操作题)模拟试卷486及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷486及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷486及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 486及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,程序中位于每个 “ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name: Smith Age: 21 ID: 99999 CourseNum: 12 Record: 970 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class StudentInfo protected: ERROR*found* char
2、 Name; int Age; int ID; int CourseNum; float Record; public: StudentInfo(char*name, intAge, int ID, int courseNum, float record); ERROR*found* VOid StudentInfo( ) float AVerageRecord( ) return Record CourseNum; void show( )const cout “Name: “ Name “Age: “ Age “ID: “ ID “CourSeNum: “ CourSeNum “ReCOr
3、d: “ Re-cord endl; ; ERROR*found* StudentInfo StudentInfo(char*Name, int Age, int ID, intCourseNum, float Record) Name=name; Age=age; this- ID=ID; CourSeNum=courSeNum; Record=record; int main( ) StudentInfo st(“Smith“, 21, 99999, 12, 970); st show( ); return0; 二、简单应用题 2 请打开考生文件夹下的解决方案文件 proj2,其中有矩阵基
4、类 MatrixBase、矩阵类 Matrix和单位阵 UnitMatrix的定义,还有 main函数的定义。请 在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 #include iostream using namespace std; 矩阵基础类,一个抽象类
5、 class MatrixBase int rows, cols; public: MatrixBase(int rows, int cols): rows(rows), cols(cols) int getRows( )constreturnroows矩阵行数 int getCols( )constreturncols; 矩阵列数 virtual double getElement(intr, int c)const=0;取第 i个元素的值 void show( )const 分行显示矩阵中所 有元素 for(int i=0; i rows; i+) cout endl; for(int j
6、=0; J cols; j+) *found* cout _ “ “; ); 矩阵类 class Matrix: public MatrixBase double*val; public: *found* Matrix(int rows, int cols, double m =NULL): _ *found* val=_; for(int i=0; i rows*cols; i+) vali=(m=NULL?0 0: mi); Matrix( )delete val; ) double getElement(int r, intc)constreturn valr*getCols( )+c;
7、 ; 单位阵 (主对角线元素都是 1,其余元素都是 0的方阵 )类 class UnitMatrix: public MatrixBase public: UnitMatrix(int rows): MatrixBase(rows, rows) 单位阵行数列数相同 double getElement(int r, int c) const *found* if(_)return1 0; return0 0; ; int main( ) MatrixBase*m; double d 5=1, 2, 3, 4, 5), 2, 3, 4, 5, 6, 3, 4, 5, 6, 7; m=new Mat
8、rix(3, 5, (double*)d); m- show( ); delete m; cout endl; m=new UnitMatrix(6); m- show( ); delete m; return0; 三、综合应用题 3 请打开考生文件夹下的解决方案文件 proj3,其中定义了用于表示特定数制的数的模板类 Number和表示一天中的时间的类 TimeOfDay;程序应当显示: 01: 02: 03 004 06: 04: 06 021 但程序中有缺失部分,请按照以下的提示,把缺失部分补 充完整: (1)在 “ *1* *found*”的下方是一个定义数据成员 seconds的语句
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 486 答案 解析 DOC
