Help with Airplane Reservation Project

Hello everyone,

I'm currently working a project for class and I am stuck. I am a complete newbie when it comes to programming and I am trying my best, so if my code looks off, please let me know where I am going wrong. Anyways here are the guidelines for my project:

This program will allow the user to keep track of airline reservations. The program should display the seating chart for the airplane. It will use an * to indicate a seat is taken and the # to indicate the seat is available. The program will also display a menu which provides the user with several options. There will be two types of seats in the airplane: first class and coach, each of which will have a different cost. The program must make use of files, arrays and functions.

The airplane will have 5 rows in the first class section with 4 seats in each row, 2 on each side of the aisle and 10 rows in the coach section with 3 seats on each side of the aisle. The prices for all the first class seats will be the same. The first 5 rows of coach will be more expensive than the last 5 rows. The prices for the seats will be stored in a file called SeatPrices.txt . The program should read these values from the file and store the values in an array of doubles. This is an example of the seating chart:
12 34
Row 1 ## ##
Row 2 ## ##
Row 3 ## ##
Row 4 ## ##
Row 5 ## ##
123 456
Row 6 ### ###
Row 7 ### ###
Etc.

The menu will provide choices to reserve a seat(s) and display the total number of seats sold (indicating first class and coach), the total number of seats empty in a row, the total number of seats empty in the plane (indicating first class and coach), and the total amount of sales (in dollars).

Validation: The seat requested by the user is a valid row and seat number. The program should also make sure the seat is not already taken.

SeatPrices.txt

==============================================================================

I am mainly having problem with my output for the seating chart, I don't know how to get the values of the array to show up as # and *. Can anyone please help me out with this???

#include <iostream>
#include <iomanip>
#include <fstream> // allows for the importing of file.
#include <string>

using namespace std;

// Constants

const int FirstCOLS = 4; // Columns for First class
const int FirstROWS = 5; // Rows for First class

const int CoachCOLS = 6; // Columns for Coach class
const int CoachROWS = 5; // Rows for Coach class


//const string Avail = "#"; // Available
//const string Taken = "*"; // Taken

// Function prototypes

void seatChart(double FirstArray[FirstROWS][FirstCOLS], double Coach1Array [CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS]);

void displayMenu(double, double FirstArray[FirstROWS][FirstCOLS], double Coach1Array[CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS]);

int main()
{


// Variables

double choice = 0;

const int FIRSTCLASS = 1,
FIRSTCOACH= 2,
SECONDCOACH = 3,
DISPLAYSEAT = 4,
EXIT = 5;

//int fcrow, fccol; // first class rows and columns inputs
//int fccrow, fcccol; // first coach class row and columns inputs
//int scrow, sccol; // second coach class row and column inputs

//double seatssold, seatsremainrow, totalsales, totalempty;

// Arrays

double FirstArray[FirstROWS][FirstCOLS];
double Coach1Array[CoachROWS][CoachCOLS];
double Coach2Array[CoachROWS][CoachCOLS];

// intro

cout << "Welcome to my Airline Seat Reservation System" << endl;
cout << "============================================= \n" << endl;

//seatChart(FirstArray, Coach1Array, Coach2Array);

displayMenu(choice, FirstArray,Coach1Array,Coach2Array);

return 0;
}


// This is a function to display the menu

