Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Help with Airline Reservation Project in C

$
0
0
I was given an assignment with the following parameters:

The Cape Fear Airlines has one plane with a seating capacity of 12. It makes one flight daily. Write a seating reservation program with the following features:

The program uses a group of arrays. The four arrays should hold a seat ID number, a marker that indicates whether the seat is assigned, the last name of the seat holder, and the first name of the seat holder.

The program displays the following menu:
To choose a function, enter its number:
1. Show the number of empty seats
2. Show a list of empty seats
3. Show by last name an alphabetical list of assigned seats
4. Assign a customer to a seat
5. Delete a seat assignment
6. Quit

The menu should be displayed after each choice except for choice 6.


I have everything working with the exception of:

2. Show a list of empty seats and 5. Delete a seat assignment


My partially working code is as follows:
//final
//airline reservation
//taddei

#include <stdio.h>
#include <ctype.h>
#include <string.h>

void instructions(void);
int getValue(void);
void menu(int);
void available(void);
void list(void);
void assign(void);
void delete(void);


int assigned[12]={0};
char seatID[12][3] = {"A1","A2","A3","A4","A5","A6","B1","B2","B3","B4","B5","B6"};
char lastName[12][15];
char firstName[12][15];

int main(void)
{
	int choice;

	instructions();

	do
	{
		printf("1. Number Avaliable 2. List Available\n");
		
		printf("3. List Names       4. Assign Seat\n");
		
		printf("5. Delete seat      6. QUIT\n\n");
		
		choice = getValue();
		menu(choice);
	}while(choice != 6);
	
	return 0;
}


///////////////////instructions/////////////////

void instructions(void)
{
	printf("This is an airline reservation program\n");
	printf("Please make a menu selection 1-6:\n\n");
}

int getValue(void)
{
	int value;
	
	do
	{
		scanf("%d", &value);
	}while(value > 12);
	
	return value;
}

void menu(int input)
{
	int temp = 0;

	switch(input)
	{
		case 1:
			for(int i = 0; i < 12; i++)
			{
				if(assigned[i] == 0)
					temp++;
			}
			printf("There are %d available seats\n\n", temp);
			break;
			
		case 2:
			available();
			break;
			
		case 3:
			list();
			break;
			
		case 4:
			assign();
			break;
			
		case 5:
			delete();
			break;
			
		case 6:
			
			break;

		default:
			printf("Be sure to enter a valid choice!\n");
	}
}

////////////////////////list available seats//////////////////

void available(void)
{
	printf("Available seats:\n");
	printf("________________\n");
	for(int i=0; i < 12; i++)
	{
		if( assigned[i] == 0 )
		{			
			printf("%s\n",seatID[i]);
		}
	}
}

////////////////////list NOT WORKING!!//////////////////////////

void list(void)
{
	char array[3][12][15];
	int c = 0;
	int max = 0;

	for(int i = 0; i < 12; i++)
	{
		if(assigned[i] > 0)
		{
			max++;
			strcpy(array[0][c], seatID[i]);
			strcpy(array[1][c], lastName[i]);
			strcpy(array[2][c], firstName[i]);
			c++;
		}
		printf("%d\n", max);
	}
			for(int x = 0; x < 3; x++)
				for(int y = 0; y < 2; y++)
					if(strcmp(array[1][y],array[1][y+1]) > 0)
					{
						char temp[15];

						strcpy(temp, array[1][y]);
						strcpy(array[1][y], array[1][y + 1]);
						strcpy(array[1][y + 1], temp);

						strcpy(temp, array[2][y]);
						strcpy(array[2][y], array[2][y + 1]);
						strcpy(array[2][y + 1], temp);

						strcpy(temp, array[0][y]);
						strcpy(array[0][y], array[0][y + 1]);
						strcpy(array[0][y + 1], temp);
					}
	for(int i = 0; i < max; i++)
	{
		printf("%s, %s,  %s\n",array[1][i], array[2][i], array[0][i]);
	}
}

////////////////////assign seat/////////////////

void assign(void)
{
	char column;
	int seat;

	for(int i = 0; i < (12 / 2); i++)
	{
		printf("A%d		B%d\n", i + 1, i + 1);
	}
	printf("Select row A or B:  ");
	fflush(stdin);
	column=getchar();
	printf("Select a seat number 1-6:  ");
	seat=getValue();
	if(toupper(column)=='A')
	{
		printf("Enter first and last name:  ");
		scanf("%s %s", firstName[seat - 1], lastName[seat - 1]);
		assigned[seat-1]++;
	}
	if(toupper(column)=='B')
	{
		printf("Enter first and last name:  ");
		scanf("%s %s", firstName[seat+(12 / 2) -1], lastName[seat+(12 / 2) -1]);
		assigned[seat + (12 / 2)-1]++;
	}
}



/////////////////////delete a seat/////////////////

void delete(void)
{
	int x = 0;
	
	printf("Enter seat ID:  \n");

	for(int i = 0; i < 12; i++)
	{
		printf("%d	%s", x + 1, seatID[i]);

		if(assigned[i] < 1)
		{
			printf("%s, %s\n", lastName[i], firstName[i]);
		}else
		{
			printf("\n");
		}
		x++;
	}

	x = getValue();

	assigned[x - 1] = 0;
}




Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>