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.