<> one , Project brief

1, This program realizes the ordering function of users , There are five kinds of dishes : Cold Dishes , Hot Dishes , Pot , staple food , drink . There are also functions such as checking the order and ending .
2, Backstage administrator : Press a Accessible , There is no prompt on the main page .
3, Reasonable use getch function , Screen clearing and pause function , The page is clean and refreshing .
4, Dishes and txt File correspondence , It can realize the integration of program and software txt It has the function of adding, deleting, modifying and checking .
5, Used C Language has a lot of basic grammar : function , Pointer , structural morphology , Documents, etc .

<> two , Program description

After running the program, press a Enter the background management page , Add a dish to the corresponding dish information , This information is automatically saved to the txt in , It will be read automatically the next time it is opened , Do a good job in the creation of dish information, you can return to the main page for the corresponding user order operation .

<> three , Function demonstration

<> four , Mind map

<> five , Program code
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h>
/* Macro definition area */ #define max_str 30 // Maximum string length #define max_num 30 // Maximum number of dishes #define
max_all 100// Maximum total sales today /* Define dish structure */ struct dishes { char name[max_str]; int price
; }; /* Define global variables */ struct dishes list1[max_num]; // Store cold dish information int num1=0; // Storage quantity of cold dishes
int *p1=&num1; struct dishes list2[max_num]; // Store hot dish information int num2=0; // Storage quantity of hot dishes
int *p2=&num2; struct dishes list3[max_num]; // Storage information of Guozi dishes int num3=0; // Storage quantity of dishes
int *p3=&num3; struct dishes list4[max_num]; // Storage of staple food information int num4=0; // Quantity of staple food stored
int *p4=&num4; struct dishes list5[max_num]; // Storage of beverage and dish information int num5=0; // Storage quantity of drinks and dishes
int *p5=&num5; struct dishes list6[max_num]; // Store the ordering information of customers int num6=0;
// Quantity of dishes ordered by customers int *p6=&num6; struct dishes list7[max_all]; // Store today's order information int num7
=0; // Storage of total dishes ordered today int *p7=&num7; /* Global statement */ /* Output of menu */ // First level main menu char menu_m1(); //
Administrator first level menu char menu_a1(); // Administrator secondary menu : Tips for adding or deleting dishes char menu_a2(); // Output menu 1( Including prompt input statement )
void output_1(struct dishes list[],int num); // Output dish information 2( There is no prompt input statement ) void output_2(
struct dishes list[],int num); /* function */ // Create the required txt file void creat_file();
// Loading dish information into structure array , Nesting function modules 1: read txt Write to a single struct array void load_dishes(struct dishes list1[],
int *p1,struct dishes list2[],int *p2,struct dishes list3[],int *p3,struct
dishes list4[],int *p4,struct dishes list5[],int *p5);
// Functions for ordering , Nesting function modules 2: Realize the structure array of ordering and write data void ordering(struct dishes list1[],int num1,
struct dishes list2[],int *p2,struct dishes list3[],int *p3); // Output function of view and settlement void
settlement(struct dishes list[],int num); // Calculate today's income void income(struct dishes
list[],int num); // Realize the price modification of dishes , Embedded function module 3: Realize the price modification and file reconstruction of structured dishes void change(struct
dishes list[],int *p,char ch); // Realize the deletion of dishes , Embedded function module 4: Realize the deletion of structured dishes and the reconstruction of files void del(
struct dishes list[],int *p,char ch); // function : Add dishes , Embedded function module 5: Realize the addition of structured dishes and the reconstruction of files
void add(struct dishes list[],int *p,char ch); /* Function module area */
// functional module 1: read txt Write to a single struct array int function_read(struct dishes list[],FILE *fp);
// functional module 2: Realize the structure array of ordering and write data void function_ordering(struct dishes list1[],int num1,
struct dishes list2[],int *p2,struct dishes list3[],int *p3,int choice); //
functional module 3: Realize the price modification and file reconstruction of structured dishes , Embedded function module 6: The modified dishes are sorted by price from low to high int funtion_change(struct
dishes list[],int num,FILE *fp); // functional module 4: Realize the deletion of structured dishes and the reconstruction of files int function_del(
struct dishes list[],int *p,FILE *fp);
// functional module 5: Realize the addition of structured dishes and the reconstruction of files ,, Embedded function module 6: The modified dishes are sorted by price from low to high int function_add(struct
dishes list[],int *p,FILE *fp); // functional module 6: The modified dishes are sorted by price from low to high void function_sort
(struct dishes list[],int num); int main() { creat_file(); load_dishes(list1,p1,
list2,p2,list3,p3,list4,p4,list5,p5); int i,j,choice; char a,b,c; while(1) { a=
menu_m1(); switch(a) { case '1': ordering(list1,num1,list6,p6,list7,p7); break;
case '2': ordering(list2,num2,list6,p6,list7,p7); break; case '3': ordering(
list3,num3,list6,p6,list7,p7); break; case '4': ordering(list4,num4,list6,p6,
list7,p7); break; case '5': ordering(list5,num5,list6,p6,list7,p7); break; case
'6': system("cls"),settlement(list6,num6),system("pause"),system("cls"); break;
case 'y': system("cls"),settlement(list6,num6),*p6=0,system("pause"); break;
case 'a': system("cls"); while(1) { b=menu_a1(); switch(b) { case '1': system(
"cls"),income(list7,num7),system("pause"),system("cls"); break; case '2': {
system("cls"); c=menu_a2(); system("cls"); switch(c) { case '1': change(list1,p1
,c); break; case '2': change(list2,p2,c); break; case '3': change(list3,p3,c);
break; case '4': change(list4,p4,c); break; case '5': change(list5,p5,c); break;
} system("cls"); } break; case '3': { system("cls"); c=menu_a2(); system("cls");
switch(c) { case '1': del(list1,p1,c); break; case '2': del(list2,p2,c); break;
case '3': del(list3,p3,c); break; case '4': del(list4,p4,c); break; case '5':
del(list5,p5,c); break; } system("cls"); } break; case '4': { system("cls"); c=
menu_a2(); system("cls"); switch(c) { case '1': add(list1,p1,c); break; case '2'
: add(list2,p2,c); break; case '3': add(list3,p3,c); break; case '4': add(list4,
p4,c); break; case '5': add(list5,p5,c); break; } system("cls"); } break; case
'0': system("cls"); break; } if(b=='0') break; } break; } system("cls"); } }
/* Output of menu */ // First level main menu char menu_m1() { char ch; printf("
---------------------------\n"); printf(" | Welcome to our restaurant |\n"); printf(" | Please select dishes by serial number
|\n"); printf(" ---------------------------\n"); printf(" | 1 Cold Dishes |\n"); printf(
" | 2 Hot Dishes |\n"); printf(" | 3 Pot |\n"); printf(" | 4 staple food |\n"); printf(" | 5 drink
|\n"); printf(" | 6 see |\n"); printf(" | y settlement |\n"); printf("
---------------------------\n"); printf(" Enter the serial number :"); ch=getch(); return ch; } //
Administrator first level menu char menu_a1() { char ch; printf("\n-------------------------------\n");
printf("\t1\t Today's revenue \t\n"); printf("\t2\t Revise price \t\n"); printf("\t3\t Delete dishes \t\n");
printf("\t4\t Add dishes \t\n"); printf("\t0\t Return to the previous level \t\n"); printf(
"-------------------------------\n"); printf(" Enter the serial number :"); ch=getch(); return ch; }
// Administrator secondary menu : Tips for adding or deleting dishes char menu_a2() { char ch; printf(
"\n-------------------------------\n"); printf("\t1\t Cold Dishes \t\n"); printf(
"\t2\t Hot Dishes \t\n"); printf("\t3\t Pot \t\n"); printf("\t4\t staple food \t\n"); printf(
"\t5\t drink \t\n"); printf("\t0\t Return to the previous level \t\n"); printf(
"-------------------------------\n"); printf(" Enter the serial number :"); ch=getch(); return ch; }
// Output menu 1( Including prompt input statement ) void output_1(struct dishes list[],int num) { int i; printf(
"\n-------------------------------------------------\n"); printf(
"|\t Serial number \t variety of dishes \t\t Price \t\t|\n"); printf(
"-------------------------------------------------\n"); for(i=0; i<num; i++) {
if(strlen(list[i].name)<=6) printf("|\t%d\t%s\t\t%d\t\t|\n",i+1,list[i].name,
list[i].price); else printf("|\t%d\t%s\t%d\t\t|\n",i+1,list[i].name,list[i].
price); } printf("|\t0\t return \t\t\t\t|\n"); printf(
"-------------------------------------------------\n"); printf(" Please enter the serial number :\n"); }
// Output dish information 2( There is no prompt input statement ) void output_2(struct dishes list[],int num) { int i; printf
("\n-------------------------------------------------\n"); printf(
"|\t Serial number \t variety of dishes \t\t Price \t\t|\n"); printf(
"-------------------------------------------------\n"); for(i=0; i<num; i++) {
if(strlen(list[i].name)<=6) printf("|\t%d\t%s\t\t%d\t\t|\n",i+1,list[i].name,
list[i].price); else printf("|\t%d\t%s\t%d\t\t|\n",i+1,list[i].name,list[i].
price); } printf("|\t0\t return \t\t\t\t|\n"); printf(
"-------------------------------------------------\n"); } /* function */
// Create the required txt file void creat_file() { FILE *fp=fopen(" Cold Dishes .txt","a"); if(fp==NULL)
return; fclose(fp); fp=fopen(" Hot Dishes .txt","a"); if(fp==NULL) return; fclose(fp); fp=
fopen(" Pot .txt","a"); if(fp==NULL) return; fclose(fp); fp=fopen(" staple food .txt","a"); if
(fp==NULL) return; fclose(fp); fp=fopen(" drink .txt","a"); if(fp==NULL) return;
fclose(fp); } // Loading dish information into structure array , Nesting function modules 1: read txt Write to a single struct array void load_dishes(struct
dishes list1[],int *p1,struct dishes list2[],int *p2,struct dishes list3[],int *
p3,struct dishes list4[],int *p4,struct dishes list5[],int *p5) { FILE *fp; fp=
fopen(" Cold Dishes .txt","r"); *p1=function_read(list1,fp); fp=fopen(" Hot Dishes .txt","r"); *p2=
function_read(list2,fp); fp=fopen(" Pot .txt","r"); *p3=function_read(list3,fp); fp
=fopen(" staple food .txt","r"); *p4=function_read(list4,fp); fp=fopen(" drink .txt","r"); *p5=
function_read(list5,fp); fclose(fp); } // Functions for ordering , Nesting function modules 2: Realize the structure array of ordering and write data void
ordering(struct dishes list1[],int num1,struct dishes list2[],int *p2,struct
dishes list3[],int *p3) { int choice; system("cls"); output_1(list1,num1); while
(1) { scanf("%d",&choice); if(choice>=0&&choice<=num1) { if(choice==0) break;
else function_ordering(list1,num1,list2,p2,list3,p3,choice); } else printf(
" Wrong input serial number , Please re-enter :\n"); } } // Output function of view and settlement void settlement(struct dishes list[],int
num) { int i,sum; for(i=0,sum=0; i<num; i++) sum+=list[i].price; printf(
"\n-------------------------------------------------\n"); printf(
"|\t Serial number \t variety of dishes \t\t Price \t\t|\n"); printf(
"-------------------------------------------------\n"); for(i=0; i<num; i++) {
if(strlen(list[i].name)<=6) printf("|\t%d\t%s\t\t%d\t\t|\n",i+1,list[i].name,
list[i].price); else printf("|\t%d\t%s\t%d\t\t|\n",i+1,list[i].name,list[i].
price); } printf("-------------------------------------------------\n"); printf(
" The total price is :%d\n\n",sum); } // Calculate today's income void income(struct dishes list[],int num) { int
i,sum; output_2(list,num); for(i=0,sum=0; i<num; i++) sum+=list[i].price; printf
(" Total revenue today :%d\n",sum); } // Realize the price modification of dishes , Embedded function module 3: Realize the price modification and file reconstruction of structured dishes void change(struct
dishes list[],int *p,char ch) { int i=1; FILE *fp; while(i!=0) { switch(ch) {
case '1': output_2(list1,num1),fp=fopen(" Cold Dishes .txt","w"),i=funtion_change(list1,
num1,fp),fclose(fp); break; case '2': output_2(list2,num2),fp=fopen(" Hot Dishes .txt","w"
),i=funtion_change(list2,num2,fp),fclose(fp); break; case '3': output_2(list3,
num3),fp=fopen(" Pot .txt","w"),i=funtion_change(list3,num3,fp),fclose(fp); break;
case '4': output_2(list4,num4),fp=fopen(" staple food .txt","w"),i=funtion_change(list4,
num4,fp),fclose(fp); break; case '5': output_2(list5,num5),fp=fopen(" drink .txt","w"
),i=funtion_change(list5,num5,fp),fclose(fp); break; } } } //
Realize the deletion of dishes , Embedded function module 4: Realize the deletion of structured dishes and the reconstruction of files void del(struct dishes list[],int *p,char ch) {
int i=1; FILE *fp; while(i!=0) { switch(ch) { case '1': output_2(list1,num1),fp=
fopen(" Cold Dishes .txt","w"),i=function_del(list1,p1,fp),fclose(fp); break; case '2':
output_2(list2,num2),fp=fopen(" Hot Dishes .txt","w"),i=function_del(list2,p2,fp),fclose(
fp); break; case '3': output_2(list3,num3),fp=fopen(" Pot .txt","w"),i=function_del
(list3,p3,fp),fclose(fp); break; case '4': output_2(list4,num4),fp=fopen(
" staple food .txt","w"),i=function_del(list4,p4,fp),fclose(fp); break; case '5': output_2(
list5,num5),fp=fopen(" drink .txt","w"),i=function_del(list5,p5,fp),fclose(fp); break
; } } } // function : Add dishes , Embedded function module 5: Realize the addition of structured dishes and the reconstruction of files void add(struct dishes list[],int
*p,char ch) { int i=1; FILE *fp; while(i!=0) { switch(ch) { case '1': output_2(
list1,num1),fp=fopen(" Cold Dishes .txt","w"),i=function_add(list1,p1,fp),fclose(fp); break
; case '2': output_2(list2,num2),fp=fopen(" Hot Dishes .txt","w"),i=function_add(list2,p2,
fp),fclose(fp); break; case '3': output_2(list3,num3),fp=fopen(" Pot .txt","w"),i=
function_add(list3,p3,fp),fclose(fp); break; case '4': output_2(list4,num4),fp=
fopen(" staple food .txt","w"),i=function_add(list4,p4,fp),fclose(fp); break; case '5':
output_2(list5,num5),fp=fopen(" drink .txt","w"),i=function_add(list5,p5,fp),fclose(
fp); break; } } } /* Function module area */ // functional module 1: read txt Write to a single struct array int function_read(struct
dishes list[],FILE *fp) { int num=1;// Index from 0 start Defined as 1 Number of Statistics char t,c[max_str]; int i;
if(fp==NULL) { printf("Can't open this file\n"); exit(1); } while(!feof(fp))
// Detect end of file on stream , If file s end , Return not 0 value , Otherwise, return 0 { t=fgetc(fp); if(t=='\n') num++; } rewind(fp)
; // Reset the pointer to the first line for(i=0; i<num; i++) { fgets(c,max_str,fp); sscanf(c,"%s %d",list[
i].name,&list[i].price); } fclose(fp); return num; } // functional module 2: Realize the structure array of ordering and write data void
function_ordering(struct dishes list1[],int num1,struct dishes list2[],int *p2,
struct dishes list3[],int *p3,int choice) { strcpy(list2[*p2].name,list1[choice-
1].name); list2[*p2].price=list1[choice-1].price; strcpy(list3[*p3].name,list1[
choice-1].name); list3[*p3].price=list1[choice-1].price; *p2=*p2+1; *p3=*p3+1; }
// functional module 3: Realize the price modification and file reconstruction of structured dishes , Embedded function module 6: The modified dishes are sorted by price from low to high int funtion_change(
struct dishes list[],int num,FILE *fp) { if(fp==NULL) { printf("Can't open this
file\n"); exit(1); } int i,n; char temp[max_str],t[max_str]; printf("\n input ID:");
scanf("%d",&n); if(n==0) { for(i=0; i<num; i++) { strcpy(temp,list[i].name);
strcat(temp," "); itoa(list[i].price,t,10);
//itoa(): Converts an integer value to a string , The parameters are as follows : Content to copy , To whom , In what base . strcat(temp,t); strcat(temp,"\n");
fputs(temp,fp); } return n; } printf(" Enter the modified price :"); scanf("%d",&list[n-1].price);
function_sort(list,num); for(i=0; i<num; i++) { strcpy(temp,list[i].name);
strcat(temp," "); itoa(list[i].price,t,10);
//itoa(): Converts an integer value to a string , The parameters are as follows : Content to copy , To whom , In what base . strcat(temp,t); strcat(temp,"\n");
fputs(temp,fp); } printf(" Modification completed \n"); system("pause"); system("cls"); return 1; }
// functional module 4: Realize the deletion of structured dishes and the reconstruction of files int function_del(struct dishes list[],int *p,FILE *fp)
{ if(fp==NULL) { printf("Can't open this file\n"); exit(1); } int i,n; char temp
[max_str],t[max_str]; printf("\n Enter the dish you want to modify ID:"); scanf("%d",&n); if(n==0) { for(i
=0; i<*p; i++) { strcpy(temp,list[i].name); strcat(temp," "); itoa(list[i].price
,t,10); //itoa(): Converts an integer value to a string , The parameters are as follows : Content to copy , To whom , In what base . strcat(temp,t); strcat(temp
,"\n"); fputs(temp,fp); } return 0; } for(i=n-1; i<*p; i++) { strcpy(list[i].
name,list[i+1].name); list[i].price=list[i+1].price; } *p=*p-1; for(i=0; i<*p; i
++) { strcpy(temp,list[i].name); strcat(temp," "); itoa(list[i].price,t,10);
//itoa(): Converts an integer value to a string , The parameters are as follows : Content to copy , To whom , In what base . strcat(temp,t); strcat(temp,"\n");
fputs(temp,fp); } printf(" Deletion complete \n"); system("pause"); system("cls"); return 1; }
// functional module 5: Realize the addition of structured dishes and the reconstruction of files , Embedded function module 6: The modified dishes are sorted by price from low to high int function_add(struct
dishes list[],int *p,FILE *fp) { if(fp==NULL) { printf("Can't open this file\n")
; exit(1); } int i,n,x; char temp[max_str],t[max_str],in[max_str]; printf(
"\n input 0 0 Return to the previous level \n"); printf(" Enter the name and price of the dish , Space between :\n"); scanf("%s%d",list[*p].name,&
list[*p].price); if(list[*p].price == 0) { for(i=0; i<*p; i++) { strcpy(temp,
list[i].name); strcat(temp," "); itoa(list[i].price,t,10);
//itoa(): Converts an integer value to a string , The parameters are as follows : Content to copy , To whom , In what base . strcat(temp,t); strcat(temp,"\n");
fputs(temp,fp); } return 0; } *p=*p+1; function_sort(list,*p); for(i=0; i<*p; i
++) { strcpy(temp,list[i].name); strcat(temp," "); itoa(list[i].price,t,10);
//itoa(): Converts an integer value to a string , The parameters are as follows : Content to copy , To whom , In what base . strcat(temp,t); strcat(temp,"\n");
fputs(temp,fp); } printf(" Add complete \n"); system("pause"); system("cls"); return 1; }
// functional module 6: The modified dishes are sorted by price from low to high void function_sort(struct dishes list[],int num) {
int i,j; struct dishes t; for(j=num-1; j>0; j--) { for(i=0; i<j; i++) if(list[i]
.price>list[i+1].price) { t=list[i]; list[i]=list[i+1]; list[i+1]=t; } } }

Technology
©2020 ioDraw All rights reserved
【webpack】DLL plugin Principle analysis Combined with source code Transformer The most comprehensive , The deepest analysis filemanager-webpack-plugin Turn resources into zip Package and archive JavaScript study ( Function declaration and parameters ) mean value - Implementation and application of variance model _python_ Data analysis _9JAVA Snake games ( Source code + notes )SpringBoot integrate Redisson Implement delay queue python code , Easy to complete Snake games Thread.setDaemon Set up the Daemons Unity Code dynamic creation of preform in editor expansion function