收藏 分销(赏)

09级C(下)上机试卷B-答案.doc

上传人:二*** 文档编号:4522527 上传时间:2024-09-26 格式:DOC 页数:9 大小:45KB
下载 相关 举报
09级C(下)上机试卷B-答案.doc_第1页
第1页 / 共9页
亲,该文档总共9页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、东南大学09级C+(下)上机试卷B-答案一、改错题(50分)本题共10个错误,每个错误5分#include #include using namespace std;class studentchar *pName;public:student();student(char *pname);student(student &s);student();student & operator=(student &s);void print();student:student()/去掉voidcoutConstructor;pName=NULL;cout缺省endl;student:student (

2、 char *pname )coutConstructor;pName = new charstrlen(pname);if ( pName ) strcpy ( pName, pname);/pName与pname互换位置coutpNameendl;student:student(student &s) /改为student &scoutCopy Constructor;if(s.pName)int len = strlen( s.pName );pName = new charlen+1; /len改为len+1if ( pName ) strcpy (pName, s.pName);co

3、utpNameendl;else pName=NULL;student:student()coutDestructor;if ( pName ) coutpNameendl;delete pName; /改为delete pName;student & student:operator = ( student &s ) coutCopy Assign operator;delete pName; if ( s.pName ) pName = new charstrlen(s.pName)+1;if ( pName ) strcpy ( pName, s.pName );coutpNameend

4、l;else pName=NULL;return *this; /改为return *this;void student:print( ) /改为void student:print( )if (pName = NULL ) cout NULL endl; else cout pName print();/改为s3-print();delete s3; return; /去掉0二、编程题(50分)每段代码10分,共50分。红字为要求设计的部分。#include #include #include using namespace std;class goods;ostream& operator

5、(istream &is, goods &a);class goodsstringName;/名称intAmount;/数量floatPrice;/单价public:goods (); goods ();/析构函数,将数据保存到文件中bool IsEmpty() return Name=; ;friend ostream& operator(istream &is, goods &a);goods: goods () ifstream file(goodinfo.data);if ( file ) /文件打开成功file *this;file.close();elseName = ;Amoun

6、t = 0;Price = 0;goods: goods ()ofstream file(goodinfo.data);file *this;file.close();ostream& operator (ostream &os, goods &a)os a.Name endl;os a.Amount endl;os a.Price (istream &is, goods &a)if ( is = cin )cout 请输入你的以下信息: endl;cout a.Name;cout a.Amount;cout a.Price;elseis a.Name;is a.Amount;is a.Pri

7、ce;return is;void main()goods g;if ( g.IsEmpty() ) cin g;cout endl;cout 显示商品信息: endl;cout g;if(!datafile) coutproductNamematNamematPrice0servicePrice; ProductName=productName; MatName=matName; MatPrice0=matPrice0; ServicePrice=servicePrice;编程题评分标准: 1. 头文件引用是否正确 2分 2. 主函数:22分 (1)创建文件流对象与要求的文件相对应数否正确 (2分) (2)是否关闭文件 (2分) (3)变量初始化 (2分) (4)产生a数组是否正确 (8分) (5)将a数组是否按要求写入文件 (4分) (6)将符合条件的数及其位置是否按要求写入文件 (4分) 3. fun函数: 26分 (1)求各行平均值,是否正确 (8分) (2)求各列最大值,是否正确 (8分) (3)条件满足判断返回是否正确 (6分) (4)不满足条件返回是否正确 (4分)

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 初中其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服