Item 2 of week 16: unable to enter the new list

Source: Internet
Author: User
/** 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 .....

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.