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

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

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

}

if(!outputfile) { }

while((ch = inputfile1.get()) != EOF)outputfile.put(ch); while((ch = inputfile2.get()) != EOF)outputfile.put(ch); cout<<\文件复制成功!\inputfile1.close(); inputfile2.close(); outputfile.close();

//关闭已打开的读文件 //关闭已打开的读文件 //关闭已打开的写文件

cout<<\打开文件失败!\outputfile1.close (); outputfile2.close (); return;

//关闭已打开的读文件

cout<<\打开文件失败!\inputfile1.close(); return;

ofstream outputfile(argv[3],ios::out|ios::trunc);//打开写文件

}

2. 编程序实现一个文本文件中所有的小写字母转为大写字母后打印出来。 #include void main() {

char ch;

ifstream inputfile(\打开读文件 if(!inputfile) {

cout<<\打开文件失败!\ return; }

while((ch = inputfile.get()) != EOF) {

if(ch>='a' && ch<='z')ch -= 32; //小写字母转为大写字母 cout<

inputfile.close(); //关闭已打开的读文件 }

3.从键盘输入若干名学生的信息(姓名、学号和成绩),写入二进制文件,再从该文件中读出学生信息,输出在屏幕上。 #include \#include \#include \class Student

{

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

搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新初中教育面向对象程序设计(C++)自我测试练习参考答案 (5)全文阅读和word下载服务。

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