Struct array Calculation

Source: Internet
Author: User

[Cpp]/* [project 3-calculation with struct array] project 2, * Copyright (c) 2013, student * All rightsreserved from computer College of Yantai University. * file name: score. cpp * Author: egg * completion date: October 13, March 13, 2013 * version: v1.0 * input Description: * Problem description: (1) read data from the file and store it in your defined struct array, that is, project 2 (1); (2) calculate the total score of each student (which can be calculated by the way in the reading process); (3) sort by the total score (in descending order ); www.2cto.com (4) outputs the sorted transcript. (5) 30 students can receive scholarships. The rule is that those with a higher overall score are preferred. Please output a list of eligible scholarship students. (6) select to calculate the average score, highest and lowest score, and standard deviation of each course and total score, and output the results. Two versions are recommended: (1) All functions are in the main () function; (2) use a custom function to implement each task * output: after reading the list of scholarship students and transcript * operation sentiment: Still reading failed, do not understand it completely, cannot find. dat 5555 */# include <iostream> # include <fstream> using namespace std; struct Student {char num [12]; char name [12]; int cpp; int math; int english; int score ;}; const int N = 200; int main () {int I, stuNum = 0; Student stu [N]; ifstream infile ("score.txt ", ios: in); // open the object if (! Infile) // test whether {cerr <"open error! "<Endl; exit (1) ;} I = 0; while (! Infile. eof () {infile> stu [I]. num> stu [I]. name> stu [I]. cpp> stu [I]. math> stu [I]. english; stu [I]. score = stu [I]. cpp + stu [I]. math + stu [I]. english; ++ stuNum; ++ I;} infile. close (); Student t; for (I = 0; I <stuNum-1; I ++) {for (int j = 0; j <stuNum-i-1; j ++) {if (stu [j]. score <stu [j + 1]. score) {t = stu [j]; stu [j] = stu [j + 1]; stu [j + 1] = t ;}}for (I = 0; I <stuNum; ++ I) {cout <stu [I]. num <"\ t" <stu [I]. name <"\ t" <stu [I]. cpp <"\ t" <stu [I]. math <"\ t" <stu [I]. english <"\ t" <stu [I]. score <endl ;}cout <"the following students are awarded the scholarship" <endl; if (stu [I]. cpp> = 60 & stu [I]. math> = 60 & stu [I]. english> = 60) {int j = 0; www.2cto.com while (j <30) {cout <stu [I]. num <"\ t" <stu [I]. name <"\ t" <stu [I]. cpp <"\ t" <stu [I]. math <"\ t" <stu [I]. english <"\ t" <stu [I]. score <endl; j ++;} I ++;} return 0 ;}

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.