2013 c++ 第二周任务-读取数据到结构体数组
2013-03-13 10:47
381 查看
/* * 程序的版权和版本声明部分 * Copyright (c)2013, 烟台大学计算机学院学生 * All rightsreserved. * 文件名称:read .cpp * 作 者:王鍇英 * 完成日期:2013年03月13日 * 版本号: v1.0 * 输入描述:略 * 输出描述:学生各科成绩 * 问题描述:略 */ #include<fstream> #include<iostream> using namespace std; struct student { char num[13]; char name[14]; int cpp; int math; int english; int score; }student[500]; int main() { int i,stuNum=0; ifstream infile("score.txt",ios::in); if(!infile) { cout<<"open error!"<<endl; exit(1); } while(!infile.eof()) { infile>>student[stuNum].num>>student[stuNum].name>>student[stuNum].cpp>>student[stuNum].math>>student[stuNum].english; ++stuNum; } infile.close(); for(i=0;i<stuNum;i++) { student[i].score=student[i].cpp+student[i].math+student[i].english; } for(i=0;i<stuNum;i++) { cout<<student[i].num<<" "<<student[i].name<<" "<<student[i].cpp<<" "<<student[i].math<<" "<<student[i].english<<" "<<student[i].score<<endl; } return 0; }
运行结果:
心得体会:
文件读取,有点眉目了。
相关文章推荐
- 2013第二周上机任务项目二(读取数据到结构体数组)
- 第二周上机任务项目2-读取数据到结构体数组
- C++第二周项目2-读取数据到结构体数组
- 第二周C++上机报告(读取数据到结构体数组)
- 第二周上机任务项目2-读取数据到结构体数组 (另一个版本)
- 2013c++ 第二周任务-用结构体数组做计算
- 第二周任务:读取数据到结构体数组
- 第二周项目二:读取数据到结构体数组
- 第二周项目二—读取数据到结构体数组
- 2013第二周上机任务项目一(有序的结构体数组)
- 第二周项目2 读取数据到结构体数组
- 2013第二周上机任务项目三(用结构体数组做计算)
- C++第2周项目2——读取数据到结构体数组
- C++程序设计练习:从文件中读取数据到结构体数组
- 第二周上机任务项目1-有序的结构体数组
- 第二周C++上机报告(用结构体数组做计算)
- c++数据类型(整型/浮点型/字符串/数组/引用/结构体(内存对齐)/类(虚函数))定义、所占字节数、最大最小值
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- 2013c++ 第二周任务 动态链表初试
- 读取数据到结构体数组