Topic Description:
There are 10 students, each student's data include number, name, English, maths, physics three classes of results, from the keyboard input 10 student data, asked to print out the total average of 3 courses, as well as the highest score of the student data (including school number, name, 3 course average score, average scores).
C + + code:
Copy Code code as follows:
#include <iostream>
#include <string>
using namespace Std;
struct student{//declares the structure body Student
String num;
String name;
float 中文版;
float match;
float physics;
float average;
};
Functions for void Shuchu (Student &s) {//Structure body content output
cout<<s.num<< "T";
cout<<s.name<< "T";
cout<<s.english<< "T";
cout<<s.match<< "T";
cout<<s.physics<< "T";
cout<<s.average<<endl;
}
int main () {
Student s[10];//declares the structure body array
cout<< "Num\tname\tenglish\tmatch\tphysics" <<endl;
int i=0;
for (; i<10;i++) {//initialization of structure statistics
cin>>s[i].num;
cin>>s[i].name;
cin>>s[i].english;
cin>>s[i].match;
cin>>s[i].physics;
S[i].average= (S[i].english+s[i].match+s[i].physics)/3;
}
float Max=s[0].average;
int k=1;
cout<< "=============show data=======" <<endl;
for (i=0;i<10;i++) {
Shuchu (S[i]);//output Structure body contents
if (S[i].average>max) {///through the Daleitai method to obtain the highest average data
K=i;
Max=s[i].average;
}
}
cout<< "The hightest:" <<endl;
Shuchu (S[k]);//output Highest score data
cout<<endl;
return 0;
}