Project 3 in the second week uses struct data for Computation

Source: Internet
Author: User

Objective: to create a data struct

Computer content: Scholarship winners and rankings

 

/*. * Copyright and version Declaration of the program. * Copyright (c) 2013, a student from the computer College of Yantai University. * All rightsreserved .. * file name: text. cpp. * Author: Liu Yujin. * completion date: January 1, March 18, 2013. * version: v1.0. * input Description: Obtain the student list from the file. * Problem description: rank the student and the person who receives the scholarship. * output: student ranking and scholarship recipients */# include <iostream> # include <fstream> # include <cstdlib> using namespace std; struct Student {char num [13]; char name [10]; int cpp; int math; int english; int grade ;}; const Int N = 200; int main () {int I, j, k, stuNum = 0; Student stu [N], t_stu; ifstream infile ("score.txt", ios :: in); if (! Infile) {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]. grade = stu [I]. cpp + stu [I]. math + stu [I]. english; ++ stuNum; ++ I;} infile. close (); for (I = 0; I <stuNum-1; I ++) {k = I; for (j = I + 1; j <stuNum; j ++) if (stu [j]. grade> stu [k]. grade) k = j; t_stu = stu [k]; stu [k] = stu [I]; stu [I] = t_stu;} 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]. grade <endl ;}cout <"Congratulations to the following students for the scholarship" <endl; I = 0, j = 1; while (j <= 30) {if (stu [I]. cpp> = 60 & stu [I]. math> = 60 & stu [I]. english >=60) {cout <j <'\ t' <stu [I]. name <'\ t' <stu [I]. grade <endl; j ++;} I ++;} return 0 ;}

Running result:

 

Experience: this operation is performed based on the combination of Project 1 and project 2.

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.