@
preface
This is a small project written in c in my freshman year, "the implementation of Internet cafe management system", which is provided for everyone to learn and use here
Main knowledge:
- Creation and use of linked list
- File operation
- Application of various c statements
tips: when using, remember to add an Account library.txt document to the c file
1, Design task
Nowadays, the network is very developed, and various software, games and media have very high requirements for the network. Therefore, in order to meet consumers, Internet cafes must be rebuilt to establish an entertainment and management platform supported by network technology, computer technology and modern information technology, and develop the current activities based on game network to the platform of multi-functional entertainment, It will not only greatly improve the competitiveness and profitability of Internet cafes, but also build them into first-class high-end Internet cafes, so as to attract high-end consumer groups and lay a strong foundation for Liu. This is what we want to achieve. Therefore, it is analyzed that a reasonable, simple and standardized Internet cafe management system meets the current demand situation.
2, Programming and Implementation
This program is for two types of users, VIPs and administrators. There are two entrances. VIPs can register and log in. Administrators have fixed accounts and passwords (secret entrances). VIP has the functions of getting on and off the computer and changing password
Administrators have successively developed functions such as viewing and recharging member information. As shown in the figure below
1. Data description
(1) Member information storage
typedef struct { char vipAccount[MAX]; //Membership account (ID number) char vipPassword[MIN]; //Member password char vipPhoneNum[11]; //Member binding mobile number int vipAmount; //Remaining amount of member } VIP;
(2) Time information storage
typedef struct clock { int hour; hour int minute; minute int second; second }Clock;
(3) Global variable design
Define global variables MAX and MIN to limit the length of account and password
2. Functional module design
(1) Function name: void signUp()
Function function: login account
Input:
Output:
Algorithm description:
(2) Function name: void enroll()
Function function: Registration
Input:
Output:
Algorithm description:
(3) Function name: void getPassBack()
Function: password retrieval
Input:
Output:
Algorithm description:
(4) Function name: void GetPassword()
Function function: password echo '*'
Enter: password
Output: None
Algorithm description:
(5) Function name: void vipMenu()
Function: member interface
Input:
Output:
Algorithm description:
(6) Function name: void maMenu()
Function function: administrator interface
Input:
Output:
Algorithm description:
(7) Function name: void getOn()
Function: user on the computer
Input:
Output:
Algorithm description
(8) Function name: void changePass()
Function function: password modification
Input:
Output:
Algorithm description:
(9) Function name: void preservation(double money)
Function function: update user information
Input: used amount
Output:
Algorithm description:
(10) Function name: void manage()
Function function: administrator login
Input:
Output:
Algorithm description:
(11) Function name: void inforSheet()
Function: View member information
Input: None
Output: None
Algorithm description:
(12) Function name: void recall()
Function: recharge
Input: None
Output: None
Algorithm description:
(13) Function name: void Begin()
Function function: transition animation
Input: None
Output: None
Algorithm description:
(14) Function name: void menu()
Function function:
Input:
Output:
Algorithm description:
3, UI design effect
1. Launch interface: a simple approach animation.
2. Start interface: display several functions.
3. User interface: basic information of members.
4. Information printing interface:
5. Deficiencies and corrective measures of the project so far:
(1) The interface display is not beautiful enough.
(2) Data printing is not neat enough.
(3) Failed to complete the function of playing games while timing (adding c language games in it) (I can't solve it now as a sophomore. My freshman intention is to use some small games written in c)
4, Code implementation (remember to add an Account library.txt text document)
tips: administrator system entry method: enter "administrator login" under the user menu. The default account is (account: admin Password: 1111)
Viewing method of verification code: open c file -- > open vercode.txt
User registration: ID is ID number, initial password: 123456 (modifiable)
#include <stdio.h> #include <string.h> #include <windows.h> #include<time.h> #include<stdint.h> #include <stdlib.h> #define MAX 19 #define MIN 16 #define MIN_INPUT 0x20 #define MAX_INPUT 0x7e time_t timer; struct tm *tblock; int userPrint;//Used for user input verification code typedef struct { char vipAccount[MAX]; //Membership account (ID number) char vipPassword[MIN]; //Member password char vipID[17]; //Unknown error (1) char vipPhoneNum[11]; //Member binding mobile number double vipAmount; //Remaining amount of member } VIP; VIP user;//Easy to operate typedef struct clock { int hour; //hour int minute; //minute int second; //second } Clock; Clock startime;//It is used to store the start time Clock endtime;//Used to store the offline time Clock temptime;//Used to store temporary time void vipMenu()//Member interface ui { system("cls"); printf("_________________________________________\n"); printf("|*Member information |\n"); printf("|*account number:%c%c%c%c%c%c%c%c%c%c%c%c%c%c**** |\n",user.vipAccount[0],user.vipAccount[1],user.vipAccount[2],user.vipAccount[3],user.vipAccount[4],user.vipAccount[5],user.vipAccount[6],user.vipAccount[7],user.vipAccount[8],user.vipAccount[9],user.vipAccount[10],user.vipAccount[11],user.vipAccount[12],user.vipAccount[13]); printf("|*cell-phone number:%c%c%c****%c%c%c%c |\n",user.vipPhoneNum[0],user.vipPhoneNum[1],user.vipPhoneNum[2],user.vipPhoneNum[7],user.vipPhoneNum[8],user.vipPhoneNum[9],user.vipPhoneNum[10]); printf("|*Balance:%lf |\n",user.vipAmount); printf("| |\n"); printf("|===========Member interface====================|\n"); printf("|=======================================|\n"); printf("|======operate a computer===========Get off the plane==============|\n"); printf("|======Use help=======Password modification==========|\n"); printf("|_______________________________________|\n"); if(user.vipAmount<0) { printf("Insufficient balance, please recharge"); system("pause"); menu(); } else { userChoices(); } } void GetPassword(char* pszPw)//Password echo "*" { char ch; int i=0; int flag=1; while( ( ch = (char)getch() ) ) { flag=1; if ( ch == 13) { pszPw[i++]=0; break; } else if ( ch >= MIN_INPUT && ch <= MAX_INPUT) /*All printable characters*/ { pszPw[i++]=ch; } else if ( ch == 8 && i> 0 ) //Backspace key { pszPw[i--] = 0; flag = 0; putchar( ch ); putchar( ' ' ); putchar( ch ); } else flag= 0; if(flag) putchar('*'); } pszPw[i]=0; } void manage()//Administrator login { char userAccount[5]; char userPass[5]; printf("account number:"); scanf("%s",userAccount); printf("password:"); scanf("%s",userPass); if(strcmp(userAccount,"admin")==0 && strcmp(userPass,"1111")==0) { maMenu(); } } void maMenu()//Administrator interface { system("cls"); printf("_________________________________________\n"); printf("|===========Administrator interface==================|\n"); printf("|=======================================|\n"); printf("|======Member information overview========Member recharge=====|\n"); printf("|======Use help=========================|\n"); printf("|_______________________________________|\n"); maChoice(); } void maChoice()//Administrator selection { char choice[20]; scanf("%s",choice); if(strcmp(choice,"Member information overview")==0) { memberInfor(); } else if(strcmp(choice,"Member recharge")==0) { memberRecharge(); } } void memberInfor()//Member information overview { int i = 0; VIP mangePass; FILE *fpp = fopen("Account library.txt","r+"); printf("|NO| |account number| |password| |Binding| |balance|\n"); printf("------------------------------------------------------------------------------\n"); while(!feof(fpp)) { i++; fscanf(fpp,"%s",mangePass.vipAccount); printf("%04d %s ",i,mangePass.vipAccount); fscanf(fpp,"%s",mangePass.vipPassword); printf("%s ",mangePass.vipPassword); fscanf(fpp,"%s",mangePass.vipPhoneNum); printf("%s ",mangePass.vipPhoneNum); fscanf(fpp,"%s",mangePass.vipID); printf("%s\n",mangePass.vipID); } maChoice(); } void memberRecharge()//Member recharge { int i = 3; int condiTime = 0; int flag = 0; char key[MAX];//For transferring data char account[MAX];//Recharge account double reMoney; while(1) { rename("Account library.txt","Accountlibrary.txt"); FILE *fp = fopen("Accountlibrary.txt","r+"); FILE *fpp = fopen("Account library.txt","wt+"); printf("Enter recharge account:"); scanf("%s",account); printf("Enter recharge amount:"); scanf("%lf",&reMoney); while(fscanf(fp,"%s",key)!=EOF) { fprintf(fpp,"%s",key); condiTime++; if(condiTime%4!=0) { fprintf(fpp," "); } else { fprintf(fpp,"\n"); } if(strcmp(account,key)==0) { flag = 1; double balance; fscanf(fp,"%s",key); fprintf(fpp,"%s ",key); fscanf(fp,"%s",key); fprintf(fpp,"%s ",key); fscanf(fp,"%lf",&balance); balance = balance + reMoney; fprintf(fpp,"%lf\n",balance); condiTime = 0; } } fclose(fpp); fclose(fp); system("del Accountlibrary.txt"); if(!flag) { printf("Account does not exist, please re-enter:"); } else { printf("Account information updated\n"); while(i>1) { printf("Return to the user interface.......%ds",i--); printf("\r"); Sleep(1000); } system("pause"); maMenu(); } } } void enroll()//register { char choice; int flag ;//Flag used to judge whether the mobile phone number is repeated VIP user; printf("Registering...\n"); while(1) { char account[MAX]; char phoneNum[12]; printf("ID number:"); scanf("%s",user.vipAccount); //ID number checking FILE *pf = fopen("Account library.txt","r+"); while(fscanf(pf,"%s",account)!=EOF) { if(strcmp(account,user.vipAccount)==0) { printf("Account has been registered,Please re-enter:"); enroll(); } } fclose(pf); if(strlen(user.vipAccount)!=18) { continue; } else if(strlen(user.vipAccount)==18) { unsigned long curTime; time(&timer); tblock = gmtime(&timer); curTime = (tblock->tm_year+1900)*10000+(tblock->tm_mon+1)*100+tblock->tm_mday; //printf("%ld",curTime); unsigned long tempTime; tempTime = (user.vipAccount[6]-'0')*10000000+(user.vipAccount[7]-'0')*1000000+(user.vipAccount[8]-'0')*100000+(user.vipAccount[9]-'0')*10000+(user.vipAccount[10]-'0')*1000+(user.vipID[11]-'0')*100+(user.vipID[12]-'0')*10+(user.vipID[13]-'0'); //printf("%ld",tempTime); if(curTime-tempTime>180000) { int flag = 0;//Used to judge //printf("pass"); while(1) { flag = 0; printf("Enter phone number:"); scanf("%s",user.vipPhoneNum); //Duplicate check of mobile phone number FILE *pf = fopen("Account library.txt","r+"); while(fscanf(pf,"%s",phoneNum)!=EOF) { if(strcmp(phoneNum,user.vipPhoneNum)==0) { printf("Mobile phone number has been registered, please re-enter:"); flag = 1; break; } } fclose(pf); if(flag) { continue; } if(strlen(user.vipPhoneNum)!=11) { printf("Input error, re-enter\n"); continue; } else { int j; //Read the verification code in the file while(1) { int i = 3; j = verCode(); printf("Please enter the verification code:"); scanf("%d",&userPrint); if(userPrint==j) { FILE *fp = fopen("Account library.txt","a+"); fprintf(fp,"%s 123456 %s 0.000000\n",user.vipAccount,user.vipPhoneNum); fclose(fp); printf("Successfully registered, please remember your account(ID number)And password (default: 123456)\n"); printf(">>>Request sending\n"); while(i>1) { printf(".......%d",i--); printf("\r"); Sleep(1000); } system("pause"); signUp(); } else { printf("Verification code error, do you want to re-enter the mobile phone number(Y/N):"); scanf("\n"); scanf("%c",&choice); if(choice == 'Y') { break; } else { printf("The verification code has been re sent,"); continue; } } } } } } else { printf("Minors are not allowed to surf the Internet\n"); continue; } } } } void signUp()//Sign in { int flag = 0;//Correct sign of account number int count = 0; FILE *fp; char userAccount[18]; char userPass[16]; while(1) { printf("account number:"); scanf("%s",userAccount); fp = fopen("Account library.txt","r"); while(!feof(fp)) { fscanf(fp,"%s",user.vipAccount); if(strcmp(userAccount,user.vipAccount)==0) { flag = 1; fscanf(fp,"%s",user.vipPassword); fscanf(fp,"%s",user.vipPhoneNum); fscanf(fp,"%lf",&user.vipAmount); while(count<3) { printf("password:"); GetPassword(userPass); if(strcmp(userPass,user.vipPassword)==0) { fclose(fp); //printf("login succeeded"); vipMenu(); } else if(count<3) { printf("The password is incorrect. Please re-enter:"); count++; } } while(1) { int j = verCode(); int userVerify; printf("Verification Code:%d\n Please enter the above verification code:",j); scanf("%d",&userVerify); if(userVerify==j) { printf("Re enter password:"); GetPassword(userPass); if(strcmp(userPass,user.vipPassword)==0) { fclose(fp); // printf("login succeeded"); vipMenu(); } } } } else { fscanf(fp,"%s",user.vipPassword); fscanf(fp,"%s",user.vipPhoneNum); fscanf(fp,"%lf",&user.vipAmount); } } if(!flag) { fseek(fp,0L,0); printf("Account does not exist,Please re-enter\n"); fclose(fp); } } } int verCode()//Send verification code { int i; int j; srand((int)time(0));//Initialization time j = rand()%9999; FILE *fp = fopen("vercode.txt","w+"); //printf("%d",j);// Need to write file fprintf(fp,"%d",j); fclose(fp); return j; } void Begin()//Start ui { printf("The Internet cafe management system is being started. Please abide by the Internet cafe management regulations and take good care of your belongings.\n"); char str[100] = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; int i,j; for(i = 0; i<strlen(str); i++) { printf("%c",str[i]); Sleep(10); } printf("\n Load complete\n"); system("pause"); system("cls"); } void menu()//Menu interface ui { system("cls"); printf("==================================\n"); printf("===========Internet cafe management system===========\n"); printf("==================================\n"); printf("======Member login=======Become a member=====\n"); printf("======Use help=======Retrieve password=====\n"); printf("==================================\n"); userChoice(); } void userChoice()//User selection 1 { while(1) { char userchoice[20]; scanf("%s",userchoice); if(strcmp(userchoice,"Member login")==0) { // printf("login"); signUp(); } else if(strcmp(userchoice,"Become a member")==0) { printf("register"); enroll(); } else if(strcmp(userchoice,"Use help")==0) { printf("help"); //userMal(); } else if(strcmp(userchoice,"Administrator login")==0) { manage(); } else if(strcmp(userchoice,"Retrieve password")==0) { getPassBack(); } else { printf("Input error, please re-enter"); } } } void getPassBack() { int j,i; int flag = 0; //Is there a label corresponding to the account number char key[11]; while(1) { printf("Enter the binding mobile number:"); scanf("%s",key); if(strlen(key)!=11) { printf("Input error, re-enter\n"); continue; } VIP mangePass; FILE *fpp = fopen("Account library.txt","r+"); while(!feof(fpp)) { fscanf(fpp,"%s",mangePass.vipAccount); fscanf(fpp,"%s",mangePass.vipPassword); fscanf(fpp,"%s",mangePass.vipPhoneNum); fscanf(fpp,"%s",mangePass.vipID); if(strcmp(key,mangePass.vipPhoneNum)==0) { flag = 1; break; } } if(flag) { printf("Verification code has been sent, please enter:"); j = verCode(); while(1) { scanf("%d",&userPrint); if(userPrint==j) { printf("|NO| |account number| |password| |Binding| |balance|\n"); printf("------------------------------------------------------------------------------\n"); printf("%04d %s ",i,mangePass.vipAccount); printf("%s ",mangePass.vipPassword); printf("%s ",mangePass.vipPhoneNum); printf("%s\n",mangePass.vipID); } else { printf("Wrong input!! Re-enter"); } } } } } void userChoices()//User selection 2 { char userchoice[10]; while(1) { scanf("%s",userchoice); if(strcmp(userchoice,"operate a computer")==0) { getOn(); } else if(strcmp(userchoice,"Get off the plane")==0) { printf("Not yet on the computer"); } else if(strcmp(userchoice,"Use help")==0) { } else if(strcmp(userchoice,"Password modification")==0) { changePass(); } } } void getOn()//operate a computer { int endWhile = 0;//Used to end the cycle after getting off the machine int vipChoice;//Area options int upOdown;//Whether to get off the machine double money;//Unit Price while(1) { Clock a; printf("Selection area: 1.VIP area\n2.Game Zone\n3.Common area"); scanf("%d",&vipChoice); switch(vipChoice) { case 1: money = 0.25; break; case 2: money = 0.16; break; case 3: money = 0.05; break; default: getOn(); } while(!kbhit()) { printf("\r"); if(endWhile == 0) { timestar(); endWhile = 1; } timeend(); Sleep(1000); a.second = temptime.second - startime.second; if(a.second<0) { a.second = a.second + 60; temptime.minute--; } a.minute = temptime.minute - startime.minute; if(a.minute<0) { a.minute = a.minute + 60; temptime.hour--; } a.hour = temptime.hour - startime.hour; printf("%02d:%02d:%02d", a.hour, a.minute,a.second); if(a.minute%15==0 && a.minute!=0 && a.second==0) { //Auto save money = money*15; preservation(money); } } printf("Get off the plane? (1/0)"); scanf("%d",&upOdown); if(upOdown==1) { if(vipChoice == 1) { //Auto save money = money *((a.hour*60+a.minute)%15); preservation(money); break; } else if(vipChoice == 2) { //Auto save money = money *((a.hour*60+a.minute)%15); preservation(money); break; } else if(vipChoice == 3) { //Auto save money = money *((a.hour*60+a.minute)%15); preservation(money); break; } } else { printf("again"); } } } void preservation(double money)//Update user information { int i = 3; int condiTime = 0; double balance; char key[19];//For transfer of file data rename("Account library.txt","Accountlibrary1.txt"); FILE *fp = fopen("Accountlibrary1.txt","r+"); FILE *fpp = fopen("Account library.txt","wt+"); while(fscanf(fp,"%s",key)!=EOF) { fprintf(fpp,"%s",key); condiTime++; if(condiTime%4!=0) { fprintf(fpp," "); } else { fprintf(fpp,"\n"); } if(strcmp(user.vipPhoneNum,key)==0) { double balance; fscanf(fp,"%lf",&balance); balance = balance - money; fprintf(fpp,"%lf\n",balance); condiTime++; } } fclose(fpp); fclose(fp); system("del Accountlibrary1.txt"); printf("Account information updated\n"); while(i>1) { printf("Return to the user interface.......%ds",i--); printf("\r"); Sleep(1000); } system("pause"); } void changePass()//Password modification { int i = 3; int j; char phone[11]; while(1) { printf("Enter the binding mobile number:"); scanf("%s",phone); if(strcmp(phone,user.vipPhoneNum)==0) { printf("Verification code has been sent, please enter:"); j = verCode(); while(1) { scanf("%d",&userPrint); if(userPrint==j) { int condiTime = 0; char key[19];//For transfer of file data printf("Enter new password:"); scanf("%s",user.vipPassword); rename("Account library.txt","Accountlibrary1.txt"); FILE *fp = fopen("Accountlibrary1.txt","r+"); FILE *fpp = fopen("Account library.txt","wt+"); while(fscanf(fp,"%s",key)!=EOF) { condiTime++; if(strcmp(key,user.vipAccount)!=0) { fprintf(fpp,"%s ",key); } else { fprintf(fpp,"%s ",key); fprintf(fpp,"%s ",user.vipPassword); fscanf(fp,"%s",key); condiTime++; } if(condiTime%4==0) { fprintf(fpp,"\n"); } } fclose(fpp); fclose(fp); system("del Accountlibrary1.txt"); printf("The password has been changed successfully. Please remember your account(ID number)And new password\n"); printf(">>>Request sending\n"); while(i>1) { printf(".......%d",i--); printf("\r"); Sleep(1000); } system("pause"); vipMenu(); } else { printf("Verification code error, re-enter:"); } } } else { printf("Mobile phone number input error"); } } } void timestar()//Record start time { time_t now ; struct tm *p ; time(&now) ; p = localtime(&now) ; startime.hour = p->tm_hour; startime.minute = p->tm_min; startime.second = p->tm_sec; } void timeend()//Record end time { time_t now ; struct tm *p ; time(&now) ; p = localtime(&now) ; temptime.hour = p->tm_hour; temptime.minute = p->tm_min; temptime.second = p->tm_sec; } int main() { Begin(); menu(); return 0; }