第十七周实验报告
2012-06-11 19:17
393 查看
/* * 程序头部注释开始 * 程序的版权和版本声明部分 * Copyright (c) 2012, 烟台大学计算机学院学生 * Copyright (c) 2012, 烟台大学计算机学院学生 * All rights reserved. * 文件名称: * 作 者: 李瑞 * 完成日期: 2012 年 6月11 日 * 版 本 号: v1.0 * 对任务及求解方法的描述部分 * 输入描述:…… * 问题描述:…… * 程序输出:…… * 程序头部的注释结束 */ #include<iostream> #include<string> #include<fstream> using namespace std; class Student { public: Student(); Student(string name, double cpp, double math, double English); double all_score(); double ave_score(); void read_score(ifstream &in); void write_score(ofstream &out); void display(); private: string name; double score_cpp; double score_math; double score_English; double score_all; double score_average; }; Student::Student() { this->name = "0000"; this->score_cpp = 0; this->score_math = 0; this->score_English = 0; } Student::Student(string name, double cpp, double math, double English) { this->name = name; this->score_cpp = cpp; this->score_math = math; this->score_English = English; } void Student::display() { this->all_score(); this->ave_score(); cout << this->name << '\t' << " c++: " << this->score_cpp << '\t' << "English: " << this->score_English << '\t' << " math : " << this->score_math << '\t' << "all_score : " << this->score_all << '\t' << "ave_score : " << this->score_average << endl << endl; } double Student::all_score() { this->score_all = this->score_cpp + this->score_math + this->score_English; return this->score_all; } double Student::ave_score() { this->score_average = (this->score_cpp + this->score_math + this->score_English) / 3; return this->score_average; } void Student::read_score(ifstream &in) { in >> this->name >> this->score_cpp >> this->score_math >> this->score_English; } void Student::write_score(ofstream &out) { out << this->name << '\t' << this->score_cpp << '\t' << this->score_math << '\t' << this->score_English << endl; } void readfile(Student * s, int num) { ifstream infile("score.dat",ios::in); if(!infile) { cerr << "open error!" << endl; exit(1); } for(int i = 0; i < num; ++i) { s[i].read_score(infile); } infile.close(); } void Readfile(Student * s, int num) { ifstream infile("binary_score.dat",ios::in|ios::binary); if(!infile) { cerr << "open error!" << endl; abort(); } for(int i = 0; i < num; ++i) { infile.read((char *) & s[i], sizeof(s[i])); } infile.close(); } void writefile(Student * s, int num) { ofstream outfile("binary_score.dat",ios::out|ios::binary); if(!outfile) { cerr << "open error!" << endl; abort(); } for(int i = 0; i < num; ++i) { outfile.write((char *) & s[i], sizeof(s[i])); } outfile.close(); } void Writefile(Student * s, int num) { ofstream outfile("binary_score2.dat",ios::out); if(!outfile) { cerr << "open error!" << endl; abort(); } for(int i = 0; i < num; ++i) { s[i].write_score(outfile); } outfile.close(); } int main() { Student stu[100], stu1[101], my_score("李瑞", 100, 100, 100); readfile(stu, 100); writefile(stu, 100); Readfile(stu1, 100); stu1[100] = my_score; for(int i = 0; i < 101; ++i) { stu1[i].display(); } Writefile(stu1, 101); system("pause"); return 0; } /* 结果: 刘得意 c++: 60 English: 75 math : 98 all_score : 233 ave_score : 77.6667 王锐 c++: 63 English: 96 math : 90 all_score : 249 ave_score : 83 何煜中 c++: 90 English: 82 math : 73 all_score : 245 ave_score : 81.6667 王磊 c++: 87 English: 92 math : 86 all_score : 265 ave_score : 88.3333 冯松 c++: 89 English: 83 math : 98 all_score : 270 ave_score : 90 裴培 c++: 75 English: 91 math : 82 all_score : 248 ave_score : 82.6667 马骁 c++: 62 English: 90 math : 67 all_score : 219 ave_score : 73 马婧 c++: 98 English: 87 math : 84 all_score : 269 ave_score : 89.6667 周俊升 c++: 57 English: 96 math : 68 all_score : 221 ave_score : 73.6667 贺祺 c++: 61 English: 72 math : 96 all_score : 229 ave_score : 76.3333 李桐 c++: 93 English: 86 math : 83 all_score : 262 ave_score : 87.3333 高路 c++: 63 English: 98 math : 74 all_score : 235 ave_score : 78.3333 冯佳媛 c++: 61 English: 81 math : 79 all_score : 221 ave_score : 73.6667 张迪 c++: 99 English: 80 math : 88 all_score : 267 ave_score : 89 张里响 c++: 85 English: 96 math : 65 all_score : 246 ave_score : 82 王瑞麒 c++: 89 English: 91 math : 83 all_score : 263 ave_score : 87.6667 徐金竹 c++: 75 English: 73 math : 89 all_score : 237 ave_score : 79 赵媛媛 c++: 77 English: 66 math : 75 all_score : 218 ave_score : 72.6667 宋宗杰 c++: 94 English: 92 math : 100 all_score : 286 ave_score : 95.3333 张佳玮 c++: 61 English: 96 math : 98 all_score : 255 ave_score : 85 王姝 c++: 70 English: 90 math : 91 all_score : 251 ave_score : 83.6667 宋媛媛 c++: 61 English: 92 math : 94 all_score : 247 ave_score : 82.3333 于莉 c++: 55 English: 78 math : 66 all_score : 199 ave_score : 66.3333 于浩 c++: 78 English: 72 math : 84 all_score : 234 ave_score : 78 王竞 c++: 90 English: 67 math : 87 all_score : 244 ave_score : 81.3333 崔赞 c++: 91 English: 93 math : 67 all_score : 251 ave_score : 83.6667 宋静 c++: 69 English: 73 math : 85 all_score : 227 ave_score : 75.6667 王磊 c++: 71 English: 77 math : 78 all_score : 226 ave_score : 75.3333 方圆 c++: 70 English: 76 math : 79 all_score : 225 ave_score : 75 李朋 c++: 90 English: 97 math : 82 all_score : 269 ave_score : 89.6667 马佳 c++: 60 English: 100 math : 90 all_score : 250 ave_score : 83.3333 张龙 c++: 62 English: 78 math : 100 all_score : 240 ave_score : 80 马里 c++: 73 English: 73 math : 95 all_score : 241 ave_score : 80.3333 韩明 c++: 83 English: 88 math : 97 all_score : 268 ave_score : 89.3333 马立 c++: 73 English: 83 math : 90 all_score : 246 ave_score : 82 吴清正 c++: 89 English: 85 math : 97 all_score : 271 ave_score : 90.3333 印虹 c++: 92 English: 75 math : 68 all_score : 235 ave_score : 78.3333 田苗苗 c++: 75 English: 71 math : 91 all_score : 237 ave_score : 79 卫青 c++: 66 English: 77 math : 73 all_score : 216 ave_score : 72 冷云 c++: 89 English: 71 math : 88 all_score : 248 ave_score : 82.6667 葛志伟 c++: 100 English: 71 math : 79 all_score : 250 ave_score : 83.3333 范振光 c++: 98 English: 89 math : 87 all_score : 274 ave_score : 91.3333 王芳 c++: 71 English: 99 math : 97 all_score : 267 ave_score : 89 杨超 c++: 67 English: 82 math : 73 all_score : 222 ave_score : 74 杨梦婕 c++: 89 English: 67 math : 99 all_score : 255 ave_score : 85 梁雅宁 c++: 55 English: 100 math : 88 all_score : 243 ave_score : 81 王琦 c++: 98 English: 98 math : 95 all_score : 291 ave_score : 97 吴玮 c++: 69 English: 68 math : 76 all_score : 213 ave_score : 71 杨阔 c++: 90 English: 98 math : 91 all_score : 279 ave_score : 93 贾伟林 c++: 63 English: 86 math : 90 all_score : 239 ave_score : 79.6667 刘亚新 c++: 77 English: 95 math : 81 all_score : 253 ave_score : 84.3333 金昕 c++: 92 English: 69 math : 67 all_score : 228 ave_score : 76 董一伟 c++: 93 English: 80 math : 88 all_score : 261 ave_score : 87 汤娜 c++: 68 English: 71 math : 85 all_score : 224 ave_score : 74.6667 周恒 c++: 87 English: 69 math : 82 all_score : 238 ave_score : 79.3333 张笑 c++: 86 English: 76 math : 88 all_score : 250 ave_score : 83.3333 文静 c++: 93 English: 85 math : 88 all_score : 266 ave_score : 88.6667 杨华鑫 c++: 81 English: 68 math : 81 all_score : 230 ave_score : 76.6667 苏明霞 c++: 59 English: 94 math : 79 all_score : 232 ave_score : 77.3333 黄京 c++: 62 English: 96 math : 75 all_score : 233 ave_score : 77.6667 佟欣 c++: 60 English: 98 math : 79 all_score : 237 ave_score : 79 张雯 c++: 69 English: 93 math : 70 all_score : 232 ave_score : 77.3333 刘京西 c++: 67 English: 78 math : 78 all_score : 223 ave_score : 74.3333 徐嘉琦 c++: 90 English: 87 math : 75 all_score : 252 ave_score : 84 魏佳 c++: 100 English: 80 math : 94 all_score : 274 ave_score : 91.3333 高举 c++: 81 English: 91 math : 99 all_score : 271 ave_score : 90.3333 边里 c++: 56 English: 87 math : 94 all_score : 237 ave_score : 79 何佳成 c++: 70 English: 78 math : 75 all_score : 223 ave_score : 74.3333 赵旭洋 c++: 87 English: 94 math : 91 all_score : 272 ave_score : 90.6667 孙大伟 c++: 65 English: 98 math : 69 all_score : 232 ave_score : 77.3333 鲁继森 c++: 84 English: 75 math : 79 all_score : 238 ave_score : 79.3333 白涛 c++: 57 English: 75 math : 82 all_score : 214 ave_score : 71.3333 蔺剑飞 c++: 88 English: 79 math : 75 all_score : 242 ave_score : 80.6667 兰天 c++: 83 English: 74 math : 66 all_score : 223 ave_score : 74.3333 王悦 c++: 79 English: 70 math : 82 all_score : 231 ave_score : 77 陈世勃 c++: 70 English: 65 math : 92 all_score : 227 ave_score : 75.6667 张昊 c++: 94 English: 96 math : 83 all_score : 273 ave_score : 91 高清 c++: 76 English: 84 math : 83 all_score : 243 ave_score : 81 王欣欣 c++: 71 English: 78 math : 83 all_score : 232 ave_score : 77.3333 王欢欢 c++: 57 English: 66 math : 33 all_score : 156 ave_score : 52 叶丹 c++: 87 English: 96 math : 80 all_score : 263 ave_score : 87.6667 李悦 c++: 63 English: 97 math : 79 all_score : 239 ave_score : 79.6667 郭倩 c++: 69 English: 69 math : 94 all_score : 232 ave_score : 77.3333 刘盈 c++: 99 English: 93 math : 72 all_score : 264 ave_score : 88 杨洁 c++: 96 English: 87 math : 79 all_score : 262 ave_score : 87.3333 徐一菡 c++: 85 English: 62 math : 45 all_score : 192 ave_score : 64 王蒙 c++: 67 English: 89 math : 97 all_score : 253 ave_score : 84.3333 张敏 c++: 85 English: 89 math : 75 all_score : 249 ave_score : 83 桂佳 c++: 60 English: 65 math : 73 all_score : 198 ave_score : 66 林倩 c++: 67 English: 80 math : 77 all_score : 224 ave_score : 74.6667 任盛达 c++: 57 English: 88 math : 86 all_score : 231 ave_score : 77 吴佳林 c++: 96 English: 82 math : 65 all_score : 243 ave_score : 81 黄金龙 c++: 85 English: 78 math : 90 all_score : 253 ave_score : 84.3333 陈美珠 c++: 82 English: 83 math : 72 all_score : 237 ave_score : 79 冼丹 c++: 100 English: 89 math : 89 all_score : 278 ave_score : 92.6667 唐楠 c++: 68 English: 77 math : 97 all_score : 242 ave_score : 80.6667 张扬 c++: 77 English: 93 math : 65 all_score : 235 ave_score : 78.3333 宋航彬 c++: 80 English: 91 math : 71 all_score : 242 ave_score : 80.6667 薛淇文 c++: 89 English: 75 math : 71 all_score : 235 ave_score : 78.3333 刘紫亮 c++: 72 English: 84 math : 98 all_score : 254 ave_score : 84.6667 李瑞 c++: 100 English: 100 math : 100 all_score : 300 ave_score : 100 请按任意键继续. . . */
相关文章推荐
- C++程序设计实验报告(八十四) --- 第十七周任务一
- 第十七周实验报告1
- 第十七周实验报告1
- 第十七周实验报告(二)
- 第十七周实验报告二( 动态链表处理成绩 )
- 第十七周实验报告
- 《第十七周实验报告任务1——学生成绩处理:保存为二进制文件》
- 第十七周实验报告一(所有同学的成绩表等用结构体做)
- 《第十七周实验报告》报告3---揭开你生世的秘密
- 第十七周实验报告(1)
- 第十七周实验报告1
- 第十七周实验报告(2)
- 第十七周实验报告(2)动态链表
- 第十七周实验报告(3)
- 第十七周实验报告(三)
- 第十七周实验报告1
- 《C++第十七周实验报告1-1》---学生成绩处理:保存为二进制文件
- 第十七周实验报告1
- 第十七周实验报告1
- 第十七周实验报告2