第一范文网 - 专业文章范例文档资料分享平台

面向对象程序设计(C++)自我测试练习参考答案

来源:用户分享 时间:2025/5/31 19:02:50 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

{

long no;

char name[16]; int score; public:

Student(){}

Student(int n,char na[],int s)//构造函数 {

no=n;

strcpy(name,na); score = s; }

void disp() {

cout<<\ } };

void main() {

ofstream outfile(\ if(!outfile) {

cout<<\打开文件d:\\\\sdata.dat失败!\ return; }

Student s1(2013001,\张三\创建第1个学生对象 Student s2(2013002,\王五\创建第2个学生对象 Student s3(2013003,\刘六\创建第3个学生对象 Student s4(2013004,\李四\创建第4个学生对象 Student s5(2013005,\刘七\创建第5个学生对象

outfile.write ((char *)&s1,sizeof(s1));//将5个学生对象分别写入文件 outfile.write ((char *)&s2,sizeof(s2)); outfile.write ((char *)&s3,sizeof(s3)); outfile.write ((char *)&s4,sizeof(s4)); outfile.write ((char *)&s5,sizeof(s5));

outfile.close(); //关闭文件

ifstream inputfile(\ if(!inputfile) {

cout<<\打开文件d:\\\\sdata.dat失败!\ return; }

Student t;

inputfile.seekg(0L,ios::beg);

inputfile.read ((char *)&t,sizeof(t));

while(!inputfile.eof ()) //A {

t.disp ();

inputfile.read ((char *)&t,sizeof(t)); }

inputfile.close (); }

4. 编一程序,实现对学生成绩信息进行管理和维护,包括学生成绩的增加、修改、删除和查询、分数的统计等功能。其中学生信息包括姓名、学号、数学、政治和英语三门功课的成绩。

面向对象程序设计(C++)自我测试练习参考答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c49ori7idox55mbu22qmh_10.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top