/** Copyright and version declaration section of the Program * Copyright (c) 2012, student * All rightsreserved from computer College of Yantai University. * file name: fun. cpp * Author: Li Yang * Completion Date: July 15, June 20, 2013 * version: v1.0 * input Description: omitted * Problem description: omitted * program output: slightly */# include <fstream> # include <iostream> # include <string> # include <cstdlib> using namespace std; int number = 0; // define the Student class Student {public: string name; double cpp; double math; double english; double total ;}; int main () {Student stu [200]; // stu [200] indicates the number of objects for data storage. Group // read the data in the file into the object array; double stotal = 0, average = 0; ifstream infile ("score. dat ", ios: in); // open the file as input if (! Infile) // test whether {cerr <"open error! "<Endl; exit (1) ;}while (! Infile. eof () {infile> stu [number]. name> stu [number]. cpp> stu [number]. math> stu [number]. // read data in stu [number]. total = stu [number]. cpp + stu [number]. math + stu [number]. english; stotal = stotal + stu [number]. total; average = stotal/number; number ++;} infile. close (); // close ofstream outfile ("pass_score.txt", ios: out); if (! Outfile) // test whether {cerr <"open error! "<Endl; exit (1) ;}for (int I = 0; I <number; ++ I) {if (stu [I]. total> = average & stu [I]. cpp> = 60 & stu [I]. math> = 60 & stu [I]. english >=60) {outfile <stu [I]. name <"" <stu [I]. cpp <"" <stu [I]. math <"" <stu [I]. english <endl; // write data} outfile. close (); // close cout <"Please go to pass_score.txt to view the list:" <endl; return 0 ;}
Sentiment: although the writing method is a bit simple, I have some experience on file-related operations! But there are still a lot of things you don't understand. You still need to work hard .....