Training project - personal information management system
preface
This blog records the training project summary of rookie (I @~@) at the end of freshman year. It has been approved by the project team members before publication. Please keep the statement for reprint. Thank you.
The main purpose of the project is to strengthen the ability of data structure code (C language version), improve teamwork ability and increase project experience. If it is inappropriate, please give advice
1, Preliminary preparation
1. Compile software installation
Dev-C + + in Windows environment is used in this training project. The training teacher recommends cross platform CLion, but for various reasons, the familiar IDE in the team has not been changed. Dev-C + + is provided here Official website download address
two. Basic technical mastery
two.1 information storage
2.1.1 temporary storage
In the temporary storage, because the number of elements changes greatly and the information entered by the user does not know how much, it is obvious that there are a large number of operation demo s for the linked list in this system. One of the advantages of the linked list over the sequential list is that it is convenient to add and delete a large amount of data, which is exactly what this project needs
2.1.2 long term storage
For long-term storage, because we haven't learned the database for the time being, and time doesn't allow, we use the familiar file operation function in C language to save the user data in the corresponding file, and the teacher doesn't allow us to use the database. It's said that it's not difficult for students who know the database (◎ロ◎)
2.2. Search and sort
In daily life, it is not difficult to find that a regular piece of data in the APP or Web or applet we usually use will generally have the search function, and the search will certainly turn the data into order before it is displayed to users, so as to increase the user experience. Therefore, we need to review the relevant algorithms of sorting and searching.
Common search algorithms: sequential search, half search, block search, hash search, etc
Common sorting algorithms: half sort, Hill sort, quick sort, heap sort, etc
2.3. Linear table operation
The addition, deletion, modification and query of linear list, especially the linked list, should be mastered skillfully, and the preparation of these functions should be handy. can't??? On the way of strengthening technology!!!
2.4 document operation
File operation is fundamental. After all, it needs long-term storage. To ensure data persistence, you can't automatically log off your account after this registration and login, right? So we have to master file operation. We are mainly familiar with file opening and closing, file information reading and writing, and file pointer positioning is not used in this project, so we just have a simple understanding of it, If you are interested, you can ask Du Niang by yourself
2.5 code writing specification
This is team cooperation. What you fear most is that the code writing is not standardized. When you do it, you must unify some writing styles of the code, or later you will find that your mind is full of "what's this a", "what's this func doing", "what's this b"... (headache)
2, Demand analysis
Only when there is demand analysis can we have the direction of writing code, so I am honored to be a customer in the team, experience the feeling of God, and determine the following functional modules
functional module | functional analysis | remarks |
---|---|---|
Registration function | Account number for new user registration | Non croppable |
Login function | Used for user login to the system | Non croppable |
Personal information management | Used to view and modify personal account information | Non croppable |
Address book management | Used to manage the contact information of the user's circle of friends | Non croppable |
Schedule management | The user records the user's schedule | Non croppable |
financial management | It is used to record the daily financial situation of users | Non croppable |
Fitness Management | It is used to record the fitness of users | Non croppable |
Attached here is the project flow chart of my team's project
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-2AYO1QV5-1626514299048)(C:\Users \ lemon fruit \ appdata \ roaming \ typora user images \ image-20210716075801216. PNG)]
3, Analysis of difficulties and doubts
1. Read the file and write it to the linked list (control size)
It mainly uses binary for storage. At the beginning, because I was unfamiliar with it, I adopted the stupidest method to read and write files line by line with fget and fput. Later, I was asked by the teacher, "why not read and write a node directly". Therefore, after looking up the data and personal demo test, I found that Zhenxiang (! w!), See -- > financial management module for specific implementation
2. How to sort in Chinese
At the beginning, another student of my group and I struggled for a long time. Finally, after a whim to use strcmp to test, we found that the sorting was successful, and then we went to widely check the experience sharing of others. It turned out that the Chinese sorting was based on its Pinyin as the logo;
3. How are multiple files linked
At first, I thought about putting it in a file. Other function modules are only its sub functions, but after merging, I found that there are more than 4000 lines (! M!) Then I went to Du Niang to find out how to solve this problem. Finally, I decided to package the function module into a function library and call it according to the header file in the main function, so as to control the amount of code of each file. It looks very comfortable and delicious (~ w ~)
4, Core code idea and Implementation
Due to team cooperation, there will be some differences in code implementation, interface layout and code style. Some of them refer to the code ideas written by members themselves. If there is any problem, you are welcome to give advice (+ w +)
//Node structure typedef struct userAccountInfo { accountInfo user; //User personal Center struct userAccountInfo *next; } userAccountInfo, *LinkuserAccountInfo;
1. Login registration
At the beginning of the program, the data stored in the user library document is first loaded into the user-defined linked list. When a new user registers, the system will judge whether the user name already exists to ensure the uniqueness of the user name (acting as the role of userID).
When logging in, it will be matched according to the account and password entered by the user. If the matching is successful, it will enter the system main menu
//Log in and traverse the linked list to match the account and password while(p) { if(!strcmp(UserName, p->user.userName)) { printf("Please input a password:"); scanf("%s",PassWord); getchar(); if(!strcmp(PassWord, p->user.userPassword)) { printf("Logging in, please wait\n"); Sleep(900); //Wait for 0.9 seconds to delete system("cls"); //Clear screen mainMenu(p->user); return ; } else { while(errortime) { printf("Please re-enter your password(Remaining%2d Second chance): ", errortime);//Password error re-enter scanf("%s", PassWord); getchar(); errortime--; if(!strcmp(PassWord, p->user.userPassword)) { //You can only make mistakes three times at most printf("Logging in, please wait\n"); Sleep(900); system("cls"); mainMenu(p->user); return ; } } if(!errortime) { //Password error reached maximum printf("Password error multiple times!! Automatically exit the login interface!!!\n"); return ; } } } p = p->next; }
During registration, it will check whether the account ID applied for registration already exists. If it already exists, you will be prompted to re-enter it
p = userInfo->next; char userPassword_1[SCOPE]; printf("----------—\n"); printf("| Please enter the user name you want to register |\n"); printf("----------—\n\n"); scanf("%s", s->user.userName); //Enter the registered user name getchar(); while(p||(strcmp(s->user.userName, "admin") == 0)) { //Determine whether the user name conflicts with the administrator if(!strcmp(s->user.userName, "admin") || !strcmp(s->user.userName, p->user.userName)) { printf("-----------—\n"); printf("| The user already exists!!! |\n"); printf("| Please re-enter the user name you want to register |\n"); printf("-----------—\n\n"); scanf("%s", s->user.userName); //Re enter the user name getchar(); p = userInfo; } p = p->next; //Mobile traversal }
2. Administrator module
The administrator set in the system has the functions of viewing user information, logging off user account and resetting user password. The main implementation is also completed by traversing the linked list. The core code of logging off user account is attached below (to judge whether the option is legal, you can use the do while loop to control it)
/*Log off user*/ void cancelUserAccount(LinkuserAccountInfo &user, char *userTarget) { userAccountInfo *p; p = searchUsesrInfo(user, userTarget); //Find target node if(!p) { return ; } int chooseSure; printf("\n----------------—\n"); printf(" Are you sure you want to log off the user\"%s\": \n",userTarget); printf(" 1. confirm 2. cancel \n"); printf("----------------—\n\n"); chooseSure = getch(); while(chooseSure > 2+48 || chooseSure < 1+48) { printf("Please enter the correct option\n"); printf("\n----------------—\n"); printf(" Are you sure you want to log off the user\"%s\": \n",userTarget); printf(" 1. confirm 2. cancel \n"); printf("----------------—\n\n"); chooseSure = getch(); } switch(chooseSure) { case '1': { system("cls"); userAccountInfo *q; q = p->next; p->next = q->next; usernum--; free(q); printf("\n----------------—\n"); printf(" user\"%s\"Has been logged off \n", userTarget); printf("----------------—\n\n"); system("pause"); system("cls"); return ; } case '2': { system("cls"); break; } } }
3. Personal Center
The main function of this module is to view and modify personal basic information and modify personal account password
/*Modify user password*/ Status changePassword(char *password) { int countError = 0; //Number of incorrect password entries char inputWord[15]; //Enter your password printf("\n----------------—\n"); printf(" Please enter your old password \n"); printf("----------------—\n"); cin >> inputWord; for(countError = 1; countError <= maxErrorTime; countError++) { //If the user enters the password incorrectly more than the set number of times, the password cannot be modified if(countError == maxErrorTime) { //Too many errors, exit the password modification program printf("\n----------------—\n"); printf(" You have entered the wrong password too many times \n"); printf(" The interface will exit automatically \n"); printf("----------------—\n"); return ERROR; } //Triggered when the input is the same as the user's old password if(!strcmp(password, inputWord)) { int flag = 1; char newPassword[15], newPasswordAgain[15]; //Judge whether the new password entered by the user twice is consistent while(flag) { printf("\n----------------—\n"); printf(" Please enter your new password \n"); printf("----------------—\n"); cin >> newPassword; //Enter new password printf("\n----------------—\n"); printf(" Please enter the new password again \n"); printf("----------------—\n"); cin >> newPasswordAgain;//Enter the new password again //Judge whether the two inputs are equal if(!strcmp(newPassword, newPasswordAgain)) { //Enter the new password twice and update the password at the same time strcpy(password, newPassword); printf("\n----------------—\n"); printf(" Password modified successfully \n"); printf("----------------—\n"); return OK; } else { //If the new password is not entered twice, re-enter the new password at the same time printf("\n----------------—\n"); printf(" The two passwords are different \n"); printf(" Please re-enter your new password \n"); printf("----------------—\n"); } } } else { printf("\n----------------—\n"); printf(" Password input error \n"); printf(" Please re-enter your password \n"); printf("----------------—\n"); cin >> inputWord; } } }
4. Schedule management
It mainly records the daily travel data of users, and also has the function of adding, deleting, modifying and querying
/*New schedule*/ Status userscheduleManaInsert(LinkuserscheduleMana &L) { userscheduleMana *s; s = new userscheduleMana; printf("\n Please enter the time:"); scanf("%s",s->elem.eventTime); getchar(); printf("\n Please enter the task:"); scanf("%s",s->elem.EventAddress); getchar(); s->next = L->next; L->next = s; printf("Increase success!!!!\n"); system("pause"); system("cls"); }
5. Address book management
It adopts the operation of linked list and the operation of reading and writing files, so as to realize the function of addition, deletion, modification and query
/*Sort contact information*/ void SortInformation(InformationLinkList &L,int n) { int i,j; Contacts temp[1]; FILE *fp = fopen(DataAddress, "wb+"); if (fp == NULL) { printf("There is no content in the file. Please create a new contact information first\n"); } Contacts read_demo[Max]; fread(read_demo, sizeof(Contacts),n, fp); for( i=1;i<n;i++)//Using insertion sorting { strcpy(temp[0].ContactsNUm,read_demo[i].ContactsNUm); strcpy(temp[0].ContactsName,read_demo[i].ContactsName); strcpy(temp[0].ContactsAge,read_demo[i].ContactsAge); strcpy(temp[0].ContactsPhone,read_demo[i].ContactsPhone); strcpy(temp[0].ContactsAddress,read_demo[i].ContactsAddress); strcpy(temp[0].ContactsMail,read_demo[i].ContactsMail); for(j=i-1;j>=0&&strcmp(temp[0].ContactsNUm,read_demo[j].ContactsNUm)<0;j--){ strcpy(read_demo[j+1].ContactsNUm,read_demo[j].ContactsNUm); strcpy(read_demo[j+1].ContactsName,read_demo[j].ContactsName); strcpy(read_demo[j+1].ContactsAge,read_demo[j].ContactsAge); strcpy(read_demo[j+1].ContactsPhone,read_demo[j].ContactsPhone); strcpy(read_demo[j+1].ContactsAddress,read_demo[j].ContactsAddress); strcpy(read_demo[j+1].ContactsMail,read_demo[j].ContactsMail); } strcpy(read_demo[j+1].ContactsNUm,temp[0].ContactsNUm); strcpy(read_demo[j+1].ContactsName,temp[0].ContactsName); strcpy(read_demo[j+1].ContactsAge,temp[0].ContactsAge); strcpy(read_demo[j+1].ContactsPhone,temp[0].ContactsPhone); strcpy(read_demo[j+1].ContactsAddress,temp[0].ContactsAddress); strcpy(read_demo[j+1].ContactsMail,temp[0].ContactsMail); } printf("The sorted contact information is(Number from small to large): \n"); printf("number Name age Telephone number postal address mailbox\n"); printf("-------------------\n"); for( i=0;i<n;i++) printf("|%s\t%s\t%s\t%s\t%s\t%s|\n",read_demo[i].ContactsNUm,read_demo[i].ContactsName, read_demo[i].ContactsAge, read_demo[i].ContactsPhone,read_demo[i].ContactsAddress,read_demo[i].ContactsMail); printf("-------------------\n"); fwrite(read_demo,sizeof(Contacts),n,fp); fflush(stdin); fclose(fp); }
6. Fitness Management
Create a structure linked list to store each data field of the scheme, enter the nodes in the linked list, add, delete, change and query to perform basic operations on the linked list, and then enter the nodes into the document and read the document
/*Find scheme information by name*/ fitnessNode *searchFitnessInfo(Fitness &userFitness, char *target) { fitnessNode *p; p = userFitness; //Sequential search of linked list while(p->next) { if(!strcmp(p->next->data.schemeName, target)) { printf("----------------—\n\n"); printf(" Scheme Name:%s \n",p->next->data.schemeName); printf(" Scheme type:%s \n",p->next->data.schemeCategory); printf(" Scheme strength:%s \n",p->next->data.schemeIntensity); printf(" Scheme Description:%s \n",p->next->data.schemeDescribe); printf("----------------—\n\n"); return p; //Return to precursor node } p = p->next; } return NULL; //If it does not exist, it returns null }
7. Financial management
Maybe I'm tired of adding, deleting, modifying and checking here. Here's a self-made read-write file code (binary) combined with my personal ideas and a highlight from the teacher. The basic idea is to read and write each time
/*Load initialization financial information*/ void initFinance() { userFinance = (FinNode *)malloc(sizeof(FinNode));//Initialize linked list userFinance->next = NULL; FILE *fp; fp = fopen("financeInfo.dat", "rb"); //open the target file if(!fp) { printf("\n----------------—\n"); printf(" Data reading error! \n"); printf("-----------------\n"); fclose(fp); return ; } // fwrite(&numFinanceInfo, sizeof(numFinanceInfo), 1, fp); // It is used by developers to set numfinanceinfo to zero at the beginning fread((void*)&numFinanceInfo, sizeof(numFinanceInfo), 1, fp); //Number of financial data nodes read from the file if(numFinanceInfo == 0) { fclose(fp); return ; } int tempNumFin = numFinanceInfo; FinNode *p; p = userFinance->next; //Enter data into the linked list while(tempNumFin--) { //Read out one by one according to the number of information p = (FinNode *)malloc(sizeof(FinNode)); fread((void*)&p->data, sizeof(financeInfo), 1, fp); //Enter the linked list with the node size read each time, and read financeInfo times p->next = userFinance->next; userFinance->next = p; } fclose(fp); } /*Update financial information*/ void upDataFinance() { FILE *fp; fp = fopen("financeInfo.dat", "wb+"); //Open file overwrite write for binary file if(!fp) { printf("\n----------------—\n"); printf(" Data error, the packet may have been lost \n"); printf("-----------------\n"); fclose(fp); return ; } fwrite(&numFinanceInfo, sizeof(numFinanceInfo), 1, fp); FinNode *p; p = userFinance->next; while(numFinanceInfo--) { //The number of writes is determined according to the number of messages if(fwrite(p, sizeof(financeInfo), 1, fp) == 1) { //Give the address to each node, write the size of a node, and write it once p = p->next; } } fclose(fp); }
5, Summary and harvest
There must be harvest and growth. I mainly summarize it into the following brief points
- The data structure review before the training made me notice the details I didn't notice before writing the code
- When writing code, code specifications and appropriate comments are important
- Teamwork in project production is a new challenge, but after you stick to it, you will naturally find your lack of technical knowledge
6, White whoring source code
We have to find a way to get the first-hand source code -- >