25-01-2016, 02:37 PM
airline reservation in c code using linkedlist stack queue
#include<stdio.h>
#include<ctype.h>
#define MAX_NUM_SEATS (20)
#define MAX_NUM_SEATS_IN_FIRST_CLASS (5)
#define MAX_NUM_SEATS_IN_ECONOMY (MAX_NUM_SEATS - MAX_NUM_SEATS_IN_FIRST_CLASS)
int main()
{
int plane[MAX_NUM_SEATS] = {0}, i=0;
int nNumSeatsInFirst = 0;
int nNumSeatsInEconomy = 0;
int nSeatAssignmentFirstClass = 1; // start at 1;
int nSeatAssignmentEconomy = MAX_NUM_SEATS_IN_FIRST_CLASS + 1; // start at 6
int choice;
int nClass;
int nCurrentSeatAssignment;// firstClass=1,economy=6,choice;
char response[2];
char firstname[35], lastname[35];
int bPrintTicket;
while( i < MAX_NUM_SEATS )
{
printf("\n%s\n%s\n", "Please type 1 for \"First class\"","Please type 2 for\"Economy\"");
scanf("%d", &choice);
if( !( ( 1 == choice ) || ( 2 == choice ) ) )
{
continue;
}
// start out assuming we will print ticket!
bPrintTicket = 1;
printf("\nEnter first name:");
scanf("%s",firstname);
printf("\nEnter lastname :");
scanf("%s", lastname);
nClass = choice; // store the class before doing all the logical checks
/****************************************************************/
/*************** ECONOMY SECTION ***************/
/****************************************************************/
if( 2 == choice )
{
// check for economy full
if( nNumSeatsInEconomy >= MAX_NUM_SEATS_IN_ECONOMY )
{
// economy full
// check for first class (plane ) full
if( nNumSeatsInFirst <= MAX_NUM_SEATS_IN_FIRST_CLASS )
{
printf("The economy section is full.\n");
printf("would you like to sit in first class ");
printf("section( Y or N)?");
scanf("%s", response);
if ( toupper(response[0])=='Y')
{
// print ticket!
bPrintTicket = 1;
printf( "Your seat assignment is %d\n", nSeatAssignmentFirstClass );
nCurrentSeatAssignment = nSeatAssignmentFirstClass;
plane[nSeatAssignmentFirstClass - 1] = 1;
nSeatAssignmentFirstClass++;
nNumSeatsInFirst++;
nClass = 1;
i++;
}
else
{
// don't print ticket!
bPrintTicket = 0;
printf("Next flight leaves in 3 hours.\n");
}
}
else
{
// don't print ticket!
bPrintTicket = 0;
// print out that plane is full
printf("Plane is full, next flight in 3 hours\n");
}
}
else
{
// economy is not full
printf("Your seat assignment is %d\n", nSeatAssignmentEconomy );
plane[(nSeatAssignmentEconomy - 1)] = 1;
nCurrentSeatAssignment = nSeatAssignmentEconomy;
nSeatAssignmentEconomy++;
nNumSeatsInEconomy++;
i++;
}
} // if( choice == 2 )
/****************************************************************/
/*************** FIRST CLASS SECTION ***************/
/****************************************************************/
if( 1 == choice )
{
// check for fisrt class full
if( nNumSeatsInFirst >= MAX_NUM_SEATS_IN_FIRST_CLASS )
{
// first class full
// check for economy class (plane) full
if( nNumSeatsInEconomy <= MAX_NUM_SEATS_IN_ECONOMY )
{
printf("The First Class section is full.\n");
printf("Would you like to sit in the economy ");
printf("section (Y or N)?");
scanf("%s", response);
if(toupper(response[0])=='Y')
{
printf("Your seat assignment is %d\n",nSeatAssignmentEconomy);
plane[nSeatAssignmentEconomy - 1] = 1;
nCurrentSeatAssignment = nSeatAssignmentEconomy;
nSeatAssignmentEconomy++;
nNumSeatsInEconomy++;
i++;
nClass = 2;
}
else
{
// don't print ticket!
bPrintTicket = 0;
printf("Next flight leaves in 3 hours.\n");
}
}
else
{
// don't print ticket!
bPrintTicket = 0;
// print out that plane is full
printf("Plane is full, next flight in 3 hours\n");
}
}
else
{
// first is not full
printf("Your seat assignment is %d\n", nSeatAssignmentFirstClass );
plane[(nSeatAssignmentFirstClass - 1)] = 1;
nCurrentSeatAssignment = nSeatAssignmentFirstClass;
nSeatAssignmentFirstClass++;
nNumSeatsInFirst++;
i++;
}
}
if( 1 == bPrintTicket )
{
printf(" ****************************************\n");
printf(" * *\n");
printf(" NAME:%s, %s \n",lastname,firstname);
printf(" * *\n");
printf(" CLASS:%d \n",nClass);
printf(" * *\n");
printf(" SEAT:%d \n",nCurrentSeatAssignment);
printf(" * *\n");
printf(" \n");
printf(" ****************************************\n");
}
}
printf("\nAll the seats for this flight are sold\n");
return 0;
}
#include<stdio.h>
#include<ctype.h>
#define MAX_NUM_SEATS (20)
#define MAX_NUM_SEATS_IN_FIRST_CLASS (5)
#define MAX_NUM_SEATS_IN_ECONOMY (MAX_NUM_SEATS - MAX_NUM_SEATS_IN_FIRST_CLASS)
int main()
{
int plane[MAX_NUM_SEATS] = {0}, i=0;
int nNumSeatsInFirst = 0;
int nNumSeatsInEconomy = 0;
int nSeatAssignmentFirstClass = 1; // start at 1;
int nSeatAssignmentEconomy = MAX_NUM_SEATS_IN_FIRST_CLASS + 1; // start at 6
int choice;
int nClass;
int nCurrentSeatAssignment;// firstClass=1,economy=6,choice;
char response[2];
char firstname[35], lastname[35];
int bPrintTicket;
while( i < MAX_NUM_SEATS )
{
printf("\n%s\n%s\n", "Please type 1 for \"First class\"","Please type 2 for\"Economy\"");
scanf("%d", &choice);
if( !( ( 1 == choice ) || ( 2 == choice ) ) )
{
continue;
}
// start out assuming we will print ticket!
bPrintTicket = 1;
printf("\nEnter first name:");
scanf("%s",firstname);
printf("\nEnter lastname :");
scanf("%s", lastname);
nClass = choice; // store the class before doing all the logical checks
/****************************************************************/
/*************** ECONOMY SECTION ***************/
/****************************************************************/
if( 2 == choice )
{
// check for economy full
if( nNumSeatsInEconomy >= MAX_NUM_SEATS_IN_ECONOMY )
{
// economy full
// check for first class (plane ) full
if( nNumSeatsInFirst <= MAX_NUM_SEATS_IN_FIRST_CLASS )
{
printf("The economy section is full.\n");
printf("would you like to sit in first class ");
printf("section( Y or N)?");
scanf("%s", response);
if ( toupper(response[0])=='Y')
{
// print ticket!
bPrintTicket = 1;
printf( "Your seat assignment is %d\n", nSeatAssignmentFirstClass );
nCurrentSeatAssignment = nSeatAssignmentFirstClass;
plane[nSeatAssignmentFirstClass - 1] = 1;
nSeatAssignmentFirstClass++;
nNumSeatsInFirst++;
nClass = 1;
i++;
}
else
{
// don't print ticket!
bPrintTicket = 0;
printf("Next flight leaves in 3 hours.\n");
}
}
else
{
// don't print ticket!
bPrintTicket = 0;
// print out that plane is full
printf("Plane is full, next flight in 3 hours\n");
}
}
else
{
// economy is not full
printf("Your seat assignment is %d\n", nSeatAssignmentEconomy );
plane[(nSeatAssignmentEconomy - 1)] = 1;
nCurrentSeatAssignment = nSeatAssignmentEconomy;
nSeatAssignmentEconomy++;
nNumSeatsInEconomy++;
i++;
}
} // if( choice == 2 )
/****************************************************************/
/*************** FIRST CLASS SECTION ***************/
/****************************************************************/
if( 1 == choice )
{
// check for fisrt class full
if( nNumSeatsInFirst >= MAX_NUM_SEATS_IN_FIRST_CLASS )
{
// first class full
// check for economy class (plane) full
if( nNumSeatsInEconomy <= MAX_NUM_SEATS_IN_ECONOMY )
{
printf("The First Class section is full.\n");
printf("Would you like to sit in the economy ");
printf("section (Y or N)?");
scanf("%s", response);
if(toupper(response[0])=='Y')
{
printf("Your seat assignment is %d\n",nSeatAssignmentEconomy);
plane[nSeatAssignmentEconomy - 1] = 1;
nCurrentSeatAssignment = nSeatAssignmentEconomy;
nSeatAssignmentEconomy++;
nNumSeatsInEconomy++;
i++;
nClass = 2;
}
else
{
// don't print ticket!
bPrintTicket = 0;
printf("Next flight leaves in 3 hours.\n");
}
}
else
{
// don't print ticket!
bPrintTicket = 0;
// print out that plane is full
printf("Plane is full, next flight in 3 hours\n");
}
}
else
{
// first is not full
printf("Your seat assignment is %d\n", nSeatAssignmentFirstClass );
plane[(nSeatAssignmentFirstClass - 1)] = 1;
nCurrentSeatAssignment = nSeatAssignmentFirstClass;
nSeatAssignmentFirstClass++;
nNumSeatsInFirst++;
i++;
}
}
if( 1 == bPrintTicket )
{
printf(" ****************************************\n");
printf(" * *\n");
printf(" NAME:%s, %s \n",lastname,firstname);
printf(" * *\n");
printf(" CLASS:%d \n",nClass);
printf(" * *\n");
printf(" SEAT:%d \n",nCurrentSeatAssignment);
printf(" * *\n");
printf(" \n");
printf(" ****************************************\n");
}
}
printf("\nAll the seats for this flight are sold\n");
return 0;
}