I am a cainiao, so the compilation is relatively simple. Here is my small attempt. I hope you can criticize and correct me. This cainiao will be very grateful.
Figure 1 input data and operation command INTERFACE
Figure 2 average column score LIST Command
# Include "stdafx. H"
# Include <iostream>
# Include <string>
Using namespace STD;
Using STD: string;
String S, name, code, name1, code1;
Char comd;
Float Chinese, English, math, tchinese = 0, tenglish = 0, tmath = 0;
Int I = 0;
Class studentrecord
{
PRIVATE:
String name;
String code;
Float Chinese;
Float English;
Float math;
Float total;
Float average;
Public:
Studentrecord (){}
Studentrecord (string N, string Co, float C, float E, float m): Name (N), Code (CO), Chinese (C), English (e ), math (m)
{
Total = C + E + m;
Average = total/3;
}
String getname ()
{Return name ;}
String getcode ()
{Return code ;}
Float getchinese ()
{Return Chinese ;}
Float getenglish ()
{Return English ;}
Float getmath ()
{Return math ;}
Float gettotal ()
{Return total ;}
Void print ()
{
Cout <"---------------------------------------------" <Endl;
Cout <"name:" <name <Endl;
Cout <"Code:" <Code <Endl;
Cout <"marks:" <Endl;
Cout <"Chinese:" <Chinese <Endl;
Cout <"English:" <English <Endl;
Cout <"Math:" <math <Endl;
Cout <"Total:" <total <Endl;
Cout <"average:" <average <Endl;
Cout <"---------------------------------------------" <Endl;
}
};
Void list (studentrecord * pobj, int I); // declares the function of the column student list
Void fname (studentrecord * pobj, int I); // declare a function to search for students by name
Void fcode (studentrecord * pobj, int I); // declare the function for finding students by student ID
Void getaverage (studentrecord * pobj, int I); // declares the function for calculating the average score.
Void sortlist (int I); // declares the function that outputs the list after sorting by the total score.
Void getfirst (int K, int I); // sorting Function
Studentrecord OBJ [20]; // defines 20 studentrecord objects
Int _ tmain (INT argc, _ tchar * argv [])
{
Cout <"***********************************" <Endl;
Cout <"Student Score Management Course" <Endl;
Cout <"Producer: dragonfly" <Endl;
Cout <"Thank you !!! "<Endl;
Cout <"***********************************" <Endl;
Do // enter Student Information
{
If (S = "end") break;
Cout <"Please enter the name :";
Cin> name;
Cout <"Please enter the code :";
Cin> code;
Cout <"Please enter the Chinese mark :";
Cin> Chinese;
Cout <"Please enter the English mark :";
Cin> English;
Cout <"Please enter the math MARK :";
Cin> math;
OBJ [I] = studentrecord (name, code, Chinese, English, math );
I ++;
Cout <"pass any key to continue... enter end to exit :";
} While (CIN> S );
Cout <"----------------------------------------------------------" <Endl;
Cout <"Now you can input a command to manage the record." <Endl;
Cout <"L: list all the record." <Endl;
Cout <"N: search record by student's name." <Endl;
Cout <"C: search record by student's code." <Endl;
Cout <"M: mean of the marks." <Endl;
Cout <"s: sort and list the record by the total." <Endl;
While (CIN> comd) // enter the student information to start student information processing.
{
Switch (comd)
{
Case 'l ':
List (OBJ, I );
Break;
Case 'N ':
Fname (OBJ, I );
Break;
Case 'C ':
Fcode (OBJ, I );
Break;
Case 'M ':
Getaverage (OBJ, I );
Break;
Case's ':
Sortlist (I );
}
}
Return 0;
}
Void list (studentrecord * pobj, int I)
{
For (Int J = 0; j <I; j ++)
{
Pobj-> Print ();
Pobj ++;
}
Cout <"Please enter the command :";
}
Void fname (studentrecord * pobj, int I)
{
Cout <"Please enter the name :";
Cin> name1;
For (Int J = 0; j <I; j ++)
{
If (pobj-> getname () = name1)
{
Pobj-> Print ();
Break;
}
Pobj ++;
}
Cout <"Please enter the command :";
}
Void fcode (studentrecord * pobj, int I)
{
Cout <"Please enter the code :";
Cin> code1;
For (Int J = 0; j <I; j ++)
{
If (pobj-> getcode () = code1)
{
Pobj-> Print ();
Break;
}
Pobj ++;
}
Cout <"Please enter the command :";
}
Void getaverage (studentrecord * pobj, int I)
{
Tchinese = 0;
Tenglish = 0;
Tmath = 0;
For (Int J = 0; j <I; j ++)
{
Tchinese + = pobj-> getchinese ();
Tenglish + = pobj-> getenglish ();
Tmath + = pobj-> getmath ();
Pobj ++;
}
Cout <"---------------------------------------------" <Endl;
Cout <"Chinese's average is:" <(tchinese/I) <Endl;
Cout <"English's average is:" <(tenglish/I) <Endl;
Cout <"math's average is:" <(tmath/I) <Endl;
Cout <"---------------------------------------------" <Endl;
Cout <"Please enter the command :";
}
Void sortlist (int I)
{
For (int K = 0; k <I; k ++)
Getfirst (K, I );
Cout <"Please enter the command :";
}
Void getfirst (int K, int I)
{
For (Int J = k + 1; j <I; j ++)
{
If (OBJ [K]. gettotal () <OBJ [J]. gettotal ())
{
Studentrecord temp;
Temp = OBJ [k];
OBJ [k] = OBJ [J];
OBJ [J] = temp;
}
}
Cout <"no." <(k + 1) <"name:" <OBJ [K]. getname () <Endl;
OBJ [K]. Print ();
}