1. Experimental Purpose
1) Familiarize yourself with and master the logical and physical structure of linear tables;
2) Familiarize yourself with and master the storage structure, basic operations and definitions of specific functions of linear chained lists;
II. EXPERIMENTAL CONTENTS
Design a main menu program with multiple menu items, and then add functions to these menu items to manage all operations of the address book.
1) Establishment of address book list.
2) Insertion of Communicator Information
3) Find the information of the communicator, find it successfully, and output the information of the finder.
4) Deletion of the communicator record requires that the communicator's search be carried out first, and that the deletion be determined after the search is successful. Delete function is not implemented until it is determined.
5) Correspondent information modification, first enter the key information of the communicator for query (such as number, ID number, name, etc.), find out to modify, find out to return no such information;
6) Display the address list lists, which output all the communicator's information in numbered order.
3. EXPERIMENTAL STEPS
1) Define single-chain lists;
2) Initial list of chains;
3) Define the main function to implement the address book menu;
Define the insert address book information function;
Define a query address book information function;
Define the Delete Address Book Information function;
Define the modify address book information function.
4. Algorithmic flowchart
Flowchart 1
Flowchart 2
Flowchart 3
5. Implementation Code
#include "stdio.h" #include "string.h" #include "stdlib.h" #define N 100 typedef struct{ //Address Book node type, should contain, number, name, contact method, address and other information char num[N];//number char name[N];//Full name char phone[N];//Phone number char add[N];//address }DataType; typedef struct node { //Node Type Definition - Single Chain Table (Data Domain, Pointer Domain) DataType data; struct node *next; }ListNode,*LinkList; typedef ListNode *LinkList; //Define Single Chain List LinkList head; ListNode *p; void CreateList(LinkList &L){ //An Address Book Chain List Algorithm with Head Nodes by End Interpolation int i,n; L=(LinkList)malloc(sizeof(ListNode)); ListNode *p,*q=L; printf("Please enter the number of employees:"); scanf("%d",&n); for (i=1;i<=n;i++){ p=(LinkList)malloc(sizeof(ListNode)); printf("Please enter #%d Employee information:\n",i); printf("Number:");//Input Element Value scanf("%s",p->data.num); printf("Full name:"); scanf("%s",p->data.name); printf("Contact information:"); scanf("%s",p->data.phone); printf("Postal address:"); scanf("%s",p->data.add); p->next=q->next; q->next=p; q=p; } q->next=NULL; } void InsertNode(LinkList &head)//Insert employee information { ListNode *p,*q; q=head->next; p=new ListNode[sizeof(ListNode)];//Create a new node printf("Please enter employee information to insert:\n"); printf("Number:"); scanf("%s",p->data.num); while (q){ if (strcmp(q->data.num,p->data.num)==0){ printf("The employee already exists!"); break ; } q=q->next; } if (q==NULL){ printf("Full name:"); scanf("%s",p->data.name); printf("Contact information:"); scanf("%s",p->data.phone); printf("Postal address:"); scanf("%s",p->data.add); p->next=head->next; head->next=p; } } void revise(LinkList &head)//Modify employee information { ListNode *p; p=head->next; int k=0; char num1[N]; printf("Enter the number of the employee that needs to be modified:"); scanf("%s",&num1); while(p){ if (strcmp(p->data.num,num1)==0){ k=1; break; } p=p->next; } if (k){ printf("Please enter the modified employee information:\n"); printf("Full name:"); scanf("%s",p->data.name); printf("Contact information:"); scanf("%s",p->data.phone); printf("Postal address:"); scanf("%s",p->data.add); }else{ printf("Numbered as%s No employees exist!\n",num1); } } void PrintList(LinkList &head) //Output Chain List { ListNode P; p=head->next; printf("number\t Full name\t Contact information\t Postal address\n"); while (p){ printf("%s\t",p->data.num); printf("%s\t",p->data.name); printf("%s\t\t",p->data.phone); printf("%s",p->data.add); printf("\n"); p=p->next; } } void ListFind1(LinkList head) {// Lookup on Ordered Address List Chain List ListNode *p; int op; char num1[N],name1[N]; p=head->next; int k=0; printf("==================\n"); printf(" 1. Query by number \n"); printf(" 2. Query by name \n"); printf("==================\n"); printf("Please select:"); scanf("%d",&op); switch (op){ case 1:{ printf("Enter the employee number you want to find:"); scanf("%s",&num1); while (p){ if (strcmp(p->data.num,num1)==0){ k=1; break; } p=p->next; } if (k){ printf("Number:%s\n",p->data.num); printf("Full name:%s\n",p->data.name); printf("Contact information:%s\n",p->data.phone); printf("Postal address:%s\n",p->data.add); printf("\n"); } else{ printf("Numbered as%s No employees exist!\n",num1); } break; } case 2:{ printf("Enter the name of the employee you want to find:"); scanf("%s",&name1); while (p){ if (strcmp(p->data.name,name1)==0){ k=1; break; } p=p->next; } if (k){ printf("Number:%s\n",p->data.num); printf("Full name:%s\n",p->data.name); printf("Contact information:%s\n",p->data.phone); printf("Postal address:%s\n",p->data.add); printf("\n"); } else{ printf("Name is%s No employees exist!\n",name1); } break; } } } void DelNode(LinkList &head) { ListNode *p=head->next; ListNode *q=head; int op; char a; char num1[N],name1[N]; p=head->next; printf("==================\n"); printf(" 1. Query by number \n"); printf(" 2. Query by name \n"); printf("==================\n"); printf("Please select:"); scanf("%d",&op); switch (op){ case 1:{ printf("Please enter the employee number that needs to be deleted:"); scanf("%s",&num1); while (p&&strcmp(p->data.num,num1)!=0){ p=p->next; q=q->next; } if (p==NULL) { printf("No communicators found to delete!\n"); break ; } if (p){ printf("Do you really want to delete this employee? ( y/n):\n"); //To be continued... printf("Please select:"); scanf("%s",&a); if (a=='y'){ printf("Delete successful!"); q->next=p->next; free(p); } } else if(a=='n') break ; break; } case 2:{ printf("Enter the name of the employee you want to delete:"); scanf("%s",&name1); while (p&&strcmp(p->data.name,name1)!=0){ p=p->next; q=q->next; } if (p==NULL) { printf("No communicators found to delete!\n"); break ; } if (p){ printf("Do you really want to delete this employee? ( y/n):\n"); //To be continued... printf("Please select:"); scanf("%s",&a); if (a=='y'){ printf("Delete successful!"); q->next=p->next; free(p); } } else if(a=='n') break ; break; } } } //Principal function int main() { //Good menu bootstrapper function //Such as 1: establishment; 2: Add; 3: Query; 4 Delete; 5: Modify; 6: Display; 0: Exit; LinkList L; int op; printf("**************Mail list*************\n"); printf("\t1,Establish employee information\n\t2,Add employee information\n\t3,Query employee information\n\t4,Delete employee information\n\t5,Modify employee information\n\t6,show address book\n\t0,Exit System\n"); printf("**********************************\n"); while (1){ printf("Please select the appropriate function:"); scanf("%d",&op); if (op==0) break; switch (op){ case 1:{ CreateList(L); printf("\n"); break; } case 2:{ InsertNode(L); printf("\n"); break; } case 3:{ ListFind1(L); printf("\n"); break; } case 4:{ DelNode(L); printf("\n"); break; } case 5:{ revise(L); printf("\n"); break; } case 6:{ PrintList(L); printf("\n"); break; } } } return 0; }
6. Operation results and analysis
1. Establish employee information (verify successful establishment of employee information)
Figure 1 establishes employee information
Figure 2 shows the address book
2. Query employee information (by number or name)
If you enter a nonexistent employee number or name, the output employee does not exist.
Figure 3 Find employee information by number
Figure 4 Find employee information by name
If the entered employee number or name exists, output the corresponding employee information
Figure 5
Figure 6
3. Delete employee information (delete by number or name)
If you enter a nonexistent employee number or name, the output employee does not exist.
7 Delete employee information by number
Figure 8 Find employee information by name
Delete employee information if the entered employee number or name exists
(You will also be asked if you really want to delete the employee (y/n) before deleting, if you select y, delete the employee, and if you enter n, exit the deletion system)
Figure 9
Figure 10
The corresponding employee has been tested and removed.
Figure 11
4. Add employee information
If the employee number entered already exists, the output employee already exists.
Figure 12
If the input employee number does not repeat, add the employee information (verified that the employee has added)
Figure 13
5. Modify employee information
1. If the input employee number does not exist, the output employee does not exist.
2. If the input employee number exists, enter the employee information that needs to be modified (verify that the employee information was modified successfully)
Figure 14
6. Exit Employee Information Management System
Fig. 15