1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <stdio.h>
#include <string.h>
struct flight_date {
int day;
int month;
int year;
};
struct flight_time {
int hour;
int minute;
};
struct flight_information {
char flight_num[4];
struct flight_date date;
struct flight_time time;
char gate[2];
}flight_info;
main()
{
int seat[4][5] = {0};
int i,j,choice,num_of_seat,empty_seat=0,row,col,x=4,y=5,z=0;
int booking_id ;
char name[20];
strcpy(flight_info.flight_num, "AK65");
strcpy(flight_info.gate, "G9");
flight_info.date.day = 25;
flight_info.date.month = 12;
flight_info.date.year = 2008;
flight_info.time.hour = 23;
flight_info.time.minute = 45;
printf("------Airline Reservation Menu------\n\n\n");
printf("Press \"1\" -\tBooking\n");
printf("Press \"2\" -\tDisplay Seat Layout & Occupancy\n");
printf("Press \"3\" -\tExit\n");
printf("\nEnter your choice > ");
scanf("%d", &choice);
printf("\n");
switch (choice)
{
case 1:
printf("Amount of seat : ");
scanf("%d", &num_of_seat);
for (i=0; i<4; i++)
{
for (j=0; j<5; j++)
{
if (seat[i][j] == 0)
empty_seat += 1;
}
}
if (num_of_seat > empty_seat)
{
printf("Not enough seats available!\n");
break;
}
else
booking_id = 101;
fflush(stdin);
printf("Please enter your name : ");
scanf("%19[^\n]s", &name);
for (i=0; i<4; i++)
{
for (j=0; j<5; j++)
{
switch(num_of_seat)
{
case 1:
case 2:
case 3:
case 4:
case 5:
seat[i][num_of_seat-1] = booking_id;
break;
case 6:
seat[i+1][num_of_seat-5] = booking_id;
break;
}
}
}
printf("%d\t", seat[0][0]);
printf("%d\t", seat[0][1]);
printf("%d\t", seat[0][2]);
printf("%d\t", seat[0][3]);
printf("%d\t\n", seat[0][4]);
printf("%d\t", seat[1][0]);
printf("%d\t", seat[1][1]);
printf("%d\t", seat[1][2]);
printf("%d\t", seat[1][3]);
printf("%d\t\n", seat[1][4]);
printf("%d\n", booking_id);
break;
case 2:
seat[2][0] = 101;
printf("\tA\tB\tC\tD\tE\n");
for (row=0; row<4; row++)
{
printf("\n%d", row+1);
for (col=0; col<5; col++)
{
printf("\t%d", seat[row][col]);
}
}
break;
case 3:
printf("Bye bye !\nHave A Nice Day !");
break;
default:
printf("Unknown choice , please read the instructions again !");
}
printf("\n\n");
}
|