void displayMenu(double, double FirstArray[FirstROWS][FirstCOLS], double Coach1Array[CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS])
{
// Variables

int CHOICE;

int fcrow, fccol; // first class rows and columns inputs
int fccrow, fcccol; // first coach class row and columns inputs
int scrow, sccol; // second coach class row and column inputs

const int FIRSTCLASS = 1,
FIRSTCOACH = 2,
SECONDCOACH = 3,
DISPLAYSEAT = 4,
EXIT = 5;

double firstprice;
double coach1price;
double coach2price;

cout << "Please pick from the following options: 1-5" << endl;
cout << "======================================" << endl;

cout << "1. First Class" << endl;
cout << "2. First Coach Class" << endl;
cout << "3. Second Coach Class" << endl;
cout << "4. Display Available seating" << endl;
cout << "5. Exit\n" << endl;
cin >> CHOICE;

//Opens input files

ifstream inputFile;
inputFile.open("SeatPrices.txt");

// Checks for failure.

if (inputFile.fail())
{
cout << "Sorry File does not exist or can not be found.\n";
exit(1);
}

// read the numbers and load them into doubles

inputFile >> firstprice;
inputFile >> coach1price;
inputFile >> coach2price;

// closing file

inputFile.close();

// Switch statement

switch (CHOICE)
{
case FIRSTCLASS :
cout << "You have chosen: First Class" << endl;
cout << "\nThe price of a ticket for First Class is:" << firstprice << endl;
cout << "\nNow please pick which row you would like to sit in: (1-5) ";
cin >> fcrow;

if (fcrow > 5)
{
cout << "\nYou have entered an invalid row number, please enter in between 1-5 ";
cin >> fcrow;
}

cout << "\nPlease pick which seat you would like to sit in, please enter between 1-4 ";
cin >> fccol;

if (fccol > 4)
{
cout << "\nYou have entered an invalid seat number, please enter between 1-4 ";
cin >> fccol;
}
break;

case FIRSTCOACH:
cout << "You have chosen: First Coach Class" << endl;
cout << "\nThe price of a ticket for First Coach Class is $" << coach1price << endl;
cout << "\nNow please pick which row you would like to sit in: ";
cin >> fccrow;
cout << "Please pick which seat you would like to sit in. Please enter between 6-10: ";
cin >> fcccol;

if (fccrow > 10)
{
cout << "\nYou have entered an invalid row number, please enter between 6-10 ";
cin >> fccrow;
}

cout << "\nPlease pick which seat you would like to sit in, please enter between 1-6: ";
cin >> fccol;

if (fcccol > 6)
{
cout << "You have entered an invalid seat number, please enter between 1-6";
cin >> fcccol;
}
break;

case SECONDCOACH:
cout << "You have chosen: Second Coach Class" << endl;
cout << "\nThe price of a ticket for Second Coach Class is: $"<< coach2price << endl;
cout << "\nNow please pick which row you would like to sit in, please choose between 11-15 ";
cin >> scrow;

if (fccrow > 15)
{
cout << "\nYou have entered an invalid row number, please enter in between 11-15 ";
cin >> scrow;
}

cout << "Please pick which seat you would like to sit in: ";
cin >> sccol;


if (fcccol > 6)
{
cout << "You have entered an invalid seat number, please enter between 1-6";
cin >> sccol;
}
break;


case DISPLAYSEAT:

seatChart(FirstArray, Coach1Array, Coach2Array);
break;

case EXIT:

cout << "You have chosen to Exit the program" << endl;
cout << "Thank you for using my program, have a good day!" << endl;
exit(1);
break;

default: cout << "You have entered in an invalid choice, please pick between 1-5" << endl;


}

}

// This is a Funciton for the Seating Chart

void seatChart(double FirstArray[FirstROWS][FirstCOLS], double Coach1Array[CoachROWS][CoachCOLS],
double Coach2Array[CoachROWS][CoachCOLS])
{
cout << "This is the Seating Chart" << endl;
cout << "========================= \n" << endl;


cout << "First Class is seats 1-4, Rows 1-5\n" << endl;

for (int a = 0; a < FirstROWS; a++)
{
for (int b = 0; b < FirstCOLS; b++)

cout << FirstArray[a] << "\t" << FirstArray[b] << endl;

cout << endl;

}

cout << "\nFirst Coach Class are seats 1-6, Rows 6-10:" << endl;

for (int a = 0; a < CoachROWS; a++)
{
for (int b = 0; b < CoachCOLS; b++)

cout << Coach1Array[a] << "\t" << Coach1Array[b] << endl;
}

cout << endl;

cout << "\nSecond Coach Class are seats 1-6, Rows 11-15" << endl;

for (int a = 0; a < CoachROWS; a++)
{
for (int b = 0; b < CoachCOLS; b++)

cout << Coach2Array[a] << "\t" << Coach2Array[b] << endl;
}

cout << endl;

}
Last edited on
Topic archived. No new replies allowed.