3-5 Student Score statistics Time Limit: 1000 ms memory limit: 65536 K Description
This topic describes how to use an object array. It is mainly used to input and output data in an object array.
Design a student with a private data member: Student ID, name, mathematics score, English score, and computer score; have a public member function: calculate the int sum () function of the total score of the three courses, the double average () function of the average score of the three courses, and the void print () function of the basic information, total score, and average score of the students (); the voidset_stu_info function that sets student data information (int n, char * P, int M, int e, int C ).
Compile the main function, create an array of student objects, input a group of student data from the keyboard, and output the student's score statistical table:
Stuid name: average score of the mathematics English computer
001 XXX 90 85 95 270 90.0
002 YYY 95 98 92 285 95.0
Input
There are five rows of input data, representing the information of five students.
Each row has five data records, separated by a space, representing the student's student ID, name, mathematics score, English score, and computer score. Except the name as a symbol string, all other data types are integer data and the data is within the int type.
Output
There are 7 rows of output data.
The first line outputs the message "input the messages of five students (studentid name math English computer )"
The second row outputs an empty row, which is used to separate input and output.
The output header of the third row is "stuid name math Eng com total average", which contains 7 data records separated by the tab '\ t, the student ID, name, mathematics score, English score, computer score, total score, and average score are displayed respectively. The average score is real-type data, with one decimal point retained.
Row 4-8 outputs data of five students. Each data occupies a tab space. The format is the same as above.
Sample Input
1001 Andy 89 90 931002 Mary 93 95 981003 Luis 90 85 981004 Sam 91 95 981005 Lily 87 98 99
Sample output
Input the messages of five students(StudentID Name Math English Computer )StuIDNameMathEngComTotalAverage1001Andy89 9093 27290.71002Mary93 9598 286 95.31003Luis 90 85 98 27391.01004Sam 91 9598 284 94.71005Lily 87 9899 284 94.7
Sample program from Huang Jingjing
# Include <iostream> # include <cstdio> // C Language Input and Output header file # include <cstring> // string operation header file using namespace STD; // define a student class student {PRIVATE: // Private int SnO, math, English, computer; char name [100]; public: // public void input (int id, char * s, int A, int B, int c) // Input Function Note: Do not forget * {SnO = ID; strcpy (name, S); // string copy Math = A; English = B; computer = C;} void output () // output function {printf ("% d \ t % s \ t % d \ t %. 1f \ n ", SnO, name, math, English, computer, math + English + computer, (Math + English + computer) * 1.0/3.0 );}}; int main () // main function {int I; int SnO, math, English, computer; char name [100]; Student STU [5]; for (I = 0; I <5; I ++) // enter five student information {CIN> SnO> Name> math> English> Computer; STU [I]. input (SNO, name, math, English, computer) ;}cout <"input the messages of five students (studentid name math English computer)" <Endl; cout <"stuid" <"\ t" <"name" <"\ t" <"math" <"\ t" <"eng" <<"\ t" <"com" <"\ t" <"Total" <"\ t" <"average" <Endl; for (I = 0; I <5; I ++) // output five student information {STU [I]. output () ;}return 0 ;}
The following are others:
#include <iostream>#include<stdio.h>using namespace std;class student{public: int sum(); double average(); void print(); void set();private: int num; char name[20]; int math; int eng; int com;};int student::sum(){ return (math+eng+com);}double student::average(){ return ((math+eng+com)/3.0);}void student::print(){ cout<<num<<'\t'<<name<<'\t'<<math<<'\t'<<eng<<'\t'<<com<<'\t'<<sum()<<'\t'; printf("%.1f",average()); cout<<endl;}void student::set(){ cin>>num>>name>>math>>eng>>com;}int main(){ int i; student stu[5]; for(i=0; i<=4; i++) stu[i].set(); cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl; cout<<endl; cout<<"StuID"<<'\t'<<"Name"<<'\t'<<"Math"<<'\t'<<"Eng"<<'\t'<<"Com"<<'\t'<<"Total"<<'\t'<<"Average"<<endl; for(i=0; i<=4; i++) stu[i].print(); return 0;}/**************************************Problem id: SDUT OJ E User name: zxw130219Result: Accepted Take Memory: 556K Take Time: 0MS Submit Time: 2014-09-30 08:43:56 **************************************/
Sdut 3-5 Student Score statistics