C++ source code of student information management system

# include & ltiostream & gt

# include & ltstdlib.h & gt

# include & ltstring.h & gt

# include & ltmalloc.h & gt

#define INIT_SIZE 10

# Define incr _ SIZE 10

# Define Subject _ Number 3

# Define Lens 3

void show _ Start();

void show _ Table();

void add record();

void Info _ delete();

void deleteRecord();

void delete _ Num(int);

void delete _ Name(char tarName[]);

void Info _ modify();

void modify record();

void modify _ Num(int);

void modify _ Name(char[]);

void Info _ query();

void query record();

void query _ Num(int);

void query _ Name(char[]);

Void display ();

void quit();

void menu _ CMD();

Char *subject[SUBJECT_NUM] = {"Gao Dai", "Shu Fen", "C language"};

Structural students

{

int num

char name[20];

Charming sex;

Floating score [subject _ num];

};

//struct STUDENT stu[LEN+ 1];

//STUDENT * record =(STUDENT *)malloc(sizeof(STUDENT)* INIT _ SIZE);

int static stuNum = 0;

//Let's temporarily define three students. ...

Student * record = (student *)malloc(sizeof (student) * init _ size); ;

int main()

{

//record =(STUDENT *)malloc(SIZE of(STUDENT)* INIT _ SIZE);

//STUDENT * record =(STUDENT *)malloc(sizeof(STUDENT)* INIT _ SIZE);

/*

Record [1]. num = 100 1;

Strcpy (record [1]). Name, "Jason");

Record [1]. sex = ' M

Record [1]. Score [0] = 85.0;

Record [1]. Score [1] = 90.0;

Record [1]. Score [2] = 95.0;

Record [2]. num = 1002;

Strcpy (record [2]). Name, "Jerry");

Record [2]. sex = ' M

Record [2]. Score [0] = 85.0;

Record [2]. Score [1] = 90.0;

Record [2]. Score [2] = 95.0;

Record [3]. num = 1003;

Strcpy (record [3]). Name, "Jesse");

Record [3]. Gender =' F

Record [3]. Score [0] = 85.0;

Record [3]. Score [1] = 90.0;

Record [3]. Score [2] = 95.0;

*/

/*

info _ modify();

Int key;

Cout & lt& lt "Please enter your choice:";

CIN & gt; & gt key;

if(key == 1)

{

int targetNum

Cout & lt& lt "Please enter the student ID of the student you want to modify:";

CIN & gt; & gttargetNum

modify _ Num(target Num);

cout & lt& ltendl

Display ();

}

if(key == 2)

{

char target name[20];

Cout & lt& lt Please enter the name of the student you want to modify:

CIN & gt; & gttargetName

Modify_Name (target name);

cout & lt& ltendl

Display ();

}

if(key == 3)

{

Exit (0);

}

*/

show _ Start();

menu _ CMD();

Returns 0;

}

//It should also be displayed after modification.

void show_Start()

{

//cout & lt; & ltendl

cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *”& lt; & ltendl

Cout & lt& lt "This is a"

Cout & lt& lt "Student Achievement Management System"

Cout & lt& lt "Student grades can be managed"

Cout & lt& lt "Welcome" < & ltendl

Cout & lt& lt "Made by Jason"<& ltendl

cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *”& lt; & ltendl

}

//Displays header information, namely: student number, name, gender, senior generation, score and C language.

void show_Table()

{

Cout & lt& lt "student number" <<" \ t "<& lt" name "

Cout & lt& lt" \ t "<& lt theme [0] < & lt" \ t " & lt& ltsubject[ 1]& lt; & lt" \ t "<& lt theme [2];

cout & lt& ltendl

}

void menu_CMD()

{

Int key;

while( 1)

{

Cout & lt& lt" 1. Add student information "

Cout & lt& lt"2. Delete student information "

Cout & lt& lt"3. Modify student information "

Cout & lt& lt"4. Inquire about student information "

Cout & lt& lt"5. Show student information "

Cout & lt& lt"6. Quit "

Cout & lt& lt "Please enter your choice:";

CIN & gt; & gt key;

while( 1)

{

If ((key<1) || (key > 6))

{

Int key;

Cout & lt& lt "You entered it incorrectly, please re-enter!" & lt& ltendl

Cout & lt& lt Please select (1-5):;

CIN & gt; & gt key;

}

other

{

Break;

}

}

Switch (key)

{

Case 1:

add record();

Break;

Case 2:

deleteRecord();

Break;

Case 3:

modify record();

Break;

Case 4:

query record();

Break;

Case 5:

Display ();

Break;

Case 6:

quit();

Break;

}

}

}

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//Add student information

void addRecord()

