C 언어 는 음식 관리 와 주문 시스템 을 실현 한다.
프로젝트 소개
1.이 프로그램 은 사용자 의 주문 기능 을 실 현 했 고 모두 다섯 가지 요 리 를 포함한다.냉채,뜨 거 운 요리,냄비,주식,음료.주문 한 메뉴 와 끝 을 확인 하 는 기능 도 있다.
2.백 스테이지 관리자:a 를 누 르 면 들 어 갈 수 있 고 홈 페이지 에 알림 이 없습니다.
3.getch 함 수 를 합 리 적 으로 활용 하고 스크린 과 일시 정지 함 수 를 사용 하 며 페이지 가 깨끗 하고 시원 합 니 다.
4.요리 와 txt 파일 이 대응 하여 프로그램 과 txt 의 동기 화 첨삭 검사 등 기능 을 실현 할 수 있 습 니 다.
5.C 언어의 많은 기초 문법:함수,지침,구조 체,파일 등 을 사 용 했 습 니 다.
절차 설명
프로그램 이 실 행 된 후 홈 페이지 에서 a 를 누 르 고 배경 관리 페이지 에 들 어가 해당 메뉴 정보 에 메뉴 를 추가 합 니 다.이런 정 보 는 txt 에 자동 으로 저장 되 고 다음 에 열 때 도 자동 으로 읽 습 니 다.메뉴 정 보 를 만 드 는 작업 을 잘 하면 홈 페이지 로 돌아 가 해당 하 는 사용자 주문 작업 을 할 수 있 습 니 다.
기능 데모
 
 
 
 사고 지도
 프로그램 코드
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
/*    */
#define max_str 30 //       
#define max_num 30 //      
#define max_all 100 //         
/*       */
struct dishes
{
 char name[max_str];
 int price;
};
/*      */
struct dishes list1[max_num]; //        
int num1=0; //        
int *p1=&num1;
struct dishes list2[max_num]; //        
int num2=0; //        
int *p2=&num2;
struct dishes list3[max_num]; //        
int num3=0; //        
int *p3=&num3;
struct dishes list4[max_num]; //        
int num4=0; //        
int *p4=&num4;
struct dishes list5[max_num]; //        
int num5=0; //        
int *p5=&num5;
struct dishes list6[max_num]; //          
int num6=0; //          
int *p6=&num6;
struct dishes list7[max_all]; //           
int num7=0; //           
int *p7=&num7;
/*    */
/*     */
//     
char menu_m1();
//        
char menu_a1();
//        :          
char menu_a2();
//    1(        )
void output_1(struct dishes list[],int num);
//      2(         )
void output_2(struct dishes list[],int num);
/*  */
//         txt  
void creat_file();
//            ,      1:  txt           
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);
//       ,      2:              
void ordering(struct dishes list1[],int num1,struct dishes list2[],int *p2,struct dishes list3[],int *p3);
//           
void settlement(struct dishes list[],int num);
//       
void income(struct dishes list[],int num);
//          ,      3:                  
void change(struct dishes list[],int *p,char ch);
//        ,      4:                
void del(struct dishes list[],int *p,char ch);
//   :       ,      5:                
void add(struct dishes list[],int *p,char ch);
/*     */
//    1:  txt           
int function_read(struct dishes list[],FILE *fp);
//    2:              
void function_ordering(struct dishes list1[],int num1,struct dishes list2[],int *p2,struct dishes list3[],int *p3,int choice);
//     3:                  ,      6:                    
int funtion_change(struct dishes list[],int num,FILE *fp);
//    4:                
int function_del(struct dishes list[],int *p,FILE *fp);
//    5:                ,,      6:                    
int function_add(struct dishes list[],int *p,FILE *fp);
//     6:                    
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");
 }
}
/*     */
//     
char menu_m1()
{
 char ch;
 printf("    ---------------------------
");
 printf("   |           |
");
 printf("   |           |
");
 printf("    ---------------------------
");
 printf("   |  1       |
");
 printf("   |  2       |
");
 printf("   |  3       |
");
 printf("   |  4       |
");
 printf("   |  5       |
");
 printf("   |  6       |
");
 printf("   |  y       |
");
 printf("    ---------------------------
");
 printf("       :");
 ch=getch();
 return ch;
}
//        
char menu_a1()
{
 char ch;
 printf("
-------------------------------
");
 printf("\t1\t    \t
");
 printf("\t2\t    \t
");
 printf("\t3\t    \t
");
 printf("\t4\t    \t
");
 printf("\t0\t     \t
");
 printf("-------------------------------
");
 printf("    :");
 ch=getch();
 return ch;
}
//        :          
char menu_a2()
{
 char ch;
 printf("
-------------------------------
");
 printf("\t1\t  \t
");
 printf("\t2\t  \t
");
 printf("\t3\t  \t
");
 printf("\t4\t  \t
");
 printf("\t5\t  \t
");
 printf("\t0\t     \t
");
 printf("-------------------------------
");
 printf("    :");
 ch=getch();
 return ch;
}
//    1(        )
void output_1(struct dishes list[],int num)
{
 int i;
 printf("
-------------------------------------------------
");
 printf("|\t  \t  \t\t  \t\t|
");
 printf("-------------------------------------------------
");
 for(i=0; i<num; i++)
 {
  if(strlen(list[i].name)<=6)
   printf("|\t%d\t%s\t\t%d\t\t|
",i+1,list[i].name,list[i].price);
  else
   printf("|\t%d\t%s\t%d\t\t|
",i+1,list[i].name,list[i].price);
 }
 printf("|\t0\t  \t\t\t\t|
");
 printf("-------------------------------------------------
");
 printf("     :
");
}
//      2(         )
void output_2(struct dishes list[],int num)
{
 int i;
 printf("
-------------------------------------------------
");
 printf("|\t  \t  \t\t  \t\t|
");
 printf("-------------------------------------------------
");
 for(i=0; i<num; i++)
 {
  if(strlen(list[i].name)<=6)
   printf("|\t%d\t%s\t\t%d\t\t|
",i+1,list[i].name,list[i].price);
  else
   printf("|\t%d\t%s\t%d\t\t|
",i+1,list[i].name,list[i].price);
 }
 printf("|\t0\t  \t\t\t\t|
");
 printf("-------------------------------------------------
");
}
/*  */
//         txt  
void creat_file()
{
 FILE *fp=fopen("  .txt","a");
 if(fp==NULL)
  return;
 fclose(fp);
 fp=fopen("  .txt","a");
 if(fp==NULL)
  return;
 fclose(fp);
 fp=fopen("  .txt","a");
 if(fp==NULL)
  return;
 fclose(fp);
 fp=fopen("  .txt","a");
 if(fp==NULL)
  return;
 fclose(fp);
 fp=fopen("  .txt","a");
 if(fp==NULL)
  return;
 fclose(fp);
}
//            ,      1:  txt           
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("  .txt","r");
 *p1=function_read(list1,fp);
 fp=fopen("  .txt","r");
 *p2=function_read(list2,fp);
 fp=fopen("  .txt","r");
 *p3=function_read(list3,fp);
 fp=fopen("  .txt","r");
 *p4=function_read(list4,fp);
 fp=fopen("  .txt","r");
 *p5=function_read(list5,fp);
 fclose(fp);
}
//       ,      2:              
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("      ,     :
");
 }
}
//           
void settlement(struct dishes list[],int num)
{
 int i,sum;
 for(i=0,sum=0; i<num; i++)
  sum+=list[i].price;
 printf("
-------------------------------------------------
");
 printf("|\t  \t  \t\t  \t\t|
");
 printf("-------------------------------------------------
");
 for(i=0; i<num; i++)
 {
  if(strlen(list[i].name)<=6)
   printf("|\t%d\t%s\t\t%d\t\t|
",i+1,list[i].name,list[i].price);
  else
   printf("|\t%d\t%s\t%d\t\t|
",i+1,list[i].name,list[i].price);
 }
 printf("-------------------------------------------------
");
 printf("    :%d
",sum);
}
//       
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("     :%d
",sum);
}
//          ,      3:                  
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("  .txt","w"),i=funtion_change(list1,num1,fp),fclose(fp);
   break;
  case '2':
   output_2(list2,num2),fp=fopen("  .txt","w"),i=funtion_change(list2,num2,fp),fclose(fp);
   break;
  case '3':
   output_2(list3,num3),fp=fopen("  .txt","w"),i=funtion_change(list3,num3,fp),fclose(fp);
   break;
  case '4':
   output_2(list4,num4),fp=fopen("  .txt","w"),i=funtion_change(list4,num4,fp),fclose(fp);
   break;
  case '5':
   output_2(list5,num5),fp=fopen("  .txt","w"),i=funtion_change(list5,num5,fp),fclose(fp);
   break;
  }
 }
}
//        ,      4:                
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("  .txt","w"),i=function_del(list1,p1,fp),fclose(fp);
   break;
  case '2':
   output_2(list2,num2),fp=fopen("  .txt","w"),i=function_del(list2,p2,fp),fclose(fp);
   break;
  case '3':
   output_2(list3,num3),fp=fopen("  .txt","w"),i=function_del(list3,p3,fp),fclose(fp);
   break;
  case '4':
   output_2(list4,num4),fp=fopen("  .txt","w"),i=function_del(list4,p4,fp),fclose(fp);
   break;
  case '5':
   output_2(list5,num5),fp=fopen("  .txt","w"),i=function_del(list5,p5,fp),fclose(fp);
   break;
  }
 }
}
//   :       ,      5:                
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("  .txt","w"),i=function_add(list1,p1,fp),fclose(fp);
   break;
  case '2':
   output_2(list2,num2),fp=fopen("  .txt","w"),i=function_add(list2,p2,fp),fclose(fp);
   break;
  case '3':
   output_2(list3,num3),fp=fopen("  .txt","w"),i=function_add(list3,p3,fp),fclose(fp);
   break;
  case '4':
   output_2(list4,num4),fp=fopen("  .txt","w"),i=function_add(list4,p4,fp),fclose(fp);
   break;
  case '5':
   output_2(list5,num5),fp=fopen("  .txt","w"),i=function_add(list5,p5,fp),fclose(fp);
   break;
  }
 }
}
/*     */
//    1:  txt           
int function_read(struct dishes list[],FILE *fp)
{
 int num=1;//   0      1    
 char t,c[max_str];
 int i;
 if(fp==NULL)
 {
  printf("Can't open this file
");
  exit(1);
 }
 while(!feof(fp)) //          ,    s  ,    0 ,    0
 {
  t=fgetc(fp);
  if(t=='
')
   num++;
 }
 rewind(fp); //         
 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;
}
//    2:              
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;
}
//     3:                  ,      6:                    
int funtion_change(struct dishes list[],int num,FILE *fp)
{
 if(fp==NULL)
 {
  printf("Can't open this file
");
  exit(1);
 }
 int i,n;
 char temp[max_str],t[max_str];
 printf("
  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():          ,     :      ,    ,     。
   strcat(temp,t);
   strcat(temp,"
");
   fputs(temp,fp);
  }
  return n;
 }
 printf("        :");
 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():          ,     :      ,    ,     。
  strcat(temp,t);
  strcat(temp,"
");
  fputs(temp,fp);
 }
 printf("    
");
 system("pause");
 system("cls");
 return 1;
}
//    4:                
int function_del(struct dishes list[],int *p,FILE *fp)
{
 if(fp==NULL)
 {
  printf("Can't open this file
");
  exit(1);
 }
 int i,n;
 char temp[max_str],t[max_str];
 printf("
         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():          ,     :      ,    ,     。
   strcat(temp,t);
   strcat(temp,"
");
   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():          ,     :      ,    ,     。
  strcat(temp,t);
  strcat(temp,"
");
  fputs(temp,fp);
 }
 printf("    
");
 system("pause");
 system("cls");
 return 1;
}
//    5:                ,      6:                    
int function_add(struct dishes list[],int *p,FILE *fp)
{
 if(fp==NULL)
 {
  printf("Can't open this file
");
  exit(1);
 }
 int i,n,x;
 char temp[max_str],t[max_str],in[max_str];
 printf("
  0 0     
");
 printf("        ,        :
");
 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():          ,     :      ,    ,     。
   strcat(temp,t);
   strcat(temp,"
");
   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():          ,     :      ,    ,     。
  strcat(temp,t);
  strcat(temp,"
");
  fputs(temp,fp);
 }
 printf("    
");
 system("pause");
 system("cls");
 return 1;
}
//     6:                    
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;
   }
 }
}이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C 언어 체인 시계는 뱀을 탐식하는 작은 게임을 실현한다본고의 실례는 여러분에게 C 언어 체인표가 뱀 탐식 게임을 실현하는 구체적인 코드를 공유하여 참고하도록 하였으며, 구체적인 내용은 다음과 같다. 프로젝트 이름: 뱀놀이 운영 환경: Linux 프로그래밍 언어: C 언...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.