WEEK 1 Task 1

Source: Internet
Author: User

/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All Rights Reserved.
* File Name:
* Author: Zhang chuanxin
* Completion date: January 1, June 13, 2012
* Version number:

* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/

# Include <iostream> # include <string> # include <iomanip> # 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 SC Ore_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 <setiosfla GS (IOs: Left) <SETW (12) <this-> name <SETW (8) <this-> score_cpp <SETW (8) <this-> score_math <SETW (8) <this-> score_english <SETW (8) <this-> score_all <SETW (8) <this-> score_average <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-> SCO Re_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 ("Zhang chuanxin", 100,100,100); readfile (STU, 100 ); writefile (STU, 100); readfile (stu1, 100); stu1 [100] = my_score; cout <setiosflags (IOs: Left) <SETW (12) <"name" <SETW (8) <"C ++" <SETW (8) <"high" <SETW (8) <"English" <SETW (8) <"total score" <SETW (8) <"average score" <Endl; For (INT I = 0; I <101; ++ I) {stu1 [I]. display ();} writefile (stu1, 101); System ("pause"); Return 0 ;}

Running result:

Name C ++ high English total score average
Liu proudly 60 98 75 233 77.6667
Wang Rui 63 90 96 249 83
He Weizhong 90 73 82 245 81.6667
Wang Lei 87 86 92 265 88.3333
Feng song 89 98 83 270 90
Pei 75 82 91 248 82.6667
Ma Yun 62 67 90 219 73
Ma Yun 98 84 87 269 89.6667
Zhou junsheng 57 68 96 221 73.6667
He Qi 61 96 72 229 76.3333
Li Tong 93 83 86 262 87.3333
Gao Lu 63 74 98 235 78.3333
Feng jiayuan 61 79 81 221 73.6667
Zhang Di 99 88 80 267 89
Zhang lixiang 85 65 96 246 82
Wang Rui 89 83 91 263 87.6667
Xu Jinzhu 75 89 73 237 79
Zhao xiaoyuan 77 75 66 218 72.6667
Song zongjie 94 100 92 286 95.3333
Zhang Jiawei 61 98 96 255 85
Wang Yi 70 91 90 251 83.6667
Song Yuanyuan 61 94 92 247 82.3333
Yu Li 55 66 78 199 66.3333
Yu Hao 78 84 72 234 78
Wang Jing 90 87 67 244 81.3333
Cui Zan 91 67 93 251 83.6667
Song Jing 69 85 73 227 75.6667
Wang Lei 71 78 77 226 75.3333
Radius 70 79 76 225 75
Li Peng 90 82 97 269 89.6667
Ma Jia 60 90 100 250 83.3333
Zhang Long 62 100 78 240 80
Mali 73 95 73 241 80.3333
Han Ming 83 97 88 268 89.3333
Mary 73 90 83 246 82
Wu qingzheng 89 97 85 271 90.3333
Yinhong 92 68 75 235 78.3333
Tian Miao 75 91 71 237 79
Wei Qing 66 73 77 216 72
Cold Cloud 89 88 71 248 82.6667
GE Zhiwei 100 79 71 250 83.3333
Fan zhenguang 98 87 89 274 91.3333
Wang Fang 71 97 99 267 89
Yang Chao 67 73 82 222 74
Yang mengying 89 99 67 255 85
Liang yaning 55 88 100 243 81
Wang Qi 98 95 98 291 97
Wu Wei, 69, 76, 68, 213, 71
Yang Kuo 90 91 98 279 93
Jia Weilin 63 90 86 239 79.6667
Liu yaxin 77 81 95 253 84.3333
Jin Xin 92 67 69 228 76
Dong Yiwei 93 88 80 261 87
Tang na 68 85 71 224 74.6667
Zhou Heng 87 82 69 238 79.3333
Zhang xiao86 88 76 250 83.3333
Wen Jing 93 88 85 266 88.6667
Yang Huaxin 81 81 68 230 76.6667
Su Mingxia 59 79 94 232 77.3333
Huang Jing 62 75 96 233 77.6667
Xin 60 79 98 237 79
Zhang Wen 69 70 93 232 77.3333
Liu Jingxi 67 78 223 74.3333
Xu jiaqi 90 75 87 252 84
Wei Jia 100 94 80 274 91.3333
Hold high 81 99 91 271 90.3333
Edge 56 94 87 237 79
He jacheng 70 75 78 223 74.3333
Zhao Xuyang 87 91 94 272 90.6667
Sun Dawei 65 69 98 232 77.3333
Rujisen 84 79 75 238 79.3333
Bai Tao 57 82 75 214 71.3333
Yan Jianfei 88 75 79 242 80.6667
Randday 83 66 74 223 74.3333
Wang Yue 79 82 70 231 77
Chen ShiBo 70 92 65 227 75.6667
Zhang Hao 94 83 96 273 91
HD 76 83 84 243 81
Wang xinxin 71 83 78 232 77.3333
Wang Huanhuan 57 33 66 156 52
Ye dan 87 80 96 263 87.6667
Li Yue 63 79 97 239 79.6667
Guo Qian 69 94 69 232 77.3333
Liu Ying 99 72 93 264 88
Yang Jie 96 79 87 262 87.3333
Xu Yizhen 85 45 62 192 64
Wang Meng 67 97 89 253 84.3333
Zhang Min 85 75 89 249 83
Gui Jia 60 73 65 198 66
Lin Qian 67 77 80 224 74.6667
Ren Shengda 57 86 88 231 77
Wu Jialin 96 65 82 243 81
Golden Dragon 85 90 78 253 84.3333
Chen meizhu 82 72 83 237 79
Dan 100 89 278 92.6667
Tang nanyi 68 97 77 242 80.6667
Zhang Yang 77 65 93 235 78.3333
Song hangbin 80 71 91 242 80.6667
Xue Wenwen 89 71 75 235 78.3333
Liu ziliang, 72 98 84 254 84.6667
Zhang chuanxin 100 100 100 300 100
Press any key to continue...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.