반응형

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

typedef struct Movies
{
       int Prcie;
       char MovieName[30];
       char *Name;
}Movie;
 

#define SIZE 100;
 

void Insert(Movie **MV,int High, int Low);//끝
int NumberPut();//끝
void Run();//끝
void Print(Movie **MV, int High, int Low);//끝
void Delete(Movie **MV,int High, int Low);
void Display();//끝
void Find(Movie **MV, int High, int Low);
 

void main()
{
       Run();
}
 

void Display()
{
     printf("-------------------------------------\n");
     printf("| 0. 메뉴에서 나가기(종료)            |\n");
     printf("| 1. 영화관 좌석 예약하기             |\n");
     printf("| 2. 영화관 좌석 취소하기             |\n");
     printf("| 3. 영화관 좌석 확인하기             |\n");
     printf("| 4. 영화관 빈 좌석 보기              |\n");
     printf("--------------------------------------\n");

 

}
 

void Run()
{
      int i,N;
      Movie **MV;
      int Low,High;
      printf("영화관의 행을 입력하세요:");
      scanf("%d",&Low);
      printf("영화관의 열을 입력하세요:");
      scanf("%d",&High);

      MV=(Movie **)calloc(High,sizeof(Movie*));//포인터형 10개만큼 할당

      for(i=0;i <High;i++)
     {
            MV[i]=(Movie *)calloc(Low,sizeof(Movie));//한줄당 COMPLEX 5개 만큼 할당
      }
      fflush(stdin);
      while(1)
     {
            Display();
            N=NumberPut();

            switch(N)
           {
                   case 1:Insert(MV ,Low, High);
                         break;
                   case 2:Delete(MV, Low, High);
                         break;
                   case 3:Find(MV, Low, High);
                         break;
                   case 4:Print(MV, Low, High);
                         break;
                   case 0:exit(0);break;

            }
     }

}


int NumberPut()
{
        int N;
        printf("숫자를 눌르세요:");
        scanf("%d", &N);

        return N;
}


void Insert(Movie **MV,int High, int Low)
{
         char TempBuffer[30];
         int i,j;
         int Seat;
         int L,H;

         printf("1. 빈자리 예약 2. 원하는 좌석 예약 \n");
         scanf("%d", &Seat);
         if(Seat==1)
         {
               for(i=0; i<High; i++)
              {
                      for(j=0;j<Low; j++)
                     {
                              if(MV[i][j].Prcie == 0)
                             {
                                      fflush(stdin);
                                      printf("성함 : ");
                                      gets(MV[i][j].MovieName);


                                       printf("지불금액 : ");
                                       scanf("%d" , &MV[i][j].Prcie);

                                       fflush(stdin);
                                       printf("핸드폰 번호 :");
                                       gets(TempBuffer);
                                       MV[i][j].Name = (char*)malloc(sizeof(char)* strlen(TempBuffer)+1);
                                       strcpy( MV[i][j].Name ,  TempBuffer);
                                       puts("예약 성공 !!!!");
                                       return;
                                  }

                          }
                          puts("");
                  }
          }else
          {
                   printf("행을 입력하세요:");
                   scanf("%d",&L);
                   printf("열을 입력하세요:");
                   scanf("%d", &H);

                   fflush(stdin);
                   printf("성함 : ");
                   gets(MV[L][H].MovieName);


                   printf("지불금액 : ");
                   scanf("%d" , &MV[L][H].Prcie);

                   fflush(stdin);
                   printf("핸드폰번호 :");
                   gets(TempBuffer);
                   MV[L][H].Name = (char*)malloc(sizeof(char)* strlen(TempBuffer)+1);
                   strcpy( MV[L][H].Name ,  TempBuffer);
                   puts("예약 성공 !!!!");
                   return;

            }

 

}


void Print(Movie **MV,int Low, int High)
{
        int i,j;
        for(i=0; i<High; i++)
       {
                for(j=0;j<Low; j++)
               {
                      if(MV[i][j].Prcie!=0)
                     {
                            printf("[X]");
                     }
                     else
                    {
                             printf("[0]");
                     }
   
               }
               puts("");
       }

}

void Delete(Movie **MV,int High, int Low)
{
         int i,j;
         char name[20];
         char a[1]={0};

         printf("이름 입력하세요:");
         scanf("%s", name);
         for(i=0; i<High; i++)
        {
                 for(j=0; j<Low; j++)
                {
                         if(MV[i][j].MovieName !=NULL && (strcmp(MV[i][j].MovieName, name)==0))
                        {
                                 strcpy(MV[i][j].MovieName ,a);
                                 strcpy(MV[i][j].Name ,a);
                                 MV[i][j].Prcie = 0; 
                         }
                 }
        }
        puts("예약을 취소 하였습니다");

}


void Find(Movie **MV,int High, int Low)
{
        int i,j;
        char name[20];

        printf("이름을 입력하세요:");
        scanf("%s", name);
        puts("+++++++++++++++++++++++++++++++++++++++");
        printf("가격   전화번호     성함    좌석 번호\n");
        puts("---------------------------------------");
        for(i=0; i<High; i++)
       {
               for(j=0; j<Low; j++)
              {
                      if(MV[i][j].MovieName !=NULL && (strcmp(MV[i][j].MovieName, name)==0))
                     {
                           printf("%d %s %s %d행의 %d열 자리 입니다.\n",MV[i][j]. Prcie,MV[i][j]. Name,MV[i][j].MovieName,i,j);
                      }
                     else
                    {
                           printf("존재하지 않는 이름입니다\n");
                           exit(0);
                      }
                }
 }
 puts("+++++++++++++++++++++++++++++++++++++++");

  /*
  printf("행을 입력하세요:");
  scanf("%d",&i);
  printf("행을 입력하세요:");
  scanf("%d",&j);

  printf("%d %s %s \n",MV[i][j]. Prcie,MV[i][j]. Name,MV[i][j].MovieName);
  */
}

반응형