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
|
#include "stdafx.h"
#define MAX 11
struct airplane
{
int seat;
int occupied;
char fName[20];
char lName[20];
};
int emptySeatNum(airplane passenger[], int size)
int seatList(airplane passenger[], int list);
int assignSeat(int passenger[]);
int unassignSeat();
int _tmain(int argc, _TCHAR* argv[])
{
struct airplane passenger[MAX];
int choice = 0;
int i;
int numSeats;
for(i = 1; i < MAX; i++)
{
passenger[i].seat = 0;
}
while(choice != 5)
{
printf("*** C & M Airlines ***\n");
printf("Choose a funtion\n");
printf("1) Show number of empty seats\n");
printf("2) Show list of seats\n");
printf("3) Assign a seat\n");
printf("4) Un-assign a seat\n");
printf("5) Quit\n");
//Get the choice from the user
printf("Enter your choice: ");
scanf("%d", &choice);
printf("\n");
switch(choice)
{
case 1:
numSeats = emptySeatNum(passenger, MAX);
printf("The number of available seats are %d\n", numSeats);
break;
case 2:
seatList(passenger, MAX);
break;
case 3:
assignSeat(passenger, MAX);
break;
case 4:
unassignSeat();
break;
case 5:
break;
default:
printf("That is not one of the available functions, please retry.\n");
}
}
return 0;
}
int emptySeatNum(airplane passenger[], int size)
{
int i;
int count = 0;
for(i = 0; i < size; i++)
{
printf("There are %d seats available.", passenger[i].seat);
count++;
}
return count;
}
int seatList(airplane passenger[], int size)
{
int i;
int count = 0;
for(i = 1; i < size; i++)
{
if(passenger[i].seat == 0)
{
printf("Seat #%d is not assigned.\n", i);
}
else
{
printf("Seat #%d is assigned to %d\n", passenger[i].seat, passenger[i].fName, passenger[i].lName);
}
}
}
int assignSeat(int passenger[])
{
int i;
int num;
printf("What seat number?");
scanf("%d", &num);
printf("What is the first name of the passenger? ");
scanf("%s", &passenger[num].fName);
printf("What is the last name of the passenger? ");
scanf("%s", &passenger[num].lName);
for (i = 0; i <= 12 ; i++)
{
if(passenger[i]==0)
return 1;
}
return 0;
}
|