# include & ltstdlib.h & gt
# include & ltmalloc.h & gt// Use memory application function malloc () and memory release function free ().
# include & ltstring.h & gt// string processing
# include & ltstdio.h & gt// file operation (reading file)
Structure Address/* Home Address */
{
Char city [10]; /* City */
Char town [10]; /* County */
Char village [10]; /* Township */
};
Structure Phone/* Contact Information */
{
char SJ[50]; /* Mobile phone */
char JD[30]; /* Home Phone */
char XD[30]; /* School Phone */
};
Structural personnel/* Personal information */
{
char name[20]; /* Name */
char sex[ 10]; /* Gender */
Chalmz [16]; /* Nationality */
Chalgj [17]; /* Nationality */
char XL[ 19]; /* Education */
};
Structure score//grade
{
Character number [20]; //Student number
Char English [20];
Char Chinese [20];
char math[20];
Char physics [20];
};
Typedef struct linknode // defines the type of node.
{
Char address [100]; //address
Char's birthday [100]; //Birth date
Structure score sc; //result
Structural person PE; //Personal information
Structural telephone te; //contact information
Boolean sign;
struct linknode * next
} node type;
A list of candidates ranked according to their examination results.
{
nodetype * head
Public:
list();
List::~ List();
link node * creat list(int); //Create a linked list
int listlen(); //Returns the length of the linked list.
nodetype * findnode(int); //Returns the pointer to the node by looking up the serial number.
nodetype * find(char c[]); //Returns a pointer to a node by looking up the name.
int find 2(char c[]); //Returns the serial number of the node by looking up the name.
nodetype * ins node(int); //Insert node
void delnode(int); //Delete node
nodetype * load(); //Initialization: reading data from the outside.
void readstr(FILE *f,char * string); //Read line function
bool check(char *a,char * b); //Compare whether two strings are equal.
void help(); //Display the help menu
void edit person(nodetype *); //Edit personal description
void edit score(nodetype *); //Edit academic performance
void edit phone(nodetype *); //Edit contact information
void dispname(); //Displays the names of all students.
void disp node(nodetype * p); //Displays all the information of a student.
void disp person(nodetype *); //Displays the student's personal description.
void dispscore(nodetype *); //Displays students' academic performance.
void disp phone(nodetype *); //Displays the contact information of the students.
};
Boolllist:: check (char * a, char * b)// Compare whether two strings are equal.
{
int I;
int j = strlen(b);
for(I = 0; I & ltj;; i++)
{
If (*a==*b)
{
a++;
b++;
}
other
Returns 0;
}
Returns1;
}
Nodetype * list:: creatlist (int n)//Create a linked list.
{
nodetype *h=NULL,*s,* t;
int I = 1;
for(int j = 0; j & ltn; j++)
{
If(i== 1) // Create the first node.
{
H= (node type *)malloc(sizeof));
h-& gt; next = NULL
t = h;
}
Otherwise//Create the remaining nodes.
{
s =(nodetype *)malloc(sizeof(nodetype));
s-& gt; next = NULL
t->; next = s;
t = s; //t always points to the last node of the generated single linked list.
}
i++;
}
head = h;
Return to h;
}
void List::readstr(FILE *f,char *string)
{
do
{
//①: Read a line first.
fgets(string,255,f); //fgets (): read a string with the length of 255- 1 from the file F.
//and store it in a string.
} while((string[0]= = '/')| |(string[0]= = ' \ n ');
Return;
}
nodetype* List::load()
{
FILE * fp
nodetype * p;
char c[255];
int num
if((fp=fopen("student.txt "," r ")= = NULL)
{
Cout & lt& lt "Unable to open file"
Returns 0;
}
readstr(fp,c);
Sscanf(c, "Link length: %d", & num); //Get the length of the linked list
p = creat list(num); //Create a linked list
for(int I = 0; I & ltnumi++)
{
readstr(fp,c);
strcpy(p-& gt; Address, c);
readstr(fp,c);
strcpy(p-& gt; Birthday, c);
readstr(fp,c);
strcpy(p-& gt; Serial number, c);
readstr(fp,c);
strcpy(p-& gt; Sc. Chinese, c);
readstr(fp,c);
strcpy(p-& gt; sc.english,c);
readstr(fp,c);
strcpy(p-& gt; sc.math,c);
readstr(fp,c);
strcpy(p-& gt; sc.physics,c);
readstr(fp,c);
strcpy(p-& gt; pe.name,c);
readstr(fp,c);
strcpy(p-& gt; pe.sex,c);
readstr(fp,c);
strcpy(p-& gt; Sports. GJ,c);
readstr(fp,c);
strcpy(p-& gt; Sports. MZ,c);
readstr(fp,c);
strcpy(p-& gt; Sports. XL,c);
readstr(fp,c);
strcpy(p-& gt; te。 SJ,c);
readstr(fp,c);
strcpy(p-& gt; te。 JD,c);
readstr(fp,c);
strcpy(p-& gt; te。 XD,c);
p = p-& gt; Next;
}
fclose(FP);
Return p;
}
Voidlist:: dispnode (nodetype * p)//Displays all the information of a student.
{
If (p! = empty)
{
disp person(p);
disp score(p);
disp phone(p);
}
}
Void List::dispname() // Displays the names of all students.
{
nodetype * p = head
Cout & lt& lt "Existing students:"
if(p==NULL)
Cout & lt& lt "No student data"
And (p! = empty)
{
Cout & lt& lt "Name:"
p = p-& gt; Next;
}
}
Int List::listlen() // Returns the length of the linked list.
{
int I = 0;
nodetype * p = head
And (p! = empty)
{
p = p-& gt; Next;
i++;
}
Return I;
}
Nodetype * list:: findnode (int I)//Returns the pointer of the node by looking up the serial number.
{
nodetype * p = head
int j = 1;
If (I & gtlistlen () || I <; =0) // i Overflow or Underflow
Returns NULL
other
{
And (p! = NULL & amp& ampj & ltI) // Find the i-th node and point to it with p.
{
j++;
p = p-& gt; Next;
}
Return p;
}
}
Nodetype* List::find(char c[]) // Returns a pointer to the node by looking up the name.
{
nodetype * p = head
int j = 1;
strcat(c," \ n "); //All externally read strings have a line break at the end.
And (p! = NULL & amp& amp! (check (c, p-> Sports. Name))///Find the i-th node and point to it with p.
{
j++;
p = p-& gt; Next;
}
Return p;
}
Int List::find2(char c[]) // Returns the serial number of the node by looking up the name.
{
nodetype * p = head
int j = 1;
strcat(c," \ n "); //All externally read strings have a line break at the end.
And (p! = NULL & amp& amp! (check (c, p-> Sports. Name))///Find the i-th node and point to it with p.
{
j++;
p = p-& gt; Next;
}
Return j;
}
nodetype* List::insnode(int i)
{
nodetype *h=head,*p,* s;
s =(nodetype *)malloc(sizeof(nodetype)); //Create a node
s-& gt; next = NULL
If (i==0) //i=0, s is the first node of the linked list.
{
s-& gt; next = h;
h = s; //Redefine the head node
}
other
{
p = findnode(I); //find the i-th node and point to it with p.
If (p! = empty)
{
s-& gt; next = p-& gt; Next;
p->; next = s;
}
Else cout & lt& lt "Incorrect I value entered"
}
head = h;
Return to s;
}
Void List::delnode(int i) // Delete the ith node.
{
Nodetype * h = head, * p = head, * s;;
int j = 1;
If(i== 1) // Delete the first node.
{
h = h-& gt; Next;
Free (p);
}
other
{
p = findnode(I- 1); //Find the I- 1 th node, and p points to this node.
If (p! = NULL & amp& ampp->; Au Suivant! = empty)
{
s = p-& gt; Next; // s points to the node to be deleted.
p->; next = s-& gt; Next;
Free;
}
other
Cout & lt& lt "Incorrect I value entered"
}
head = h;
}
void List::edit person(nodetype * p)
{
char c[ 100];
Cout & lt& lt "Please enter a name:"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; pe.name,c);
Cout & lt& lt "Please enter gender:"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; pe.sex,c);
Cout & lt& lt "Please enter the date of birth (for example:1982-1-1):" < < endl
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; Birthday, c);
Cout & lt& lt "Please enter nationality:"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; Sports. MZ,c);
Cout & lt& lt "Please enter nationality:"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; Sports. GJ,c);
Cout & lt& lt Please enter education level: "< & ltendl"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; Sports. XL,c);
Cout & lt& lt "Please enter your home address (for example, Jiefang Road, Yulin City, Guangxi 1 1)" < & ltendl
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; Address, c);
Cout & lt& lt "Personal information editing completed!" & lt& ltendl
disp person(p);
}
void List::editscore(nodetype* p)
{
char a[50];
Cout & lt& lt "Please enter your student number:"
CIN & gt; & gta;
strcat(a," \ n ");
strcpy(p-& gt; sc.num,a);
Cout & lt& lt "Please enter a language score:"
CIN & gt; & gta;
strcat(a," \ n ");
strcpy(p-& gt; Sc. Chinese, a);
Cout & lt& lt "Please enter your English score:"
CIN & gt; & gta;
strcat(a," \ n ");
strcpy(p-& gt; sc.english,a);
Cout & lt& lt "Please enter your math score:"
CIN & gt; & gta;
strcat(a," \ n ");
strcpy(p-& gt; sc.math,a);
Cout & lt& lt "Please enter your physics score:"
CIN & gt; & gta;
strcat(a," \ n ");
strcpy(p-& gt; Science physics a);
Cout & lt& lt "Editing subject scores is complete!" & lt& ltendl
disp score(p);
}
void List::edit telephone(nodetype * p)
{
char c[50];
Cout & lt& lt "Please enter your mobile phone number:"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; te。 SJ,c);
Cout & lt& lt "Please enter your home phone number:"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; te。 JD,c);
Cout & lt& lt "Please enter the school phone number:"
CIN & gt; & gtc;
strcat(c," \ n ");
strcpy(p-& gt; te。 XD,c);
Cout & lt& lt "Editing contact information is complete!" & lt& ltendl
disp phone(p);
}
void List::disp person(nodetype * p)
{
Cout & lt& lt "Name:"
Cout & lt& lt "Gender:"
Cout & lt& lt "Nationality:"
Cout & lt& lt "Nationality:"
Cout & lt& lt "Education:"
Cout & lt& lt "Date of birth:"
Cout & lt& lt "Home Address:"
}
void List::dispscore(nodetype* p)
{
Cout & lt& lt "Student ID:"
Cout & lt& lt "China's achievements:"
Cout & lt& lt "English scores:" <<P->; Sc. English;
Cout & lt& lt "Math scores:"
Cout & lt& lt "Physics scores:"
}
void List::disp phone(nodetype * p)
{
Cout & lt& lt "The mobile phone number is:"
Cout & lt& lt "Home phone number is"
Cout & lt& lt "What's the phone number of the school?"
}
void List::help()
{
cout & lt& ltendl & lt& ltendl
cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * & lt; & ltendl
Cout & lt& lt" 1: Edit Personal Information "
Cout & lt& lt"2. Editing academic achievements "
Cout & lt& lt" 3: Edit contact information "
Cout & lt& lt" 4: Show Personal Information "
Cout & lt< "5: Showing Academic Achievements"
Cout & lt& lt" 6: Show contact information "
Cout & lt& lt" 7: Show all the information of this student "
Cout & lt& lt" 8: Help Menu "
Cout & lt& lt" 9: Return to the previous menu "
cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * & lt; & ltendl
}
List:: ~ List ()
{
nodetype *pa=head,* pb
If (bang! = empty)
{
Pb = pa-& gt; Next;
if(pb==NULL)
Free (PA);
other
{
And (pb! = empty)
{
Free (PA);
pa = pb
Pb = p B- & gt; Next;
}
Free (PA);
}
}
}
Class operator
{
List l1;
Public:
void Loop(); //main loop
Void display (); //Display menu
};
List::List()
{
head = NULL
}
Void operator:: display ()
{
cout & lt& ltendl & lt& ltendl
cout & lt& lt"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
Cout & lt& lt" 1: Add a student information "
Cout & lt& lt" 2: Delete student information "
Cout & lt& lt" 3: Show the names of all students "
Cout & lt& lt" 4: Show all the information of a single student by name "
Cout & lt& lt" 5: Edit individual students by name "
Cout & lt& lt" 6: Help Menu "
Cout & lt& lt" 7: Save data "
Cout & lt& lt" 0: Exit the system "
cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *”& lt; & ltendl
}
Void operator:: Loop ()
{
List l1; //List object
char ch[20];
nodetype *p,* head
int I; //Store the node serial number
p = l 1 . load(); //Initialization: read data from the outside and create a linked list.
head = p;
Display ();
while( 1)
{
cout & lt& ltendl & lt& ltendl
Cout & lt& lt "Please enter an option (Help Options-> 6):" & lt; & ltendl
CIN & gt; & gtch;
////system(" cls ");
if(L 1.check(ch," 1 "))
{
p = l 1 . ins node(0);
head = p;
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * student information * * * * * * * * * * * * * * * *”<<;; endl
Cout & lt& lt "Enter your personal information below:"
l 1 . edit person(p);
Cout & lt& lt "Enter the subject score below:"
l 1 . edit score(p);
Cout & lt& lt "Enter the contact information below:"
l 1 . edit phone(p);
}
if(L 1.check(ch," 2 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * Delete a student information * * * * * * * * * * * * * * * *”<<;; endl
l 1 . dispname();
Cout & lt& lt "Please enter the student's name:"
CIN & gt; & gtch;
I = l 1 . find 2(ch);
l 1 . del node(I);
}
if(L 1.check(ch," 3 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt* * * * * * * * * * * * * * * * the names of all students * * * * * * * * * *
l 1 . dispname();
}
if(L 1.check(ch," 4 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * Displays all the information of a single student by name * * * * * * * * * * * * * * < < endl
l 1 . dispname();
Cout & lt& lt "Please enter the student's name:"
CIN & gt; & gtch;
p = l 1 . find(ch);
l 1 . disp node(p);
}
if(L 1.check(ch," 6 "))
{
Display ();
}
If(L 1.check(ch, "7))// Save the data.
{
FILE * fp
if((fp=fopen("student.txt "," w ")= = NULL)
{
Cout & lt& lt "Unable to open file"
Return;
}
int I;
char t[255];
//Assign L 1.listlen () to the number in the string.
Sprintf(t, "Link length: %d\n", l1.listlen ());
fputs(t,FP);
strcpy(t," \ n ");
fputs(t,FP);
p = l 1 . findnode( 1); //point the pointer to the head of the linked list to p.
for(I = 0; I<L1.listlen (); i++)
{
fputs(p-& gt; Address, FP); //output address
fputs(p-& gt; Birthday, FP); //output birthday
fputs(p-& gt; sc.num,FP); //output student number
fputs(p-& gt; sc.chinese,FP); //Output the language score
fputs(p-& gt; sc.english,FP); //Output English scores
fputs(p-& gt; sc.math,FP); //output math scores
fputs(p-& gt; sc.physics,FP); //output physics scores
fputs(p-& gt; pe.name,FP); //output name
fputs(p-& gt; pe.sex,FP); //Output gender
fputs(p-& gt; Sports. GJ,FP); //Export nationality
fputs(p-& gt; Sports. MZ,FP); //Export nationality
fputs(p-& gt; Sports. XL,FP); //Output academic qualifications
fputs(p-& gt; te。 SJ,FP); //Output mobile phone
fputs(p-& gt; te。 JD,FP); //Output residential phone
fputs(p-& gt; te。 XD,FP); //output the school phone number
fputs(t,FP);
p = p-& gt; Next;
}
P = head;
fclose(FP);
}
if(L 1.check(ch," 5 "))
{
char c[20];
//system(" cls ");
cout & lt& ltendl
Cout & lt< "* * * * * * * * * Edit individual students according to their names * * * * * * * * * * * * * * * *" <; & ltendl
l 1 . dispname();
Cout & lt& lt "Please enter the student's name:"
CIN & gt; & gtc;
p = l 1 . find(c);
//system(" cls ");
cout & lt& ltendl & lt& ltendl
cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * & lt; & ltendl
Cout & lt& lt" 1: Edit Personal Information "
Cout & lt& lt"2. Editing academic achievements "
Cout & lt& lt" 3: Edit contact information "
Cout & lt& lt" 4: Show Personal Information "
Cout & lt< "5: Showing Academic Achievements"
Cout & lt& lt" 6: Show contact information "
Cout & lt& lt" 7: Show all the information of this student "
Cout & lt& lt" 8: Help Menu "
Cout & lt& lt" 9: Return to the previous menu "
cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * & lt; & ltendl
while( 1)
{
cout & lt& ltendl & lt& ltendl
Cout & lt& lt "Please enter an option (Help Options-> 8):" & lt; & ltendl
CIN & gt; & gtc;
//system(" cls ");
if(L 1.check(c," 1 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt< "* * * * * * * * * * Edit personal information * * * * * * * * * * * * * * * <<;; endl
l 1 . edit person(p);
}
else if(L 1.check(c," 2 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * * * * * Academic achievements of editorial department * * * * * * * * * "< < endl
l 1 . edit score(p);
}
else if(L 1.check(c," 3 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * contact information of editor * * * * * * * * * * * "< < endl
l 1 . edit phone(p);
}
else if(L 1.check(c," 4 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * Display personal information * * * * * * * * * * * * "
l 1 . disp person(p);
}
else if(L 1.check(c," 5 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <<;; endl
l 1 . disp score(p);
}
else if(L 1.check(c," 6 "))
{
//system(" cls ");
cout & lt& ltendl
Cout & lt& lt“* * * * * * * * * * * * * * * * * * the contact information * * * * * * * * * * * * * *”<<;; endl
l 1 . disp phone(p);
}
else if(L 1.check(c," 7 "))
{
//system(" cls ");
l 1 . disp node(p);
}
else if(L 1.check(c," 8 "))
{
//system(" cls ");
l 1 . help();
}
else if(L 1.check(c," 9 "))
{
Display ();
Break; //Use break to jump out of this loop without returning, which means quitting the program.
}
}
}
else if(L 1.check(ch," 0 "))
Return;
}
Return;
}
int main()
{
System ("color 3a");
Operator chp
Cogeneration of heat and power. loop();
Returns 0;
}
It will definitely work.