hi, I'm working on a project and I'm almost done. However, I'm having a few problems with the prices.
this is the guide for the project:
Airplane Seat Allocation System
Write a C++ program for the following task using modular approach.
a) 48 seats in 12 rows with a Aisle in the center. Seats at end of each row is a “Window Seat. The middle two seats in a row are “Aisle seats and 4 Seats in row one are “Leg Room Seats.
b) The program should display the seat plan.
c) Display a welcome greeting ,
d) Menu driven program to allow request for, ‘Window’, ‘Aisle’ and ‘Leg Room’ Seats, display seat # and block (if available). If the seats are not available in existing category, display a sorry message.
e) Provide a ‘Quit’ facility to exit from the program.
AND THIS IS MY CODE SO FAR:
//Airplanes Seating Allocation System
//libraries included
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
char airplane [12] [4];
float ticketPrice [12] = { 0.0 };
float totalsales = 0.0f;
int row, seat;
//Function Prototypes
void DisplaySeats (void);
void DisplayPrices (float []);
void DisplaySales ();
void PurchaseTicket (float[]);
void main ()
{
int choice;
char response = 'Y';
cout << "WELCOME TO C++ AIRPLANES SEATING ALLOCATION SYSTEM!\n";
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n";
//initialize airplane with labels (A, S, W, L) - all seats available
for (int y =0; y < 1; y++)
for (int q = 0; q <4; q++)
airplane [y][q] = 'L'; //Leg Room Seats
for (y = 1; y < 12; y++)
{
for (int z = 0; z < 4; z++)
{
for (int x = 0; x < 1; x++)
airplane [y][x] = 'S'; //Regular Seats
for (int v = 1; v < 3; v++)
airplane [y][v] = 'A'; //Aisle Seats
for (int w = 3; w <4; w++)
airplane [y][w] = 'W'; //Window Seats
}
}
//initialize seat prices for each of the 12 rows
for (int i = 0; i < 12; i++)
{
cout << "\nPlease enter ticket price for Row " << i + 1 << ": ";
cin >> ticketPrice [i];
}
while (response = 'Y')
{
//display menu of choices
cout << "\n\n\n\tC++ Airplane Seating Allocation System" << endl << endl;
cout << "\n\t1. View Availabe Seats";
cout << "\n\t2. View Seating Prices";
cout << "\n\t3. View Ticket Sales";
cout << "\n\t4. Purchase a Ticket";
cout << "\n\t5. Exit the Program\n\n";
cout << "\n\tEnter your choice (1-5): ";
cin >> choice;
switch (choice)
{
case 1:
cout << "Testing. DisplaySeats() called\n";
DisplaySeats();
break;
case 2:
DisplayPrices(ticketPrice);
break;
case 3:
DisplaySales();
break;
case 4:
PurchaseTicket(ticketPrice);
break;
case 5:
exit (0);
break;
default:
exit(0);
break;
} //end switch
}; //end while
} //end main
//Display a seating chart of the airplane
void DisplaySeats (void)
{
cout << "\n\tSEATS\n";
cout << " 1234";
cout << endl;
for (int r = 0; r < 12; r++)
{
cout << "\nRow " << setw(2) << r + 1 << "\t";
for (int s =0; s < 4; s++)
{
cout << airplane[r][s];
}
}
cout << "\n\n\n\tLegend:\t* = Sold";
cout << "\n\t\tA = Aisle Seats (Available)";
cout << "\n\t\tW = Window Seats (Available)";
cout << "\n\t\tS = Regular Seats (Avaiable)";
cout << "\n\t\tL = Leg Room Seats (Available)";
cout << endl;
char keyin;
cout << endl << endl;
cout << "\nPress an alphanumeric key to continue.";
cin >> keyin;
} //end DisplaySeats
void DisplayPrices(float price[])
{
cout << "\n\tTicket Prices By Row: " << endl << endl;
cout << "\tRow Price" << endl;
cout << "\t------ -------" << endl << endl;
cout.precision(2);
cout.setf(ios::fixed | ios::right);
for (int m =0; m < 12; m++)
{
cout << "\n\tRow " << setw(2) << m+1 << ":\t\t" << setw(5) << price[m];
}
char keyin;
cout << endl << endl;
cout << "\nPress an alphanumeric key to continue.";
cin >> keyin;
}
void PurchaseTicket(float price[])
{
int a, b = 0;
char response;
cout << "\n\t C++ Airplane Seating Allocation System" << endl;
cout << "\t\tTicket Purchase Opportunity" << endl;
do
{
do
{
cout << "\nPlease enter row number (1-12): ";
cin >> a;
} while (a <1 || a > 12);
do
{
cout << "\nPlease enter seat number (1-4): ";
cin >> b;
} while ( b < 1 || b > 4);
if (airplane [a-1][b-1] == 'A' || airplane [a-1][b-1] == 'L' ||
airplane [a-1][b-1] == 'W' || airplane [a-1][b-1] == 'S') //if the seat is available
{
airplane[a-1][b-1] = '*'; //indicate that the seat is taken
totalsales +=ticketPrice[a-1];
cout << "\nYour purchase of Seat " << b << "in Row " << a << "is confirmed." << endl;
}
else //seat has bee sold
{
cout << "\nSorry. That seat has been sold.\n";
}
cout << "\nWould you like to purchase another seat?";
cin >> response;
} while (toupper(response) == 'Y');
}
void DisplaySales ()
{
cout.setf(ios::fixed);
cout << "\n\nTotal Sales to Date: $" << setprecision(2) << totalsales << endl;
}
I tried to set different prices for the seats but I don't know how to work around the array problem. what I mean is that, how can I put these different prices in dirrent arrays and have them added up and stored inthe totalsales function?
I also don't know how to separate the column so that it would have an aisle down the middle.
Can you please help?
Thanks in advance,
Karen