Address book management system - simple version
1, Design requirements
Program design format requirements are as follows:
(1) It is required to implement the design in a multi text way.
(2) It is required to implement structured design in each document.
(3) Each module is treated as a separate C file.
(4) Each function of the system is realized in the form of function call.
(5) Macros and data structures are placed in header files and compiled using conditions.
(6) Friendly interface (good man-machine interaction), and the program shall be annotated.
Complete a student achievement management system. The specific requirements are as follows:
1. Establish address book information, which at least includes number, name, age, telephone, mailing address, e-mail, etc
2. It can add, delete and modify address book information
3. It can provide the function of querying in different ways; Such as inquiry by name or age, telephone, etc
4. Save the address book in a file
5. Be able to output address book information in tabular form
6. Exit the program
2, Outline design
1. Data structure design
Define a structure type address_list. The structure contains name, student number, number, mobile phone number, email and address, as well as a pointer to the next person's information. There are 7 structure members in total.
struct address_list { char name[30]; //name char age[30]; //birthday int number; //number char handset1[30]; //Mobile 1 char handset2[30];//Mobile 2 char email[30]; //E-mail char address[30]; //postal address struct address_list *next; };
2. Function description and calling relationship
According to the function module division, the functions required by the address book management system and the function description of each function are shown in the table below.
Function name | Function description |
---|---|
void print() | Create a function to create a linked list without leading nodes |
void add() | Output function, tabular output of address book information |
void delet() | Add function and add address book information |
void order() | Delete function, delete redundant person information |
void search() | The display function displays the required information in a single surface grid |
void renew() | Sort function to sort the address book information according to the name size |
void out() | Find function to find the required information in the specified way |
void set() | Create user function to create a new user |
void enter() | Enter the system function, which is used to enter the management system |
void person() | System interface function, menu interface of management system |
3. Disk file
There's only one file here, Is the file that holds our user name and password (Jilu. Txt); it should be noted that this address book system is not divided into administrators and users, but its characteristic function is to register user names and passwords by ourselves. The jilu.txt file here is used to save our user names and passwords; in addition, it does not mean that our program has only this file, but we need to know this file because it When we create a user, the program has automatically generated the corresponding file.
3, Detailed design
1. Log in to the system
The execution of the system starts from the menu of logging in to the system, allowing the user to enter a value between 1 and 3 to select the operation to be performed.
The treatment process is as follows:
- If the user enters 1, the user will log in. The user needs to enter the correct account and password before entering the address book management system;
- If the user enters 2, the user will be created. The user can create a new account password. The contacts in different accounts and address books are different and set by different users;
- If the user enters 3, he will exit the login system;
- If you enter other numbers, characters or strings, the system will give an error prompt and re select.
The processing flow of login system is shown in the figure below.
2. Address book management system
After entering the correct account and password from the login interface, the user will enter the personal address book management system, which allows the user to enter different numbers between 1 and 7 for corresponding operations.
The treatment process is as follows:
- If the user enters 1, the information of the existing contacts in the address book will be displayed;
- If the user enters 2, the contact will be added; You can enter the information of the added contact, including name, date of birth, phone 1, phone 2, email and address. When entering the phone, the system will detect whether the phone is a valid 11 digit Arabic numeral. If the contact has no phone 2, you can enter the next item without entering.
- If the user enters 3, the contact will be searched. The search operation includes accurate search and fuzzy search. You can enter the mobile phone number and name respectively for accurate search or fuzzy search;
- If the user enters 4, the system will sort the names of the contacts in the address book from short to long, and output the sorted address book content;
- If the user enters 5, the information will be modified, in which the mobile phone number and address can be modified;
- If the user enters 6, the information will be deleted. Enter the name of the person to be deleted, and the contact information will be cleared;
- If the user enters 7, the whole system will exit;
- If you enter other numbers, characters or strings, the system will give an error prompt and re select;
The processing flow of the address book management system is shown in the figure below.
3. Find the operation module
Module function: when the user enters 3 in the management system interface, enter the search information module. After entering the submenu, carry out a variety of detailed operations.
The treatment process is as follows:
- After selecting the search operation, the user will enter the next submenu and select again to select accurate search or fuzzy search;
- After selecting the exact search, the user will enter the selection again, phone 1, phone 2, or name search;
- After selecting fuzzy search, the user will enter the selection again, phone 1, phone 2, or name search;
- After searching, the user can choose to exit and return to the initial menu interface for other required operations;
The processing flow of the search operation module is shown in the figure below.
4. Modify information module
When the user enters 5, it will enter the modify information operation menu, which allows the user to enter a value between 1 and 4 for corresponding operation.
The treatment process is as follows:
- If the user enters 1, the mobile phone number 1 can be modified. After entering, enter the name of the modified contact according to the prompt, and then enter the modified mobile phone number 1 to complete the modification operation;
- If the user enters 2, the mobile phone number 2 can be modified. After entering, enter the name of the modified contact according to the prompt, and then enter the modified mobile phone number 2 to complete the modification operation;
- If the user enters 3, the address can be modified. After entering, enter the name of the modified contact according to the prompt, and then enter the modified address to complete the modification operation;
- If the user enters 4, it will return to the previous interface;
- If you enter other numbers, characters or strings, the system will give an error prompt and re select;
The processing flow of modifying the information module is shown in the figure below.
4, Description of improved and added modules
1. Sorting module
The sorting module can sort the information in the address book according to the alphabetical order of the contact name, then store and output it; When there are a large number of contacts, you can sort the address book and output it to view the information in the address book. In this way, it is easier to find the information of the contact you want to find. The code is as follows.
void order() { FILE *fp; int z,i,j; struct stu { char name[30]; char age[30]; int number; char handset1[30]; char handset2[30]; char email[30]; char address[30]; }; struct address_list *p,*last; struct stu temp,s[200]; p=(struct address_list *)malloc(sizeof(struct address_list)); last=p; fp=fopen(pp,"r");//open if(fp==NULL) { printf("can not open!\n"); return ; } i=0; while(fread(p,LEN,1,fp)) { strcpy(s[i].name,p->name); strcpy(s[i].age,p->age); s[i].number=p->number; strcpy(s[i].handset1,p->handset1); strcpy(s[i].handset2,p->handset2); strcpy(s[i].email,p->email); strcpy(s[i].address,p->address); i++; } z=i; for(i=0;i<z-1;i++) { for(j=i+1;j<z;j++) { if('s[i].name'>'s[j].name')>0) { temp=s[i]; s[i]=s[j]; s[j]=temp; } } } fclose(fp); //close fp=fopen(pp,"w"); //open for(i=0;i<z;i++) { strcpy(p->name,s[i].name); strcpy(p->age,s[i].age); p->number=s[i].number; strcpy(p->handset1,s[i].handset1); strcpy(p->handset2,s[i].handset2); strcpy(p->email,s[i].email); strcpy(p->address,s[i].address); fwrite(p,LEN,1,fp); } fclose(fp); printf("=*=*=*=*=*=*=*=*=\n"); printf(" The sorted information is as follows:\n"); printf("=*=*=*=*=*=*=*=*=\n"); print(); }
2. In the menu option, the user enters a number for selection, and an error will be reported if an illegal character is entered
For example, under the query menu, there are three submenu items waiting for the user to select, and the code is as follows.
void search() { ...//The source code is long, and part of the code is omitted here ... ... printf(" ┌──────────┐\n"); printf(" │1 Exact search│\n"); printf(" │2 fuzzy search│\n"); printf(" │3 sign out │\n"); printf(" └──────────┘"); printf("\n"); printf("=*=*=*=*=*=*=*=*=\n"); printf(" Please enter your action:\n"); printf("=*=*=*=*=*=*=*=*=\n"); printf("\n"); gets(str); printf("\n"); if(strlen(str)>1) { printf("=*=*=*=*=*=\n"); printf("Operation error!\n"); printf("=*=*=*=*=*=\n"); printf("\n"); continue; } switch(*str) { case '1': ....;break; case '2': ....;break; case '3': ....;break; default :printf("Operation error!\n");break; } ... ... ...//The source code is long, and part of the code is omitted here }
3. Optimize the interface of output information
The output information is output in the form of table, so that the output interface looks clearer and the user experience is more comfortable. The code is as follows.
void print() { FILE *fp; int n=0; struct address_list *p,*head,*last; p=(struct address_list *)malloc(LEN); { head=p; last=p; } fp=fopen(pp,"r"); if(fp==NULL) { fp=fopen(pp,"w"); printf("Address book does not exist!An address book has been recreated!\n"); //return ; } while(fread(p,LEN,1,fp)) { n++; p->number=n; if(n==1) { printf("================================================================================================\n"); printf("|full name |birthday |number |Mobile number 1 |Mobile number 2 |mailbox |address |\n"); } printf("------------------------------------------------------------------------------------------------\n"); printf("|%-12s|%-13s|%-6d|%-14s|%-14s|%-19s|%-10s|\n",p->name,p->age,p->number,p->handset1,p->handset2,p->email,p->address); } if(n!=0) printf("================================================================================================\n"); } ...//The source code is long, and part of the code is omitted here ... ... fclose(fp); }
4. Add login and account creation
The system adopts the method of account and password login, which enhances the universality of the system in different situations, facilitates the address book added by multiple people, and uses the method of creating user to create address book for different users. The account and password of the user and the address book file will be saved in the file, and the code is as follows.
void est() //Create user { FILE *fp,*Fp; int flag=1; struct person *p; char Number[30],Key[30]; p=(struct person *)malloc(sizeof(struct person)); fp=fopen("jilu.txt","r"); if(fp==NULL) { printf("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n"); printf(" The user directory file does not exist and has been recreated.\n"); printf("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n"); printf("\n"); printf("=*=*=*=*=*=*=*=*=\n"); printf(" Please re create the user\n"); printf("=*=*=*=*=*=*=*=*=\n"); printf("\n"); fp=fopen("jilu.txt","w"); fclose(fp); return ; } printf("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n"); printf(" Please set a new user name:(Please enter English characters)\n"); printf("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n"); printf("\n"); gets(Number); printf("\n"); printf("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n"); printf(" Please set user password:(English and figures only)\n"); printf("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n"); printf("\n"); gets(Key); printf("\n"); ...//The source code is long, and part of the code is omitted here ... ... } }
5, Program test
1. Test whether the system can correctly display login options
After executing the program, the interface is shown in the figure below, which shows the login options of the system.
2. Test whether the system can create users
Enter the following data:
User name: mye password: 12345
After entering the given account and password, the system will prompt that the creation is successful. As shown in the figure below.
3. Test whether the program can use the created user to enter the system
According to the given account and password, enter the account login interface, enter the account and password, as shown in the figure below, and the system will prompt you to successfully enter the address book management system.
4. Test whether the system can correctly input contact information
test data
Name: zhangsan
Birthday: January 1, 1998
Mobile number 1: 12345654321
Mobile 2: 12345676543
email: 123@163.com
Address: Anyang
Enter the given contact information into the address book, as shown in the figure below.
5. Test whether the system can correctly display contact information
Enter the number 1 in the main menu interface to display, and the display results are shown in the figure below.
6. Test whether the system can correctly find contact information (take name search as an example)
Enter the number 3 in the main menu interface to enter the search interface, and test the accurate search and fuzzy search in turn. The results are shown in the figure below.
7. Test whether the system can be sorted correctly
Enter the number 4 in the main menu interface to enter the sorting interface, and the output after sorting is shown in the figure below.
8. Test whether the system can correctly modify the address book information (take modifying the telephone as an example)
Enter the number 5 in the main menu to enter the modification information interface, select Modify phone 1, and modify zhangsan's phone 1 to 18637621756. The results are shown in the following figure.
9. Test whether the system can delete contact information
Enter the number 6 in the main menu interface to enter the deletion operation and delete the information of lisi. The interface is shown in the following figure.
10. Can the test program exit
Enter 7 in the main menu to exit the whole address book management system, as shown in the figure below.