{

if(stuNum == 0)

{

Cout & lt& lt "has no record. Now create a new table! " & lt& ltendl

stun um++;

}

other

{

Cout & lt& lt "Now add new information at the end of the current table!" & lt& ltendl

stun um++;

}

//If the array space is insufficient, reapply for space.

if(stuNum & gt; Initialization size)

{

Cout & lt& lt "There is not enough memory space. Now apply for a new memory space!" & lt& ltendl

record =(STUDENT *)realloc(record,(INIT _ SIZE+incr _ SIZE)* sizeof(STUDENT));

Cout & lt& lt "Space application completed!" & lt& ltendl

}

Cout & lt& lt You want to add a new set of information now, are you sure? & lt& ltendl

Cout & lt& lt "Please enter your choice (Yes/No):";

char choi

CIN & gt; & gt Cui;

if((choi == 'Y')||(choi == 'y '))

{

Cout & lt& lt "Please enter your student number:";

CIN & gt; & gt record [stun]. num

Cout & lt& lt Please enter a name: ";

CIN & gt; & gt record [stun]. Name;

Cout & lt& lt "Please enter gender (m is male and f is female)";

CIN & gt; & gt record [stun]. Sex;

int I;

for(I = 0; I< number of topics; i++)

{

Cout & lt& lt "Please enter"

CIN & gt; & gt record [stun]. Score [I];

}

}

if((choi == 'N')||(choi == 'n '))

{

Cout & lt& lt "Stop adding new student information!" & lt& ltendl

cout & lt& ltendl

}

Cout & lt& lt "already has"

cout & lt& ltendl

}

//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////

//Delete information at night. ...

//Displays the header information of deleteRecord.

void Info_delete()

{

Cout & lt& lt "Please enter a deletion method:"

Cout & lt& lt" 1. Delete by student number "

Cout & lt& lt"2. Delete by name "

Cout & lt& lt"3. Exit and delete "

}

//Delete student information, including two sub-functions.

void deleteRecord()

{

Int key;

cout & lt& ltendl

info _ delete();

Cout & lt& lt "Please enter your choice:";

CIN & gt; & gt key;

if(key == 1)

{

int targetNum

Cout & lt& lt "Please enter the student ID of the student you want to delete:";

CIN & gt; & gttargetNum

//Delete by Student ID

delete _ Num(target Num);

cout & lt& ltendl

}

if(key == 2)

{

char target name[20];

Cout & lt& lt Please enter the name of the student you want to delete:

CIN & gt; & gttargetName

//Delete by name

delete _ Name(target Name);

cout & lt& ltendl

}

if(key == 3)

{

while( 1)

{

menu _ CMD();

}

}

}

//Delete the student information according to the student number.

//Only delete operation is needed, and no output is needed. The output operation can be performed in the main menu.

void delete_Num(int tarNum)

{

int I;

for(I = 1; I<= stuNumi++)

{

If (record [i]. num == tarNum)

{

//Deletion will be discussed in two cases.

// 1. The student information to be deleted is the last one.

//2. The student information to be deleted is not the last one.

//In the first case, the student to be deleted is the last one.

if(i = stuNum)

{

Cout & lt& lt "The student information you want to delete is:"

show _ Table();

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex<& lt" \t "

& lt& lt record [i]. Score [0] < & lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

cout & lt& ltendl

Cout & lt& ltendl & lt& lt "The deleted student information table is:"

show _ Table();

for(int I = 1; I< = stunum-1; i++)

{

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

for(int j = 0; Number of j< topics; j++)

{

Cout & lt& lt" \ t "<& lt record [i]. score[j];

}

cout & lt& ltendl

}

//Display information should be put in the back.

/*

stuNum-;

Cout & lt& lt "Now only"

cout & lt& ltendl

*/

}

//2. In the second case, the student to be deleted is not the last one.

If (me! = stuNum)

{

Cout & lt& lt "The student letter information you want to delete is:"

show _ Table();

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex<& lt" \t "

& lt& lt record [i]. Score [0] < & lt" \ t "<& lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

for(int j = I+ 1; j & lt= stuNumj++)

{

Record [j- 1] = record [j];

}

//Then finish the output.

cout & lt& ltendl

Cout & lt& lt "The deleted student information table is:"

show _ Table();

for(int I = 1; I< = stunum-1; i++)

{

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

for(int j = 0; Number of j< topics; j++)

{

Cout & lt& lt" \ t "<& lt record [i]. score[j];

}

cout & lt& ltendl

}

/*

stuNum-;

Cout & lt& lt "Now only"

cout & lt& ltendl

*/

}

stuNum-;

Cout & lt& lt "What's left now"

cout & lt& ltendl

}

}

}

