1, Subject content and requirements
1. Problem description
With the improvement of modern living standards, household cars have increasingly become a necessity in life. Learn about riders' information to facilitate communication and organize activities among riders. The system requires the development of a riders Club software, which can easily query riders' information, understand riders' dynamic information, launch riders' activities and other functions. Through this subject, master various operations of files, arrays and pointers, as well as the application of some algorithm ideas.
2. Basic requirements
(1) Riders' information shall include: owner information (member name, nickname, gender, occupation, driving age, age, etc.), driving information (vehicle brand, vehicle model, color, etc.); (use struct to store riders' information)
(2) Password verification is required to enter the system;
(3) Establish a ridership information base, and the input information conforms to logic, such as driving age is positive, relevant information conforms to actual standards, etc;
(4) Realize the dynamic update of the information of new members and retired members of the car club, and make statistics and display of the changes in the age composition of members at each time stage;
(5) Conditional query. It is convenient to query the information of riders according to the conditions such as name, gender, age, car payment and membership time, and sort them with different sorting algorithms.
(6) Store the information content and query information of the car club in the form of files.
2, Demand analysis
1. Provide operable main menu: output menu, which is used to display the total customer information loaded from the file and several optional function options. Run different functions and functions according to the options entered by the customer. There are several menu display functions in the program, which need to be called and displayed circularly.
2. Certain input detection: there are many places for users to choose in this program, and they will call each other on the menu, including circular operation. When users select the corresponding menu options, they will enter, which requires certain detection of user input.
3. Clear storage format: when the structure array is used for user information storage. As well as the storage of user satisfaction survey information, the file format should be optimized to make it clear. And it can be flexible, convenient and easy to operate when reading and saving file information.
3, Outline design
1. Main storage structure
// The code is bad, light spray. Note: for reference only. //Riders information structure struct Club { char id[20];//Membership card number char name[20];//full name char sex[10];//Gender char age[10];//Age char job[20];//work char drive_age[20];//Driving age char brand[20];//Car brand char style[20];//Car style char color[20];//Car color char time_user[BUFLEN];//Membership time }; typedef struct Club club;
The storage diagram is as follows:
2. Main function flow
(1) System operation: after entering the system, the outermost menu function will be called to display the password and outer menu. The process is shown in the figure:
(2) The operation flow of menu functions is shown in the figure. There are a large number of menu calling functions similar to this in this program. Only the most important menu function instance is listed here.
(3) General framework of the system
4, Source code
// The code is bad, light spray. Note: for reference only. // Header file #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> // #include<bits/stdc++.h> // using namespace std; //Global variable definition #define USER_FILE "user.txt" / / store the information file of the riders #define RESULT_FILE "result.txt" / / satisfaction survey file #define CONSOLE "CON" / / redirect the use, and the output is directed on the console #define BUFLEN 255 / / get the timestamp length #define NUM 50 / / number of riders, which can be changed according to actual needs #define PASSWORD 123 / / the password used to enter the system //================Structure content================== //Riders information structure struct Club { char id[20];//Membership card number char name[20];//full name char sex[10];//Gender char age[10];//Age char job[20];//work char drive_age[20];//Driving age char brand[20];//Car brand char style[20];//Car style char color[20];//Car color char time_user[BUFLEN];//Membership time }; typedef struct Club club; //================Function declaration================== //Function declaration; Convenient calls between functions void init(club* user);//Initialize structure void readuser(club* user);//Read the rider user information from the file to the structure void saveuser(club* user);//Save the riders' user information to the file int topmenu();//Outermost main menu void user_result(club* user);//Satisfaction survey function void menu(club* user);//Menu of main program functions void showid(club* user);//Display riders' information according to id void managemenu(club* user);//Driver information management menu void add_user();//Add riders information void del_user(club* user);//Delete riders void modify_user(club* user);//Modify information void sum_menu(club* user);//Main menu of riders statistics void total_user(club* user);//Count the total number of riders void total_age(club* user);//Number of riders of all ages void factor_menu(club* user);//Condition query main menu void find_sex(club* user);//Query information by gender void find_style(club* user);//Query information according to style void find_name(club* user);//Query information by name void find_age(club* user);//Query information by age void find_time(club* user);//Query information according to membership time //================Program auxiliary related content================== //Initialization information function void init(club* user) { for (int i = 0; i < NUM;i++) { strcpy(user[i].id, ""); strcpy(user[i].name, ""); strcpy(user[i].sex, ""); strcpy(user[i].age, ""); strcpy(user[i].job, ""); strcpy(user[i].drive_age, ""); strcpy(user[i].brand, ""); strcpy(user[i].style, ""); strcpy(user[i].color, ""); strcpy(user[i].time_user, ""); } } //Read the rider user information from the file to the structure void readuser(club* user) { //Input redirection, input from file freopen(USER_FILE, "r", stdin); for (int i = 0;i < NUM;i++) { scanf("%s%s%s%s%s%s%s%s%s%s", user[i].id, user[i].name, user[i].sex, user[i].age, user[i].job, user[i].drive_age, user[i].brand, user[i].style, user[i].color, user[i].time_user); } //Redirect back to console //printf("%s,%s,%s,%s,%s,%s,%s,%s,%s",user[0].id, user[0].name, user[0].sex, user[0].age, user[0].job, user[0].drive_age, user[0].brand, user[0].style, user[0].color); freopen("CON", "r", stdin); } //Save the riders' user information to the file void saveuser(club* user) { freopen(USER_FILE, "w", stdout); for (int i = 0;i < NUM;i++) { if (strlen(user[i].id) != 0) { printf("%s %s %s %s %s %s %s %s %s %s\n", user[i].id, user[i].name, user[i].sex, user[i].age, user[i].job, user[i].drive_age, user[i].brand, user[i].style, user[i].color, user[i].time_user); } } freopen(CONSOLE, "w", stdout); } //================Riders information management related================== //Display the riders' information according to the riders' membership card number id void showid(club* user) { readuser(user); int flag = -1; char num_id[20]; printf(" Please enter the members to display ID: "); scanf("%s", num_id); for (int i = 0;i < NUM - 1;i++) { if (strcmp(user[i].id, num_id) == 0) { flag = i; printf(" Membership card No.:%s", user[i].id); printf(" full name:%s", user[i].name); printf(" Gender:%s", user[i].sex); printf(" Age:%s", user[i].age); printf(" occupation:%s", user[i].job); printf(" Driving age:%s\n", user[i].drive_age); printf(" Vehicle brand:%s", user[i].brand); printf(" Car payment:%s", user[i].style); printf(" Color:%s", user[i].color); printf(" Membership time:%s\n", user[i].time_user); } } if (flag == -1) printf(" There is no such card!"); } //Add riders information function void add_user() { char id[20];//Membership card number char name[20];//full name char sex[5];//Gender char age[5];//Age char job[20];//work char drive_age[20];//Driving age char brand[20];//Car brand char style[20];//Car style char color[20];//Car color char time_user[BUFLEN];//Membership time //Get time time_t t = time(0); char tmpBuf[BUFLEN]; //This time is 2020-11-27-23:01:23 //strftime(tmpBuf, BUFLEN, "%Y-%m-%d-%H:%M:%S", localtime(&t)); // Format time //This time is November 27, 2020 strftime(tmpBuf, BUFLEN, "%Y-%m-%d", localtime(&t)); //Format time printf(" Enter membership card number:"); scanf("%s", id); printf(" Enter name:"); scanf("%s", name); printf(" Enter gender:"); scanf("%s", sex); printf(" Enter age:"); scanf("%s", age); printf(" Enter Occupation:"); scanf("%s", job); printf(" Enter driving age:"); scanf("%s", drive_age); printf(" Enter vehicle make:"); scanf("%s", brand); printf(" Enter vehicle payment:"); scanf("%s", style); printf(" Enter color:"); scanf("%s", color); // field name pointer FILE* fp = fopen(USER_FILE, "a+"); // output to a file fputs(id, fp); fputs(" ", fp); fputs(name, fp); fputs(" ", fp); fputs(sex, fp); fputs(" ", fp); fputs(age, fp); fputs(" ", fp); fputs(job, fp); fputs(" ", fp); fputs(drive_age, fp); fputs(" ", fp); fputs(brand, fp); fputs(" ", fp); fputs(style, fp); fputs(" ", fp); fputs(color, fp); fputs(" ", fp); fputs(tmpBuf, fp); fputs("\n", fp); fclose(fp); printf("Successfully added!"); } //Delete riders information function void del_user(club* user) { readuser(user); int flag = -1; char num[20]; printf(" Please enter the card number to delete:"); scanf("%s", num); for (int i = 0;i < NUM - 1;i++) { //Empty after finding the card if (strcmp(user[i].id, num) == 0) { flag = i; strcpy(user[i].id, ""); strcpy(user[i].name, ""); strcpy(user[i].sex, ""); strcpy(user[i].age, ""); strcpy(user[i].job, ""); strcpy(user[i].drive_age, ""); strcpy(user[i].brand, ""); strcpy(user[i].style, ""); strcpy(user[i].color, ""); strcpy(user[i].time_user, ""); printf(" Delete succeeded!"); } } if (flag == -1) printf(" If you don't have this card, please register first!"); saveuser(user); } //Modify riders information function void modify_user(club* user) { readuser(user); int flag = -1, mod_ch = 0; char num[20], change[20]; printf(" Please enter the card number to modify the information:");scanf("%s", num); for (int i = 0;i < NUM - 1;i++) { //Empty after finding the card if (strcmp(user[i].id, num) == 0) { flag = i; printf("==Please select the type to modify==\n"); printf(" Press 1 : Modify name\n"); printf(" Press 2 : Modify gender\n"); printf(" Press 3 : Modify age\n"); printf(" Press 4 : Modify occupation\n"); printf(" Press 5 : Modify driving age\n"); printf(" Press 6 : Modify vehicle brand\n"); printf(" Press 7 : Modify car payment\n"); printf(" Press 8 : Modify color\n\n"); printf(" Please enter your choice"); scanf("%d", &mod_ch); printf(" Please enter the modified information:");scanf("%s", change); switch (mod_ch) { case 1:strcpy(user[i].name, "");strcpy(user[i].name, change);break; case 2:strcpy(user[i].sex, "");strcpy(user[i].sex, change);break; case 3:strcpy(user[i].age, "");strcpy(user[i].age, change);break; case 4:strcpy(user[i].job, "");strcpy(user[i].job, change);break; case 5:strcpy(user[i].drive_age, "");strcpy(user[i].drive_age, change);break; case 6:strcpy(user[i].brand, "");strcpy(user[i].brand, change);break; case 7:strcpy(user[i].style, "");strcpy(user[i].style, change);break; case 8:strcpy(user[i].color, "");strcpy(user[i].color, change);break; } printf(" Modification succeeded!"); } } if (flag == -1) printf(" If you don't have this card, please register first!"); saveuser(user); } //Driver information management menu void managemenu(club* user) { int re = 0; printf("\n======== Riders information management ========\n"); printf(" [---- Press 1 : Add riders information----]\n"); printf(" [---- Press 2 : Delete riders information----]\n"); printf(" [---- Press 3 : Modify riders' information----]\n"); printf(" [---- Press 0 : Previous Menu ----]\n"); printf(" Please enter your choice:");scanf("%d", &re); if (re >= 0 && re < 5) { switch (re) { case 1:fflush(stdin);add_user();break;//Add riders information case 2:fflush(stdin);del_user(user);break;//Delete riders information case 3:fflush(stdin);modify_user(user);break;//Modify information case 0:fflush(stdin);menu(user);break;//Return to superior } } else { printf(" Input error!\n");managemenu(user); } } //================Statistics on the number of riders================== //Count the total number of riders void total_user(club* user) { readuser(user); int total = 0; for (int i = 0;i < NUM;i++) { if (strlen(user[i].id) != 0) { total++; } } printf(" The total number of riders is:%d", total); } //Number of riders of all ages; void total_age(club* user) { readuser(user); int total[11]; memset(total, 0, 11 * sizeof(int));//Initialization zero for (int i = 0;i < NUM;i++) { if (strlen(user[i].age) != 0) { total[atoi(user[i].age) / 10]++; } } for (int i = 0; i < 11; i++) { printf(" %2d0 — %2d0 The number of people in the age group is:%d\n", i, i + 1, total[i]); } } //Riders Statistics Menu void sum_menu(club* user) { int re = 0; printf("\n======== Number of riders Statistics Menu ========\n"); printf(" [---- Press 1 : Total number of riders------]\n"); printf(" [---- Press 2 : Number of people of all ages----]\n"); printf(" [---- Press 0 : Previous Menu ----]\n"); printf(" Please enter your choice:");scanf("%d", &re); if (re >= 0 && re < 5) { switch (re) { case 1:fflush(stdin);total_user(user);break;// case 2:fflush(stdin);total_age(user);break;// case 0:fflush(stdin);menu(user);break;//Return to superior } } else { printf(" Input error!\n");sum_menu(user); } } //================Query related information according to criteria================== //Condition query main menu void factor_menu(club* user) { int re = 0; printf("\n======== Driver information query menu ========\n"); printf(" [---- Press 1 : Query by gender----]\n"); printf(" [---- Press 2 : Query according to car payment----]\n"); printf(" [---- Press 3 : Query by name----]\n"); printf(" [---- Press 4 : Query by age----]\n"); printf(" [---- Press 5 : Query according to membership time]\n"); printf(" [---- Press 0 : Previous Menu ----]\n"); printf(" Please enter your choice:");scanf("%d", &re); if (re >= 0 && re < 6) { switch (re) { case 1:fflush(stdin);find_sex(user);break;//Query information by gender case 2:fflush(stdin);find_style(user);break;//Query information according to style case 3:fflush(stdin);find_name(user);break;//Query information by name case 4:fflush(stdin);find_age(user);break;//Query information by age case 5:fflush(stdin);find_time(user);break;//Query information according to membership time case 0:fflush(stdin);menu(user);break;//Previous Menu } } else { printf(" Input error!\n");factor_menu(user); } } //Query information by gender void find_sex(club* user) { readuser(user); int flag = -1; char cx[20]; printf(" Please enter the corresponding information to query:"); scanf("%s", cx); for (int i = 0;i < NUM - 1;i++) { if (strcmp(user[i].sex, cx) == 0) { flag = i; printf(" Membership card No.:%s", user[i].id); printf(" full name:%s", user[i].name); printf(" Gender:%s", user[i].sex); printf(" Age:%s", user[i].age); printf(" occupation:%s", user[i].job); printf(" Driving age:%s\n", user[i].drive_age); printf(" Vehicle brand:%s", user[i].brand); printf(" Car payment:%s", user[i].style); printf(" Color:%s", user[i].color); printf(" Membership time:%s\n", user[i].time_user); } } if (flag == -1) printf(" Sorry, we didn't find the information you need!"); } //Check information according to style void find_style(club* user) { readuser(user); int flag = -1; char cx[20]; printf(" Please enter the corresponding information to query:"); scanf("%s", cx); for (int i = 0;i < NUM - 1;i++) { if (strcmp(user[i].style, cx) == 0) { flag = i; printf(" Membership card No.:%s", user[i].id); printf(" full name:%s", user[i].name); printf(" Gender:%s", user[i].sex); printf(" Age:%s", user[i].age); printf(" occupation:%s", user[i].job); printf(" Driving age:%s\n", user[i].drive_age); printf(" Vehicle brand:%s", user[i].brand); printf(" Car payment:%s", user[i].style); printf(" Color:%s", user[i].color); printf(" Membership time:%s\n", user[i].time_user); } } if (flag == -1) printf(" Sorry, we didn't find the information you need!"); } //Check information by name void find_name(club* user) { readuser(user); int flag = -1; char cx[20]; printf(" Please enter the corresponding information to query:"); scanf("%s", cx); for (int i = 0;i < NUM - 1;i++) { if (strcmp(user[i].name, cx) == 0) { flag = i; printf(" Membership card No.:%s", user[i].id); printf(" full name:%s", user[i].name); printf(" Gender:%s", user[i].sex); printf(" Age:%s", user[i].age); printf(" occupation:%s", user[i].job); printf(" Driving age:%s\n", user[i].drive_age); printf(" Vehicle brand:%s", user[i].brand); printf(" Car payment:%s", user[i].style); printf(" Color:%s", user[i].color); printf(" Membership time:%s\n", user[i].time_user); } } if (flag == -1) printf(" Sorry, we didn't find the information you need!"); } //Check the information according to age void find_age(club* user) { readuser(user); int flag = -1; char cx[20]; printf(" Please enter the corresponding information to query:"); scanf("%s", cx); for (int i = 0;i < NUM - 1;i++) { if (strcmp(user[i].age, cx) == 0) { flag = i; printf(" Membership card No.:%s", user[i].id); printf(" full name:%s", user[i].name); printf(" Gender:%s", user[i].sex); printf(" Age:%s", user[i].age); printf(" occupation:%s", user[i].job); printf(" Driving age:%s\n", user[i].drive_age); printf(" Vehicle brand:%s", user[i].brand); printf(" Car payment:%s", user[i].style); printf(" Color:%s", user[i].color); printf(" Membership time:%s\n", user[i].time_user); } } if (flag == -1) printf(" Sorry, we didn't find the information you need!"); } //Check the information according to the membership time void find_time(club* user) { readuser(user); int flag = -1; char cx[BUFLEN]; printf(" Please enter the corresponding information to query:"); scanf("%s", cx); for (int i = 0;i < NUM - 1;i++) { if (strcmp(user[i].time_user, cx) == 0) { flag = i; printf(" Membership card No.:%s", user[i].id); printf(" full name:%s", user[i].name); printf(" Gender:%s", user[i].sex); printf(" Age:%s", user[i].age); printf(" occupation:%s", user[i].job); printf(" Driving age:%s\n", user[i].drive_age); printf(" Vehicle brand:%s", user[i].brand); printf(" Car payment:%s", user[i].style); printf(" Color:%s", user[i].color); printf(" Membership time:%s\n", user[i].time_user); } } if (flag == -1) printf(" Sorry, we didn't find the information you need!"); } //================Content in the top-level menu================== //Main menu of riders information void menu(club* user) { int re = 0; printf("\n======== Welcome to the riders menu ========\n"); printf(" [---- Press 1 : Show riders information----]\n"); printf(" [---- Press 2 : Riders information management----]\n"); printf(" [---- Press 3 : Statistics of riders----]\n"); printf(" [---- Press 4 : Query by criteria----]\n"); printf(" Please enter your choice:");scanf("%d", &re); if (re > 0 && re < 5) { switch (re) { case 1:fflush(stdin);showid(user);break;//Display the car friend information according to the car friend card number id case 2:fflush(stdin);managemenu(user);break;//Riders information management case 3:fflush(stdin);sum_menu(user);break;//Statistics of riders case 4:fflush(stdin);factor_menu(user);break;//Query by criteria } } else { printf(" Input error!\n");menu(user); } } //Satisfaction survey function void user_result(club* user) { readuser(user); int flag = -1; char id[20], satis[20],feel[401]; printf(" Please enter your id: "); scanf("%s", id); for (int i = 0;i < NUM - 1;i++) { if (strcmp(user[i].id, id) == 0) { flag = i; printf(" Please rate the club(1-10): "); scanf("%s", satis); printf(" Please enter your personal feelings:"); scanf("%s", feel); printf(" Thank you for filling in. Bye!"); FILE* fp = fopen(RESULT_FILE, "a+"); fputs(id, fp); fputs(" ", fp); fputs(satis, fp); fputs(" ", fp); fputs(feel, fp); fputs("\n", fp); fclose(fp); } } if (flag == -1) printf(" If you don't have this card, please join the membership!"); } //================Top level menus and main functions================== //Enter the outermost menu of the program int topmenu() { int re = -1, password; printf(" Please enter the system password:");scanf("%d", &password); if (password == PASSWORD) { printf("\n======== Welcome to the riders system ========\n"); printf(" [---- Press 1 : Enter menu----]\n"); printf(" [---- Press 2 : Fill in the questionnaire----]\n"); printf(" [---- Press 0 : Exit the system----]\n"); printf(" Please enter your choice:"); scanf("%d", &re); while (!(re >= 0 && re < 3)) { printf(" Wrong input! Please re-enter!"); printf("\n======== Welcome to the riders system ========\n"); printf(" [---- Press 1 : Enter menu----]\n"); printf(" [---- Press 2 : Fill in the questionnaire----]\n"); printf(" [---- Press 0 : Exit the system----]\n"); printf(" Please enter your choice:"); scanf("%d", &re); } return re; } else printf(" Your password is incorrect, please confirm and try again!"); return -1; } int main(void) { club user[NUM];//Initialize riders entity init(user);//Call the initialization function to initialize //printf("Go:\n"); int re_menu = 0;//Receive the return value of menu() re_menu = topmenu();//menu() enters the system and returns the operation to be performed if (re_menu == 1) { printf("\n You will enter the riders menu!\n"); menu(user);//Call up the riders menu } else if (re_menu == 2) { printf("\n You will fill in the questionnaire!\n\n"); user_result(user);//Call the questionnaire filling function } else if (re_menu == 0) { exit(0); } printf("\n"); system("pause"); return 0; }
5, Test summary
001 qwe male 28 coder 2 maserati ghibli black 218-11-27
002 qqq female 33 lsp 5 maserati ghibli black 2019-11-27
003 www male 35 qwe 6 maserati ghibli yellow 2019-11-27
004 eee female 43 lkj 5 maserati ghibli red 2019-11-27
005 eee female 23 lkj 3 mahh ghi blue 2020-11-27
006 hhs male 56 haha 6 car 20 white 2020-11-27
010 nju male 35 tec 5 www 19 green 2020-11-27
The above is all the initial data of the test (written by yourself without basis). The data will change with the test. If necessary, screenshots will be compared, but the user data will not be initialized between two different tests.
Note: the above data respectively represent: Member id, name, gender, age, occupation, driving age, vehicle brand, vehicle payment, color and membership time.
The running part of the program is not mapped. If you are interested, please run it yourself~
6, Other
The above and the blog content with the words "sorting in school" in the blog are the code I wrote during my undergraduate study in school. My level is very low, big guy light spray. The purpose of sorting out is to help beginners learn and have reference when necessary. Again: for learning and communication only. If you have any questions, please leave a message~