예약시스템

언어2015. 9. 26. 23:06

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define ROW 4
#define COL 11
typedef int theater;
//0
void setting(theater(*s)[COL]);
//1
void show(theater(*s)[COL]);
//2
void reserve(theater(*s)[COL]);
int main(void)
{
 srand((unsigned)time(NULL));
 theater seat[ROW][COL] = { 0, };
 setting(seat);
 show(seat);
 reserve(seat);
 return 0;
}
//0
void setting(theater(*s)[COL])
{
 int i, j;
 // 0 1 2 3 4 5 6 7 8 9 10
 for (j = 0; j < COL; j++)
 {
  *(*(s + 0) + j) = j;
 }
 
 for (i = 1; i < ROW; i++)
 {
  *(*(s + i) + 0) = i;
 }

 for (i = 1; i < ROW; i++)
 {
  for (j = 1; j < COL; j++)
  {
   *(*(s + i) + j) = rand()%2;
  }
 }
 
}
//1
void show(theater(*s)[COL])
{
 int i, j;
 //sector 1: row(0)
 for (j = 0; j < COL; j++)
 {
  if (j == 0)
  {
   printf("    ");
   continue;
  }
  printf("%2d  ", *(*(s + 0) + j));
 }
 printf("\n");
 //sector 2:
 for (j = 0; j < COL; j++)
 {
  printf("====");
 }
 printf("\n");
 //sector 3: row(1->)
 for (i = 1; i < ROW; i++)
 {
  for (j = 0; j < COL; j++)
  {
   printf("%2d  ", *(*(s + i) + j));
  }
  printf("\n");
 }
}
//2
void reserve(theater(*s)[COL])
{
 int row_seat = 0;
 int col_seat = 0;
 int i, j;
 while (1 == 1)
 {
  while (1 == 1)
  {
   printf("어느 줄을 예약하시겠습니까  ");
   scanf_s("%d", &row_seat);
   if (row_seat<1 || row_seat>ROW)
   {
    printf("좌석줄을 잘 못 입력하셨습니다.\n");
   }
   else//row_seat>=1 && row_seat<=ROW
   {
    break;
   }
  }
  while (1 == 1)
  {
   printf("어느 좌석을 예약하시겠습니까  ");
   scanf_s("%d", &col_seat);
   if (col_seat<1 || row_seat>COL)
   {
    printf("좌석을 잘 못 입력하셨습니다.\n");
   }
   else//col_seat>=1 && col_seat<=ROW
   {
    break;
   }
  }
  if (*(*(s + row_seat) + col_seat) == 1)
  {
   printf("이미 예약 된 자리 입니다. 다시 자리를 신청합니다.\n");
  }
  else
  {
   printf("입력하신 좌석의 위치는 [row[%d] | col[%d]]\n", row_seat, col_seat);
   *(*(s + row_seat) + col_seat) = 1;
   break;
  }
 }
  
 for (j = 0; j < COL; j++)
 {
  if (j == 0)
  {
   printf("    ");
   continue;
  }
  printf("%2d  ", *(*(s + 0) + j));
 }
 printf("\n");
 //sector 2:
 for (j = 0; j < COL; j++)
 {
  printf("====");
 }
 printf("\n");
 //sector 3: row(1->)
 for (i = 1; i < ROW; i++)
 {
  for (j = 0; j < COL; j++)
  {
   printf("%2d  ", *(*(s + i) + j));
  }
  printf("\n");
 }
}

 

 

'언어' 카테고리의 다른 글

0123456789(별찍기 응용)  (0) 2015.10.03
문자 counting  (0) 2015.09.28
2*2 행렬  (0) 2015.09.26
homework  (0) 2015.09.23
네이버 지식인  (0) 2015.09.20