/*

//The method is the same as above

void delete_Name(char tarName[])

{

int I;

for(I = 1; I<= stuNumi++)

{

if(strcmp(record[i])。 name,tarName) == 0)

{

//Deletion will be discussed in two cases.

// 1. The student information to be deleted is the last one.

//2. The student information to be deleted is not the last one.

//Case 1: The student to be deleted is the last one.

if(i = stuNum)

{

Cout & lt& lt "The student information you want to delete is:"

show _ Table();

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex<& lt" \t "

& lt& lt record [i]. Score [0] < & lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

cout & lt& ltendl

Cout & lt& ltendl & lt& lt "The deleted student information table is:"

show _ Table();

for(int I = 1; I< = stunum-1; i++)

{

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

for(int j = 0; Number of j< topics; j++)

{

Cout & lt& lt" \ t "<& lt record [i]. score[j];

}

cout & lt& ltendl

}

}

//In the second case, the student to be deleted is not the last one.

If (me! = stuNum)

{

Cout & lt& lt "The student letter information you want to delete is:"

show _ Table();

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex<& lt" \t "

& lt& lt record [i]. Score [0] < & lt" \ t "<& lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

//Move forward one place as a whole.

for(int j = I+ 1; j & lt= stuNumj++)

{

Record [j- 1] = record [j];

}

cout & lt& ltendl

//Then finish the output.

Cout & lt& lt "The deleted student information table is:"

show _ Table();

for(int I = 1; I< = stunum-1; i++)

{

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

for(int j = 0; Number of j< topics; j++)

{

Cout & lt& lt" \ t "<& lt record [i]. score[j];

}

cout & lt& ltendl

}

cout & lt& ltendl

}

}

}

}

*/

void delete_Name(char tarName[])

{

int I;

for(I = 1; I<= stuNumi++)

{

//Deletion will be discussed in two cases.

// 1. The student information to be deleted is the last one.

//2. The student information to be deleted is not the last one.

//When the student to be deleted is the last one, directly output the information of the previous LEN- 1 student.

if(strcmp(record[i])。 name,tarName) == 0)

{

if(i == stuNum)

{

Cout & lt& lt "The student information you want to delete is:"

show _ Table();

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex<& lt" \t "

& lt& lt record [i]. Score [0] < & lt" \ t "<& lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

cout & lt& ltendl

Cout & lt& lt "The deleted student information table is:"

show _ Table();

for(int I = 1; I< = stunum-1; i++)

{

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

for(int j = 0; Number of j< topics; j++)

{

Cout & lt& lt" \ t "<& lt record [i]. score[j];

}

cout & lt& ltendl

}

/*

stuNum-;

Cout & lt& lt "Now only"

cout & lt& ltendl

*/

}

//When the student to be deleted is not the last one, move forward one place as a whole.

If (me! = stuNum)

{

Cout & lt& lt "The student information you want to delete is:"

show _ Table();

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex<< "\ t";

Cout & lt& lt record [i]. Score [0] < & lt" \ t "<& lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

cout & lt& ltendl

//Move forward one place as a whole.

for(int j = I+ 1; j & lt= stuNumj++)

{

Record [j- 1] = record [j];

}

//and then output

cout & lt& ltendl

Cout & lt& lt "The deleted student information table is:"

show _ Table();

for(int I = 1; I< = stunum-1; i++)

{

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

for(int j = 0; Number of j< topics; j++)

{

Cout & lt& lt" \ t "<& lt record [i]. score[j];

}

cout & lt& ltendl

}

/*

stuNum-;

Cout & lt& lt "Now only"

cout & lt& ltendl

*/

}

stuNum-;

Cout & lt& lt "Now only"

cout & lt& ltendl

}

}

}

/*****************************************************************************

******************************************************************************/

//Displays the header information of modifyRecord.

void Info_modify()

{

Cout & lt& lt "Please enter a modification method:"

Cout & lt& lt" 1. Modify according to student number "

Cout & lt& lt"2. Modify by name "

Cout & lt& lt"3. Exit modification "

}

//Inquiring about students' grades, of course, includes two sub-functions.

void modifyRecord()

{

Int key;

cout & lt& ltendl

info _ modify();

Cout & lt& lt "Please enter your choice:";

CIN & gt; & gt key;

//Modify according to the student number

if(key == 1)

{

int targetNum

Cout & lt& lt "Please enter the student ID of the student you want to modify:";

CIN & gt; & gttargetNum

modify _ Num(target Num);

cout & lt& ltendl

//Display ();

}

//Modify by name

if(key == 2)

{

char target name[20];

Cout & lt& lt Please enter the name of the student you want to modify:

CIN & gt; & gttargetName

Modify_Name (target name);

cout & lt& ltendl

//Display ();

}

//Exit modification

if(key == 3)

{

while( 1)

{

menu _ CMD();

}

}

}

//Modify according to the student number

Void modify_Num (integer)

