A Super Classic C + + structure topic _c language

Source: Internet
Author: User
Tags float max
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;
}


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.