Comprehensive experiment 1:Application of linear list
One. Experimental target
1、Use the basic operations to implement the specific operations for the linear table;
2、Master the application of file operations;
3、Improve the understanding of the data structure of linked storage structure, and gradually cultivate the programming ability to solve practical problems.
Two. Experimental environment
A computer with Visual Studio.
This experiment has 4 class hours in all.
Three. Experiment content
1. address list design
Design a classmate’s address list, requested as follows:
Each student in the address list contains the following information: student id、name、telephone number. If you need more fields, please add them yourself.
The program has a main menu containing the following functions:
(1) Add a record: Add a student record from the input.
(2) Delete a record: Delete a student record according to the student id from the input.
(3) Output all records: Display all the records in the address list.
(4) Search by name: Input the student name and then output the whole information of the student.
(5) Save records: Save all the records in the address list to a certain file.
(6) Clear records: Delete all the records in the address list and then delete the file.
(7) Quit
hint**:**
When the program starts, it should be determined whether there is a record file. If the file exists, read each record from it to the list.
After the user selects and completes a function of the main menu, the program should return to the main menu.
When a record is added, it should be inserted into the tail of the list.
If a record does not exist when performing delete or and search operation, the program should output some information to the user.
You do not need to write files when adding records or deleting records.
When you want to save a record you’d better overwrite the file. (Or delete the original file first, and then save all the records)
Each module is written in the form of a function, called by the main function.
optional**:**
Add a sorting function in the main menu, the sorting result should be in an ascending order according to the student number. Sorting methods can be done by bubble sort or insert sort.
Four.Important data structures
Important data structures: the structure of linked lists
typedef struct stu {
int id; //id storage student ID
char name[20]; //storage student name
int tel; //storage student telephone
stu *next; //Link to the next node
}stu;
Function Main Function and Query
cout << "|*----------1:Create a large number of contacts-*|\
|*----------2:Insert a data---------------------*|\
|*----------3:Detele the data-------------------*|\
|*----------4:Disply all the Mail list----------*|\
|*----------5:Store to the file-----------------*|\
|*----------6:Clear the file--------------------*|\
|*----------7:Accurate search-------------------*|\
|*----------8:rough search----------------------*|\
|*----------0:exit------------------------------*|" << endl;
The main operation of address book function
stu*Create(); // Bulk creation of data nodes
stu*Insert_(stu*head, stu*p); // Insert data nodes
stu*Delete_(stu*head, int id); // Delete data nodes
stu*Display_(stu*head); // Show all nodes
stu*Find_(stu*head, char name[]); // Find the required nodes by name
stu*Rough(stu*head, char name[]); // Rough search, keyword search stu*Store_(stu*head); // Store in a file
stu*Clear_(stu*head); // Clear Nodes and Delete Files
int check_data(stu*head, int id, char name[], int tel);//Find out if there is duplicate data, and if there is duplicate data, it will not be stored in the table.