{

int I;

for(I = 1; I<= stuNumi++)

{

If (record [i]. num == tarNum)

{

Cout & lt& ltendl & lt& lt "Please modify this student's information"

Cout & lt& lt "Please enter your student number:";

CIN & gt; & gt record [i]. num

Cout & lt& lt "Please enter the student's name:";

CIN & gt; & gt record [i]. Name;

Cout & lt& lt "Please enter the gender of the student:";

CIN & gt; & gt record [i]. Sex;

Cout & lt& lt "Please enter"

CIN & gt; & gt record [i]. Score [0];

Cout & lt& lt "Please enter"

CIN & gt; & gt record [i]. Score [1];

Cout & lt& lt "Please enter"

CIN & gt; & gt record [i]. Score [2];

}

}

}

//Modify by name

void modify_Name(char tarName[])

{

int I;

for(I = 1; I<= stuNumi++)

{

if(strcmp(record[i])。 name,tarName) == 0)

{

Cout & lt& ltendl & lt& lt "Please modify this student's information:"

Cout & lt& lt "Please enter your student number:";

CIN & gt; & gt record [i]. num

Cout & lt& lt "Please enter the student's name:";

CIN & gt; & gt record [i]. Name;

Cout & lt& lt "Please enter the gender of the student:";

CIN & gt; & gt record [i]. Sex;

Cout & lt& lt "Please enter"

CIN & gt; & gt record [i]. Score [0];

Cout & lt& lt "Please enter"

CIN & gt; & gt record [i]. Score [1];

Cout & lt& lt "Please enter"

CIN & gt; & gt record [i]. Score [2];

}

}

}

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//Displays the header information of queryRecord.

void Info_query()

{

Cout & lt& lt "Please enter a query method:"

Cout & lt& lt" 1. Query by student number "

Cout & lt& lt"2. Query by name "

Cout & lt& lt"3. Exit the query "

}

//query student information queryRecord

void queryRecord()

{

Int key;

cout & lt& ltendl

info _ query();

Cout & lt& lt "Please enter your choice:";

CIN & gt; & gt key;

if(key == 1)

{

int targetNum

Cout & lt& lt "Please enter the student ID of the student you want to query:";

CIN & gt; & gttargetNum

query _ Num(target Num);

cout & lt& ltendl

}

if(key == 2)

{

char target name[20];

Cout & lt& lt "Please enter the student ID of the student you want to query:";

CIN & gt; & gttargetName

query _ Name(target Name);

cout & lt& ltendl

}

//Exit the query and return to the main menu. ...

if(key == 3)

{

while( 1)

{

menu _ CMD();

}

}

}

//Query by Student ID

void query_Num(int tarNum)

{

int I;

for(I = 1; I<= stuNumi++)

{

If (record [i]. num == tarNum)

{

//If there is information about the student in the table, output the information about the student.

//Output students' information.

Cout & lt& lt "Students' information is as follows:"

//Display header information

show _ Table();

//Displays the specific information of students.

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

Cout & lt& lt" \ t "<& lt record [i]. Score [0] < & lt" \ t "<& lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

cout & lt& ltendl

}

}

}

//Query by name

void query_Name(char tarName[])

{

int I;

for(I = 1; I<= stuNumi++)

{

if(strcmp(record[i])。 name,tarName) == 0)

{

Cout & lt& lt "Students' information is as follows:"

show _ Table();

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

Cout & lt& lt" \ t "<& lt record [i]. Score [0] < & lt" \ t "<& lt record [i]. Score [1] < & lt" \ t "<& lt record [i]. Score [2];

cout & lt& ltendl

}

}

}

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//First, display the information of all students.

//Displays the scores of all students in the record.

Empty display ()

{

show _ Table();

int i,j;

for(I = 1; I<= stuNumi++)

{

//cout & lt; & lt "student number" <<" \ t "<& lt" name "

Cout & lt& lt record [i]. Num<& lt" \ t "<& lt record [i]. Name & lt& lt" \ t "<& lt record [i]. Sex;

for(j = 0; Number of j< topics; j++)

{

Cout & lt& lt" \ t "<& lt record [i]. score[j];

}

cout & lt& ltendl

}

cout & lt& ltendl

}

//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////

//Exit

Void exit ()

{

char choi

Cout & lt& lt "Are you sure you want to quit?" & lt& ltendl

Cout & lt& lt "Please enter your choice (Yes/No):";

CIN & gt; & gt Cui;

if((choi == 'Y')||(choi == 'y '))

{

Cout & lt& lt "Quit the student information management system now" < & ltendl

Exit (0);

}

//If not, return to the main interface.

other

{

cout & lt& ltendl

menu _ CMD();

}

}

This is original ... it runs in C-Free 4.0 and works normally.

You can try running, and you can contact me if you have any questions.