Sophomore winter brush essay questions

7.5 Sorting student achievement

The basic assumptions of student information, including number, name, three courses achievements and personal grade point average, the definition of a type capable of representing the structure of student information. Enter n (n <50) student achievement information, according to individual student's average score from high to low output their information. If the average the same, arranged in order of input.

Input formats:
Enter a positive integer n (n <50), the following line input n n student information, including: school, name, score three courses (integer).

Output formats:
student information output from high to low sort, including: Student ID, name, the average score (two decimal places).

Sample input:
. 3
101 Zhang 78 87 85
102 88 91 is Wang 90
103 75 90 84 of Li

Output Sample:
102, Wang, 89.67
101, Zhang, 83.33
103, of Li, 83.00

Experiment code:

#include<iostream>
#include<algorithm>
using namespace std;
struct stu{
    int id;
    char name[50];
    int a,b,c;
    double avg;
}s[55];
bool cmp(stu x,stu y){
    return x.avg>y.avg;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i].id>>s[i].name>>s[i].a>>s[i].b>>s[i].c;
        s[i].avg=(s[i].a+s[i].b+s[i].c)/3.0;//注意除以3.0而不是3,否则得不到有效浮点数
    }
    sort(s,s+n,cmp);
    for(int i=0;i<n;i++){
    printf("%d,%s,%.2f\n",s[i].id,s[i].name,s[i].avg);
    }
    return 0;
}

Problems:

1. c language written with the first pass of the time found himself a string of very poor grasp of knowledge, and then open the books to brush up before the details of the input and output as well as a string pointer
2. Computer with vs and the file will appear vc6 does not exist, has not compiled, bored, could not understand debug inside exe files can not find what is the reason to waste a lot of time, and finally also with devc ++, has been staying in this does not solve the problem, tried many ways
the first c ++ 3. it is my submission procedures, found that c ++ really better than c quick and easy much
the beginning I did not grasp c ++, this is my vulnerability, I intend to buy a book to learn about c ++, can not always use scanf printf, c ++ feeling hard work in solving logic problems very easy, not so hard

to sum up

Winter feeling did not write any code, I base this on the weak become more precarious, pta now watching the above topic a little fat ignorant, the feeling has been unable to start, but do not remember many details, thief trouble
as well as macro and pointer learn the poor thief trouble. . . . . . . Do not feel confident to write code, you are not required to sink the heart to see a few books. Hey

Guess you like

Origin www.cnblogs.com/husiyu/p/12273279.html