Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with 6 seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. You program will prompt the user to enter their ticket type, and then their userid (this will just be an arbitrary number picked by you).
This will be implemented by using a two-dimensional array. Every element in the array will be initialized to zero. You will be able to tell if a seat is open if it has a value of 0.
The program will then fill the seats from smallest to largest in the appropriate row per the ticket type. It will print to the user which seat they were given, or if all seats for that ticket type were full, it will print a message indicating all seats for that ticket type are full. If there is an open seat, the user’s userid will be placed in the array indicating that seat is taken.
Once they are done reserving seats (they enter “N” when asked if they’d like to reserve another seat), the contents of the array will be printed to show that the seats were in fact reserved as entered. An example of how the program should look is given on the next page.
what i can't seem to figure out is this part Once they are done reserving seats (they enter “N” when asked if they’d like to reserve another seat), the contents of the array will be printed to show that the seats were in fact reserved as entered. An example of how the program should look is given on the next page.
this is what i have so far.
#include <stdio.h> int printMenu(); int main() { printf("welcome to the airline reservation system\n"); int airlineSeats[13][6]={0}; int colSize=13; int rowSize=6; int ticketNumber; int reRun; int r,c; int menuChoice=printMenu(); switch(menuChoice) { case 1: for(r=0; r<=1; ++r) //This loops on the rows. { for(c=0; c<6; c++) //This loops on the columns { printf("Please enter your ticket number\n"); scanf("%i", &airlineSeats[r][c]); printf("You have been assigned to row %i seat %i\n",r+1,c+1); printf("Would you like to reserve another seat? type 1 for yes 2 for no\n"); scanf(" %i", &reRun); } } break; case 2: for(r=2; r<=6; ++r) //This loops on the rows. { for(c=0; c<6; c++) //This loops on the columns { printf("Please enter your ticket number\n"); scanf("%i", &airlineSeats[r][c]); printf("You have been assigned to row %i seat %i\n",r+1,c+1); printf("Would you like to reserve another seat? type 1 for yes 2 for no\n"); scanf(" %i", &reRun); } } break; case 3: for(r=7; r<=12; ++r) //This loops on the rows. { for(c=0; c<6; c++) //This loops on the columns { printf("Please enter your ticket number\n"); scanf("%i", &airlineSeats[r][c]); printf("You have been assigned to row %i seat %i\n",r+1,c+1); printf("Would you like to reserve another seat? type 1 for yes 2 for no\n"); scanf(" %i", &reRun); } } break; } for(r=0; r<rowSize; ++r) //This loops on the rows. { for(c=0; c<colSize; c++) //This loops on the columns { printf("%i\t", airlineSeats[r][c]); } } } int printMenu() { printf("Please enter your ticket type\n"); printf("1. First Class\n"); printf("2. Business Class\n"); printf("3. Economy Class\n"); int menuChoice; scanf("%i", &menuChoice); return menuChoice; }
This post has been edited by jimblumberg: 25 January 2013 - 07:11 AM
Reason for edit:: Fixed Code Tags.