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

发布时间 : 星期二 文章面向对象程序设计(C++)自我测试练习参考答案更新完毕开始阅读6d699ec07cd184254a353549

{

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