# include & ltiostream & gt
Use STD:: CIN;
Use STD:: cout;
Use STD:: CERR;
Use STD:: endl;
Use STD:: IOs;
# include & ltfstream & gt
Use STD::of stream;;
Use STD::if stream;;
Use STD::fstream;;
# include & lt string & gt
Use STD::string;;
# include & ltiomanip & gt
Use STD:: setw;
int enter choice();
void searchGrade(string names[],string ID[],int Chinese[],int Math[],int Eng[],int row);
void changeGrade(string names[],string ID[],int Chinese[],int Math[],int Eng[],int row);
Void deleteGrade (string name [], string ID[], int Chinese[], int Math[], int Eng[], int & row);
Void addGrade (string name [], string ID[], int Chinese[], int Math[], int Eng[], int & row);
int getRow(if stream & amp; InP);
void getID(if stream & amp; Inp, string name [], string ID[], int Chinese [], int mathematics [], int engineering []);
void countGrade(string names[],string ID[],int Chinese[],int Math[],int Eng[],int row);
Void saveResult (string name [], string ID[], int Chinese [], int mathematics [], int project [], int line);
void showGrade(string names[],string ID[],int Chinese[],int Math[],int Eng[],int row);
void averGrade(int Chinese[],int Math[],int Eng[],int row);
int main()
{
ifstream infile(" grade info . txt ");
If (! infile){
Error occurred when cerr & lt& lt opened the file, gradeInfo.txt does not exist < & ltendl.
Exit (1); }
int row = getRow(infile);
infile . close(); //Ensure that the current number of students is row.
ifstream infile 2(" grade info . txt ");
//Provide performance management for up to 60 students. It is determined according to the current reasonable number of classes. It can be changed as needed.
String name [60]; //Name of student
String id [60]; //student ID
Int Chinese [60]; //Language scores
int Math[60]; //Math scores
int Eng[60]; //English scores
GetID(infile2, names, ID, Chinese, Mathematics, English); //Read student information from the file.
infile 2 . close();
Int part; //Its value indicates the module selected by the user.
//The main menu of the system. The user selects the operation to be performed.
And (part! =4){
Cout & lt& lt" \n ** Welcome to the student information management system * * "<& lt endel.
& lt& lt“-”& lt; & lt endel
& lt& lt "Please select the operation you want to perform"
& lt& lt" 1- Maintenance of student achievement information "
& lt< "2-Inquiry of Students' Achievement Information"
& lt< "3-Student Achievement Statistics"
& lt< "4-log out of the system"
& lt& lt“-”& lt; & ltendl
CIN & gt; & gt part;
if (part== 1){
Int selection; //The executive function selected by the user in the information maintenance module.
while((choice=enterChoice())! =4){
Switch (Select) {
Case 1:
AddGrade (name, ID, Chinese, math, English, line);
Break;
Case 2:
DeleteGrade (name, ID, Chinese, math, English, line);
Break;
Case 3:
ChangeGrade (name, ID, Chinese, math, English, row);
Break;
Default value:
Cerr & lt& lt "Your choice is incorrect" < & ltendl.
Break;
}
}
}
if (part==2){
Cout & lt& lt "Please select:"
& lt& lt" 1- query by student number or name "
& lt< "2-View all student information"
int allOrPart
CIN & gt; & gtallOrPart
if (allOrPart== 1)
SearchGrade (name, ID, Chinese, math, English, row);
if (allOrPart==2)
ShowGrade (name, ID, Chinese, math, English, row);
}
if (part==3){
Cout & lt& lt "Please select:"
& lt& lt" 1- Query the distribution of students in a single subject score "
& lt< "2-Calculate the average score of a single account"
int averOrPart
CIN & gt; & gtaverOrPart
if (averOrPart==2)
AverGrade (Chinese, math, English, and English);
if (averOrPart== 1)
CountGrade (name, ID, Chinese, math, English, row);
}
}
Returns 0;
}
//This function is used to obtain the information of the number of students stored in the current system.
int getRow(if stream & amp; inp)
{
int row = 0;
String a, name, id;
Int tag;
inp & gt& gta & gt& gta & gt& gta & gt& gta & gt& gta; //Skip the directory structure of the first line.
while(inp){
Inp>& gt name & gt& gtID & gt& gt mark & gt& gt mark;
row++;
}
Return line-1;
}
//This function is used to read the data in the text document into the memory for the user to operate on the terminal.
void getID(if stream & amp; Inp, string name [], string ID[], int Chinese [], int mathematics [], int engineering [])
{
String a;
inp & gt& gta & gt& gta & gt& gta & gt& gta & gt& gta; //Skip the directory structure of the first line.
int I = 0;
while(inp){
Inp>& gt name [i] > & gtID[I]& gt; & gt Chinese [I] > & gtmath[I]& gt; & gteng[I];
i++;
}
}
//This function realizes the sub-menu of the student achievement information maintenance module.
int enterChoice()
{
Cout & lt& lt "Please enter the operation you want to perform"
& lt& lt" | 1- Add student information | "
& lt& lt" | 2- Delete student information | "
& lt& lt" | 3- Modify student information | "
& lt& lt" | 4- Return to the previous level | "
Int selection;
CIN & gt; & gt selection;
Regression selection;
}
//This function provides users with the query function of students' grades, and can use students' names or student numbers.
Void searchGrade (string name [], string ID[], integer Chinese [], integer mathematics [], integer engineering [], integer line)
{
String searchGoal
Cout & lt< "\ nPlease enter student ID or name"
CIN & gt; & gtsearchGoal
Boolean discovery;
for(int j = 0; J< platoon; j++){
if(names[j]= = search goal | | ID[j]= = search goal){
Cout & lt& lt "query results"
& lt& lt "name, student number, Chinese, math, English" << endel.
& lt& ltsetw(6)& lt; & ltnames[j]& lt; & ltsetw(6)& lt; & ltID[j]& lt; & ltsetw(6)& lt; & lt Chinese [j] < & ltsetw(6)& lt; & ltmath[j]& lt; & ltsetw(6)& lt; & lteng[j]& lt; & ltendl
Discovery = true;
Break;
}
}
If (found! = true)
Cout & lt& lt "The searched student scores do not exist" < & ltendl
}
//This function can delete the student information records stored in the system.
Void deleteGrade (string name [], string ID[], int Chinese[], int Math[], int Eng[], int & line)
{
Cout & lt< "\ nPlease enter the name or student number of the student whose information you want to delete"
String delName
CIN & gt; & gtdelName
Boolean discovery;
for(int j = 0; J< platoon; j++){
if(names[j]= = delName | | ID[j]= = delName){
Discovery = true;
names[j]= " \ 0 ";
ID[j]= " \ 0 ";
Chinese [j] =-1;
math[j]=- 1;
eng[j]=- 1;
SaveResult (name, ID, Chinese, math, English, line);
Cout & lt& lt "Student information has been deleted successfully"
}
}
If (found! = true)
Cout & lt& lt "The student information to be deleted does not exist"
}
//This function can write new student information into a text file.
Void addGrade (string name [], string ID[], int Chinese[], int Math[], int Eng[], int & line)
{
String newID
Cout & lt& lt "Please enter the student ID first:"
//So judge whether the information to be added is duplicate by the student number.
CIN & gt; & gtnewID
Boolean existence;
for(int j = 0; J< platoon; j++)
if(newID==ID[j]){
Cout & lt& lt "Student information already exists"
Existence = truth;
Break; }
If (exists! = true) {
Cout & lt< \ nPlease enter the student's name and three grades again, separated by the space bar. endl
ID[row]= newID;
CIN & gt; & gtnames[row]& gt; & gt Chinese [row] > & gtmath[row]& gt; & gteng[row];
row++;
SaveResult (name, ID, Chinese, math, English, line);
Cout & lt& lt "Student information added successfully"
}
}
//This function can change all kinds of information of students.
Void changeGrade (string name [], string ID[], integer Chinese [], integer mathematics [], integer engineering [], integer line)
{
String changeGoal
Cout & lt< "\ nPlease enter the name or student number of the student whose information you want to change:";
CIN & gt; & gt change the target;
Boolean discovery;
Int changeNum// User's option to modify content.
for(int j = 0; J< platoon; j++){
if(names[j]= = change goal | | ID[j]= = change goal){
Discovery = true;
Cout & lt& lt "The original information of this student is:"
& lt& lt "name, student number, Chinese, math, English" << endel.
& lt& ltsetw(6)& lt; & ltnames[j]& lt; & ltsetw(6)& lt; & ltID[j]
& lt& ltsetw(6)& lt; & lt Chinese [j] < & ltsetw(6)& lt; & lt Mathematics [j]
& lt& ltsetw(6)& lt; & lteng[j]& lt; & lt endel
& lt& lt "Please select:"
& lt& lt" 1- Modify student name "
& lt& lt" 2- Modify Student ID "
& lt< "3-Revise Chinese scores"
& lt< "4-Modify Math Score"
& lt< "5-Revise English scores"
CIN & gt; & gtchangeNum
Cout & lt& lt "Please enter the modified content:";
Switch (changenum)
Case 1:
CIN & gt; & gt name [j];
Break;
Case 2:
CIN & gt; & gtID[j];
Break;
Case 3:
CIN & gt; & gt Chinese [j];
Break;
Case 4:
CIN & gt; & gtmath[j];
Break;
Case 5:
CIN & gt; & gteng[j];
Break;
}
SaveResult (name, ID, Chinese, math, English, line);
Cout & lt< "\ nModification succeeded!" & lt& lt endel
& lt& lt "The revised student information is:"
& lt& lt "name, student number, Chinese, math, English" << endel.
& lt& ltsetw(6)& lt; & ltnames[j]& lt; & ltsetw(6)& lt; & ltID[j]
& lt& ltsetw(6)& lt; & lt Chinese [j] < & ltsetw(6)& lt; & lt Mathematics [j]
& lt& ltsetw(6)& lt; & lteng[j]& lt; & ltendl
}
}
If (found! = true)
Cout & lt& lt "The student information to be modified does not exist"
}
//This function can count the distribution of students in a certain subject and a certain fraction, including students' names, student numbers, grades and the number of people in that fraction.
Void countGrade (string name [], string ID[], integer Chinese [], integer mathematics [], integer engineering [], integer line)
{
String theme;
Int is low and high;
int count result = 0;
Cout & lt< \ nPlease enter the course name and score segment to be queried, separated by spaces, such as English 60 70.
CIN & gt; & gt theme & gt& gt low>& gt high;
Cout & lt& lt theme & lt& lt "Achievement lies in"
for(int I = 0; I< platoon; i++){
If (subject== "Chinese"&; & Chinese [I] > = low & Chinese [I] <; = high) {
count result++;
cout & lt& ltsetw(7)& lt; & lt name [I] < & ltsetw(7)& lt; & lt "student number"
& lt& ltsetw(5)& lt; & ltID[I]& lt; & ltsetw(7)& lt; & lt "score"
& lt& ltsetw(7)& lt; & lt Chinese [I] < & ltendl
}
If (subject== "Mathematics"&; & ampmath[I]& gt; = low & math [I] <; = high) {
count result++;
cout & lt& ltsetw(7)& lt; & lt name [I] < & ltsetw(7)& lt; & lt "student number"
& lt& ltsetw(5)& lt; & ltID[I]& lt; & ltsetw(7)& lt; & lt "score"
& lt& ltsetw(7)& lt; & ltmath[I]& lt; & ltendl
}
if(subject = = " English " &; & ampeng[I]& gt; = low & peng [i] < = high) {
count result++;
cout & lt& ltsetw(7)& lt; & lt name [I] < & ltsetw(7)& lt; & lt "student number"
& lt& ltsetw(5)& lt; & ltID[I]& lt; & ltsetw(7)& lt; & lt "score"
& lt& ltsetw(7)& lt; & lteng[I]& lt; & ltendl
}
}
Cout & lt< "\ n * *"< & ltccountresult & lt "people"
}
//This function can save the changes of students' information data in memory to a text file.
Void saveResult (string name [], string ID[], integer Chinese [], integer mathematics [], integer project [], integer line)
{
of stream outfile(" grade info . txt ");
Outfile & lt& lt "name, student number, Chinese, math, English" < & ltendl.
for(int n = 0; N< row; n++){
if (names[n]! ="\0")
outfile & lt& ltsetw(7)& lt; < name [n] < & ltsetw(6)& lt; & ltID[n]
& lt& ltsetw(7)& lt; < Chinese [n] < & ltsetw(7)& lt; & lt Mathematics
& lt& ltsetw(7)& lt; & lteng[n]& lt; & ltendl
}
}
//Displays all student information recorded in the current system.
Void showGrade (string name [], string ID[], integer Chinese [], integer mathematics [], integer engineering [], integer line)
{
for(int n = 0; N< row; n++){
if (names[n]! ="\0")
cout & lt& ltsetw(7)& lt; < name [n] < & ltsetw(6)& lt; & ltID[n]
& lt& ltsetw(7)& lt; < Chinese [n] < & ltsetw(7)& lt; & lt Mathematics
& lt& ltsetw(7)& lt; & lteng[n]& lt; & ltendl
}
}
//Calculate the average score of single subject.
void average(int Chinese[],int Math[],int Eng[],int row)
{
Cout & lt& lt "Please select the account for which you want to calculate the average score:"
& lt& lt" 1- Chinese "
& lt< "2-Mathematics" << endel
& lt< "3-English"
Int theme;
CIN & gt; & gt subject;
int sum = 0;
for(int n = 0; N< row; n++){
if (Eng[n]! =- 1)
{
if (subject== 1)
Sum+= Chinese [n];
if (subject==2)
sum+= Math[n];
if (subject==3)
sum+= Eng[n];
}
else row = row- 1;
}
Double averGrade
averGrade = static _ cast & ltdouble & gt(sum)/static _ cast & lt; Double >
The average score of cout & lt& lt "is:"
}