#include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio.h>
#include <windows.h> #define N sizeof(user) #define M sizeof(table) #define T
sizeof(order) #define S sizeof(menu) typedef struct User{ char
username[12];// account number char password[18];// password int vip;//1 For members 0 no int
adm;//administrator ditto // Or store the above data in the way of data domain struct User* next; }user; // Pay attention to initialization
, You can write an initialization function draw lessons from 7 month 9 In the notes of No “ initialization ” typedef struct Menu{ int num;//1~10 Serve hot dishes 11~20 Serve cold dishes
21~25 For drinks char name[20]; int price; struct Menu* next; }menu; typedef struct
Table{ int number; int is_blank; int peoplenum; struct Order*
ordert;// The head node of the order of the table int price;// The total price of the table struct Table* next; }table; typedef
struct Order{ int number;// The number of the dish char name[20]; int copies;// Number of dishes int price; int
xiaoji; struct Order* next; }order; // The following are user-defined functions void welcome(); int ORDER(order*
head);// Order function //void reg();// Registration function void login(); void logon(); void
show();// Display menu function void client();// Customer function void look_amend();// View modified functions void
add();// Additive function void cancel();// Cancel function int priceall();// Calculation of total price function void
getpassword(char password[18],char againpassword[18]); int
is_password_same(char password[18],char againpassword[18]); void
save_user(user* p); menu* ffmenuhot(); menu* ffmenucold(); menu* ffmenudrink();
table* fftable(); void resave_table(table* head); table* fftable() { FILE *fp1;
// field name pointer int n = 0; table* head = NULL; table* q; table* p; //system("md
E:\\canyin\\table"); fp1 = fopen("E:\\canyin\\table\\table.txt","a+");
// Open the file as read-only if(fp1 == NULL) { printf(" File open failed \n"); //getchar(); //exit(0); }
else { while(!feof(fp1)) // Determine whether the file location flag is moved to the end of the file { n ++; p =
(table*)malloc(sizeof(table)); // Request a space from memory //fread(p, N, 1, fp1);
// take fp The contents of the file to which you point are assigned to p fscanf(fp1,"%d %d %d %d %d", &p->number , &p->is_blank ,
&p->peoplenum , &p->price , &p->ordert ); if(n == 1) { head = p; q = p; } else
// Create linked list { q->next = p; q = p; } } q->next = NULL; } fclose(fp1); // Close the file return
head; // Return header pointer } void resave_table(table* head) { table* p; p = head;
//system("md E:\\canyin\\table"); FILE *file; // field name pointer file =
fopen("E:\\canyin\\table\\table.txt","wb+"); // Open the file as an append if(file == NULL) {
printf(" File open failed \n"); } ///if(fwrite(p, N, 1, fp)!=1)
// take p The target 1 Size of N Write data structure of fp In the file pointed to //{ //printf(" File write failed \n"); while(p->next != NULL)
{ fprintf( file ,"%d %d %d %d %d \n", p->number, p->is_blank , p->peoplenum ,
p->price , p->ordert); p=p->next; } //} fclose(file); // Close the file } void client() {
order* orderh; orderh=(order*)malloc(sizeof(order)); int tablenum;
printf(" What are the current table choices :\n"); table* head; table* p; head =
(table*)malloc(sizeof(table)); p = (table*)malloc(sizeof(table)); head =
fftable(); p = head; while(p->next != NULL) { if(p->is_blank==0)
printf("%d number \t",p->number); } printf(" Please choose your table number :"); scanf("%d",&tablenum); p =
head; while(p->number == tablenum) { p->is_blank = 1; p->ordert = orderh;
break; } // Confirm seat number //char a; /* printf("1. order "); printf("2. View ordered dishes ");
scanf("%s",&a); switch(a) { case'1':order();break;// Calling the order function
case'2':look_amend();break;// Call the view function default:printf(" Please enter the correct option !");break; } */
printf(" Order, please :\n"); p->price = ORDER(orderh); resave_table(head); } int
ORDER(order* head) { menu* hot; menu* cold; menu* drink; int copies; int i=1;
int priceall = 0; hot = ffmenuhot(); cold = ffmenucold(); drink =
ffmenudrink(); menu *h , *c , *d; show();// Display menu function int numo;
printf("\n Please enter the serial number of your order :( with # end )"); // Add the main dish to the order list //order* head; order* p; order*
q; head = (order*)malloc(sizeof(order)); p = head; while(getch()!='#') {
printf("%d:",i); scanf("%d",&numo); printf(" Number of copies :"); scanf("%d",&copies); h =
hot; c = cold; d = drink; while(h->next != NULL) { if(h->num==numo) { //p =
(order*)malloc(sizeof(order)); q = (order*)malloc(sizeof(order)); q->next =
NULL; p->number = h->num; strcmp(p->name , h->name ); p->price = h->price;
p->copies = copies; p->next = q; q = p; priceall = priceall +
copies*(h->price); break; } } while(c->next != NULL) { if(c->num==numo) { //p =
(order*)malloc(sizeof(order)); q = (order*)malloc(sizeof(order)); q->next =
NULL; p->number = c->num; strcmp(p->name , c->name ); p->price = c->price;
p->copies = copies; p->next = q; q = p; priceall = priceall +
copies*(h->price); break; } } while(d->next != NULL) { if(d->num==numo) { //p =
(order*)malloc(sizeof(order)); q = (order*)malloc(sizeof(order)); q->next =
NULL; p->number = d->num; strcmp(p->name , d->name ); p->price = d->price;
p->copies = copies; p->next = q; q = p; priceall = priceall +
copies*(h->price); break; } } i++; } printf("\n Order successfully !");
printf(" What is the total price of your order :%d",priceall); Sleep(10000); system("cls"); return priceall;
//look_amend(); } void look_amend() { char a; printf(" What's your order :\n");
// Output the dishes in the order list one by one printf("1. Add dishes \n"); printf("2. Delete dishes \n"); printf("3. determine \n");
scanf("%s",&a); switch(a) { case'1':add();break;// Call add dish function
case'2':cancel();break;// Call subtraction function case'3':priceall();break;
default:printf(" Please enter the correct option !");break; } } void add() { show();
printf(" Please input the serial number of the dish you want to add :"); // Add vegetables to order list printf("\n Add food successfully !"); Sleep(2000);
system("cls"); look_amend(); } void cancel() { printf(" What's your order :");
printf("\n Please enter the serial number of the dish you want to delete :"); // Delete the dish from the order list printf("\n Cancel successfully !"); Sleep(2000);
system("cls"); look_amend(); } /* void enter()// Sign in { printf(" account number :\n");
printf(" password :"); // Call judgment login function ; printf("\n Login successful !"); Sleep(2000);
printf("\n Welcome !");// Judge ordinary customers member administrators client(); }*/ /* void login() {
printf(" account number :\n"); printf(" password :"); // Call judgment login function ; printf("\n Login successful !"); Sleep(2000);
printf("\n Welcome !");// Judge ordinary customers member administrators client(); }*/ /* void reg()// Registration function { // Registered account
printf(" login was successful !"); Sleep(2000); system("cls"); order();// Calling the order function } */ void
show()// display { menu* p1; menu* p2; menu* p3; menu* headhot; menu* headcold; menu*
headdrink; headhot = ffmenuhot(); headcold = ffmenucold(); headdrink =
ffmenudrink(); p1 = headhot; p2 = headcold; p3 = headdrink; printf(" Hot Dishes :\n");
printf(" Serial number Dish name Price \n"); printf("%d %s %d \n", p1->num, p1->name , p1->price);
while(p1->next != NULL) { printf("%d %s %d \n", p1->num, p1->name , p1->price);
p1=p1->next; } printf(" cold dish :\n"); printf(" Serial number Dish name Price \n"); while(p2->next!=NULL) {
printf("%d %s %d \n", p2->num, p2->name , p2->price); p2=p2->next; }
printf(" Drinks :\n"); printf(" Serial number Dish name Price \n"); while(p3->next!=NULL) { printf("%d %s %d
\n", p3->num, p3->name , p3->price); p3=p3->next; } } int priceall()// Total price {
// Calculate the total price and output printf(" What is the total price of your order :"); printf("\n Please wait for the waiter to serve you ( If you need to modify, please contact the attendant )"); } void
welcome() { system("cls"); system("color 3E");
printf("=============== Welcome to Ganwei Hakka restaurant management system ===============\n\n\n\n"); printf("\t
1. Sign in \n"); printf("\t 2. register \n"); printf(" Please select [1 2] : [ ]\b\b\b"); int n; while(1)
{ scanf("%d",&n); switch(n) { case 1: login();// Sign in break; case 2: logon();// register
break; default: break; } } } user* ff1() // Output the content in the file of the account number to the linked list { FILE *fp1;
// field name pointer int n = 0; user* head = NULL; user* q; user* p; system("md
E:\\canyin\\zhanghu"); fp1 = fopen("E:\\canyin\\zhanghu\\zhanghu.txt","a+");
// Open the file as read-only if(fp1 == NULL) { printf(" File open failed \n"); //getchar(); //exit(0); }
else { while(!feof(fp1)) // Determine whether the file location flag is moved to the end of the file { n ++; p = (user*)malloc(N);
// Request a space from memory //fread(p, N, 1, fp1); // take fp The contents of the file to which you point are assigned to p fscanf(fp1,"%s %s %d
%d",p->username ,p->password ,&p->vip ,&p->adm); if(n == 1) { head = p; q = p;
} else // Create linked list { q->next = p; q = p; } } q->next = NULL; } fclose(fp1); // Close the file
return head; // Return header pointer } // Read menu from menu file menu* ffmenuhot() { FILE *fp1; // field name pointer int n
= 0; menu* head = NULL; menu* q; menu* p; system("md E:\\canyin\\menu"); fp1 =
fopen("E:\\canyin\\menu\\hotcai.txt","a+"); // Open the file as read-only if(fp1 == NULL) {
printf(" File open failed \n"); //getchar(); //exit(0); } else { while(!feof(fp1))
// Determine whether the file location flag is moved to the end of the file { n ++; p = (menu*)malloc(sizeof(menu)); // Request a space from memory
//fread(p, N, 1, fp1); // take fp The contents of the file to which you point are assigned to p fscanf(fp1,"%d %s %d",&p->num
,p->name ,&p->price); if(n == 1) { head = p; q = p; } else // Create linked list { q->next =
p; q = p; } } q->next = NULL; } fclose(fp1); // Close the file return head; // Return header pointer }
menu* ffmenucold() { FILE *fp1; // field name pointer int n = 0; menu* head = NULL; menu* q;
menu* p; system("md E:\\canyin\\menu"); fp1 =
fopen("E:\\canyin\\menu\\coldcai.txt","a+"); // Open the file as read-only if(fp1 == NULL) {
printf(" File open failed \n"); //getchar(); //exit(0); } else { while(!feof(fp1))
// Determine whether the file location flag is moved to the end of the file { n ++; p = (menu*)malloc(sizeof(menu)); // Request a space from memory
//fread(p, N, 1, fp1); // take fp The contents of the file to which you point are assigned to p fscanf(fp1,"%d %s %d",&p->num
,p->name ,&p->price); if(n == 1) { head = p; q = p; } else // Create linked list { q->next =
p; q = p; } } q->next = NULL; } fclose(fp1); // Close the file return head; // Return header pointer }
menu* ffmenudrink() { FILE *fp1; // field name pointer int n = 0; menu* head = NULL; menu* q;
menu* p; system("md E:\\canyin\\menu"); fp1 =
fopen("E:\\canyin\\menu\\drink.txt","a+"); // Open the file as read-only if(fp1 == NULL) {
printf(" File open failed \n"); //getchar(); //exit(0); } else { while(!feof(fp1))
// Determine whether the file location flag is moved to the end of the file { n ++; p = (menu*)malloc(sizeof(menu)); // Request a space from memory
//fread(p, N, 1, fp1); // take fp The contents of the file to which you point are assigned to p fscanf(fp1,"%d %s %d",&p->num
,p->name ,&p->price); if(n == 1) { head = p; q = p; } else // Create linked list { q->next =
p; q = p; } } q->next = NULL; } fclose(fp1); // Close the file return head; // Return header pointer } void
login() // Account login { system("cls"); // Clear screen user* p; user* head; head = ff1(); p =
head; // Call function , The return value is the pointer of the head node /* p = head; while(p->next!=NULL) { printf("%s %s %d
%d\n", p->username ,p->password , p->vip, p->adm); p=p->next; }*/ do{ char t,
c, k, name1[12], password1[18]; int i = 0;
printf("***************************\n\n\n\n"); printf("\t\t Login status ");
printf(" Please enter your account number :"); scanf("%s", name1); printf(" Please enter your password :"); for(;;)
// Here is the operation of entering password without echo { k = getch(); // input k if(k == '\r') // If input k For carriage return , Jump out of the loop { break; }
else if(k == '\b') // If input k Is the delete key { if(i > 0) // If the password has not been completely deleted { printf("\b");
printf(" "); printf("\b"); i--; } } else // If the k Is not a delete key , It's not a enter { password1[i] =
k; // hold k The value of is assigned to _password[i]; printf("*"); // output * number , Protect user privacy i ++; // Password digit plus 1 } }
password1[i] = '\0'; while( (p != NULL) && (strcmp(p->username, name1) != 0) )
// Traverse linked list , Find the account number of the currently entered account { p = p->next; } if(p != NULL) // If p Not empty {
if(strcmp(p->password, password1) == 0) // If the password is correct { printf(" Logging in ....\n");
Sleep(500); // suspend 0.5 second system("cls"); printf(" Successful login !\n"); break; // Jump out of the loop } else
// If you enter the wrong password { printf(" Logging in ....\n"); Sleep(500); system("cls");
printf("-------------------------\n"); printf("| |\n"); printf("| Wrong password ! Do you want to continue ?
|\n"); printf("| 1. yes 2. no |\n"); printf("| |\n");
printf("-------------------------\n"); while(1) { t = getch(); // input t if(t ==
'1') { system("cls"); // Clear screen break; } else if(t == '2') // If input t by n, Enter the start interface {
welcome(); break; } } } } else // If p It is empty , That is, the entered account number is incorrect { printf(" Logging in ....\n");
Sleep(500); system("cls"); printf("-------------------------\n"); printf("|
|\n"); printf("| Account number error ! Do you want to continue ? |\n"); printf("| |\n"); printf("| 1. yes 2. no |\n");
printf("| |\n"); printf("-------------------------\n"); while(1) // Dead loop prevents interference from other keys
{ c = getch(); if(c == '1') { system("cls"); break; } else if(c == '2') {
welcome(); break; } } } }while(1); // Always true Sleep(500); // suspend 0.5 second client();
//menu(); // The account and password are correct , Enter the main menu } void logon() // Registered account number { //system("md
E:\\canyin\\zhanghu"); system("cls"); user* p; p = (user*)malloc(N);
// Request a space from memory p->next==NULL; //do //{ char
name[12],password[18],againpassword[18],c,k; int i = 0; printf(" Ganwei Hakka catering management system \n");
printf("**************************\n"); printf(" Please enter the account number ( cell-phone number ):\n");
scanf("%s",name); //printf(" Please input a password :\n"); for(;;) // Here is the operation of entering password without echo {
getpassword(password,againpassword);
if(is_password_same(password,againpassword)==1); //if(strcmp(password,
againpassword) == 0) // If both passwords are correct { strcpy(p->username, name);
strcpy(p->password, password); printf("\n Register as a member (0. no ,1. yes )"); scanf("%d",
&p->vip); printf("\n Register as administrator (0. no ,1. yes )"); scanf("%d", &p->adm);
printf(" Registering ....\n"); save_user(p); Sleep(500); system("cls");
printf(" login was successful !\n"); Sleep(500); // suspend 0.5 second break; // Jump out of the loop } /* else // If the two passwords entered are different {
printf(" Registering ....\n"); Sleep(500); system("cls");
printf("-----------------------------"); printf("| |"); printf("|
login has failed ! The two passwords are not unified , Continue to register ? |"); printf("| |"); printf("| 1. yes 2. no |"); printf("| |");
printf("-----------------------------"); while(1) { c = getch(); if(c == '1') {
system("cls"); //logon(); break; } else if(c == '2') { welcome(); break; } }
}*/ } //}while(1); // Always true printf(" Auto login for you ....\n"); Sleep(500);
printf("\n Login successful !"); Sleep(2000); printf("\n Welcome !");// Judge ordinary customers member administrators client();
//login(); } void getpassword(char password[18],char againpassword[18]) { char
k; int i=0; printf(" Please input a password :\n"); for(;;) // Here is the operation of entering password without echo { k = getch(); // input k
if(k == '\r') // If input k For carriage return , Jump out of the loop { break; } else if(k == '\b') // If input k Is the delete key { if(i
> 0) // If the password has not been completely deleted { printf("\b"); printf(" "); printf("\b"); i --; } } else
// If the k Is not a delete key , It's not a enter { password[i] = k; // hold k The value of is assigned to _password[i]; printf("*");
// output * number , Protect user privacy i ++; // Password digit plus 1 } } password[i] = '\0'; i = 0;
printf("\n Please confirm your password :\n"); for(;;) // Here is the operation of entering password without echo { k = getch(); // input k if(k ==
'\r') // If input k For carriage return , Jump out of the loop { break; } else if(k == '\b') // If input k Is the delete key { if(i > 0)
// If the password has not been completely deleted { printf("\b"); printf(" "); printf("\b"); i --; } } else
// If the k Is not a delete key , It's not a enter { againpassword[i] = k; // hold k The value of is assigned to _password[i];
printf("*"); // output * number , Protect user privacy i++; // Password digit plus 1 } } againpassword[i] = '\0'; } int
is_password_same(char password[18],char againpassword[18]) { char c;
if(strcmp(password, againpassword) != 0) { { printf(" Registering ....\n"); Sleep(500);
system("cls"); printf("-----------------------------"); printf("| |");
printf("| login has failed ! The two passwords are not unified , Continue to register ? |"); printf("| |"); printf("| 1. yes 2. no |");
printf("| |"); printf("-----------------------------"); while(1) { c = getch();
if(c == '1') { system("cls"); //logon(); getpassword(password,againpassword);
break; } else if(c == '2') { return 0; welcome(); //break; } } } } else return
1; } void save_user(user* p) { system("md E:\\canyin\\zhanghu"); FILE *file;
// field name pointer file = fopen("E:\\canyin\\zhanghu\\zhanghu.txt","a"); // Open the file as an append
if(file == NULL) { printf(" File open failed \n"); } ///if(fwrite(p, N, 1, fp)!=1)
// take p The target 1 Size of N Write data structure of fp In the file pointed to //{ //printf(" File write failed \n"); fprintf( file ,"%s %s
%d %d\n", p->username , p->password , p->vip , p->adm ); //} fclose(file);
// Close the file } int main() { /* char a; printf(" Welcome to the catering management system !"); Sleep(2000);// suspend 1s
system("cls"); printf("1. Sign in "); printf("2. register "); scanf("%s",&a); switch(a) {
case'1':enter();break;// Call login function case'2':reg();break;// Call registration function
default:printf(" Please enter the correct option !");break; } */ welcome();// Call login function }
This is previously written catering management system , It's no match for the big guys , You can refer to it , The file can't be found because it was written before , You can modify the file and create it again  

 

Technology