Mar 7, 2014 at 9:40pm UTC
I have been working away at this program, and I need some assistance. I am getting lost with the arrays when it comes to assigning the seats, and checking to see if a seat is available. I am also not sure how to add up all of the rows for the array and display that. Lastly, I'm trying to open a file in a function, read two prices from the file, place them in an array. I then need to use those numbers to determine a price for tickets. Any help would be greatly appreciated!
/*This is a program which will let a user keep track of their airline reservation.
The program will display a seating chart, display a menu with various options to
the user, which will be able to choose between first class and coach seating, both
of which have a different price.*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//Creating function prototypes.
void showMenu();
void chooseSeatType();
void getPrices();
void settingSeats();
void displaySeatingChart();
const int firstClassRows = 5;
const int firstClassColumns = 5;
char fSeat[firstClassRows][firstClassColumns];
const int coachRows = 10;
const int coachColumns = 7;
char cSeat[coachRows][coachColumns];
void main()
{
char choice, answer;
char seatType;
void settingSeats();
showMenu();
cin >> choice;
switch (choice)
{
case '1': cout << "You have chosen to reserve a seat.\n";
chooseSeatType();
cin >> seatType;
if (seatType == '1')
{
void settingSeats();
cout << "You have chosen First Class.\n";
cout << "Please choose a seat: \n";
cin >> fSeat[firstClassRows][firstClassColumns];
if(fSeat[firstClassRows][firstClassColumns] == 'X')
{
fSeat[firstClassRows][firstClassColumns] = 'X';
}
else
{
int x = rand()% firstClassRows;
int y = rand()% firstClassColumns;
while(fSeat[x][y] == 'X');
{
int x = rand()% firstClassRows;
int y = rand()% firstClassColumns;
}
fSeat[firstClassRows][firstClassColumns] = 'X';
}
}
else if (seatType == '2')
{
void settingSeats();
cout << "You have chosen a coach seat.\n";
cout << "Please choose a seat: \n";
cin >> cSeat[coachRows][coachColumns];
if(cSeat[coachRows][coachColumns] == 'X')
{
cSeat[coachRows][coachColumns] = 'X';
}
else
{
int rows = rand()% coachRows;
int columns = rand()% coachColumns;
while ( cSeat[coachRows][coachColumns] = 'X')
{
int rows = rand()% coachRows;
int columns = rand()% coachColumns;
}
cSeat[rows][columns] = 'X';
}
}
break;
case '2': cout << "Here is the seating chart:\n";
displaySeatingChart();
showMenu();
break;
case '3': cout << "Here are your ticketing details:\n";
break;
case '4': cout << "Thank you for using the Airline Reservation Program.\n";
break;
default: {
cout << "You did not make a valid choice. Please make a valid choice:\n";
showMenu();
cin >> choice;
}
}
}
void showMenu()
{
cout << "\tWelcome to the Airline Reservation System.\n";
cout << "\tPlease make a choice from the following menu:\n";
cout << endl;
cout << "1: Reserve a seat.\n";
cout << "2: Display the seating chart\n";
cout << "3: Review ticketing details.\n";
cout << "4: Quit.\n";
}
void getPrices()
{
const int SEAT_PRICES = 2;
double prices[SEAT_PRICES];
int count = 0;
ifstream inputFile;
inputFile.open("C:\\data\\SeatPrices.txt");
while (count < SEAT_PRICES && inputFile >> prices[count])
count++;
inputFile.close();
}
void settingSeats()
{
char seatLetters[11] = "ABCDEFGHIJ";
char seatLetter;
for ( int firstClassRows = 0; firstClassRows < 5; firstClassRows++ )
{
seatLetter = seatLetters[firstClassRows];
//for every seat in a row for ( int column = 0;
for ( int firstClassColumns = 0; firstClassColumns < 5; firstClassColumns++ )
{
fSeat[seatLetter][firstClassColumns] = '0';
}
for (int coachRows = 0; coachRows < 10; coachRows++)
for (int coachColumns = 0; coachColumns < 7; coachColumns++)
{
cSeat[seatLetter][coachColumns] = '0';
}
}
}
void chooseSeatType()
{
cout << "\tPlease make a seat choice:\n";
cout << "1: First Class\n";
cout << "2: Coach\n";
}
void displaySeatingChart()
{
cout << "Row 1: ## ##\n";
cout << "Row 2: X# ##\n";
cout << "Row 3: ## ##\n";
cout << "Row 4: ## X#\n";
cout << "Row 5: ## ##\n";
cout <<endl;
cout << "Row 6: ### ###\n";
cout << "Row 7: ### #X#\n";
cout << "Row 8: ### ###\n";
cout << "Row 9: ### ###\n";
cout << "Row 10: X## ###\n";
cout << "Row 11: ### ###\n";
cout << "Row 12: ### #X#\n";
cout << "Row 13: ### ###\n";
cout << "Row 14: ### ###\n";
cout << "Row 15: X## ###\n";
}