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

For displaying the aisle, you can either write a string with spaces in it, " "
or a tab character, "\t" in your seat display couts.

Edit: I'll be back later. Gotta catch a bus.

For displaying the aisle, you can either write a string with spaces in it, " "
or a tab character, "\t" in your seat display couts.

Edit: I'll be back later. Gotta catch a bus.

I know this function, however, I put my seats in a 2-D array, how do I put the "\t" function in a 2-D array?

hi,
just in case I didn't sound very clear with the original post, I'd like different prices for different types of seatings (i.e aisle seats would cost $5, window seats $10) I only did the row prices because I don't know how to do the types prices......I'm rambling... Ok what I WANT is that I want each type of seating has its own price.

Also the prices can't be preset, the program has to asks the user to enter their prices. So, instead of asking the user to "enter the price for Row 1 (or 2, 3....12), it would ask the user to "enter the price for <W>indow seats, <A>isle seats....
that's why I'm thinking that I have to save this in an array or a function so that the total can be calculated. And This PART I don't know how to do, because it links with other functions.

Did I make myself clear to you? Sorry, I'm not very well with words.

Can you please help?

Thanks,
Karen

something like....

#include <iostream>
#include <limits>
using namespace std;

int GetInput(string s)
{
   cout<<s;
   int input;
   while (!(cin>>input))
   {
      cerr<<endl<<"error! re-enter"<<endl;
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(),'\n');
   }
   return input;
}

int main()
{
   int windowseatprice = GetInput(string("How much for a window seat"));
   return 0;
}

something like....

#include <iostream>
#include <limits>
using namespace std;

int GetInput(string s)
{
   cout<<s;
   int input;
   while (!(cin>>input))
   {
      cerr<<endl<<"error! re-enter"<<endl;
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(),'\n');
   }
   return input;
}

int main()
{
   int windowseatprice = GetInput(string("How much for a window seat"));
   return 0;
}

Ummm...hi....I forgot to mention that I'm a level-1 C++ beginner.
your code looks really complicated to me. I didn't learn about #include <limits> yet, nor cerr, nor...this "cin.ignore(numeric_limits<streamsize>::max(),'\n');"

do you know a less-advanced way of doing this?

sorry,
karen

OK, I'll explain it a little. GetInput takes a string to print to the console and returns an int that was entered. If there is a bad input then an error message is printed and the garbage removed from the stream so we can try recieve input again. When for instance cin is expecting an int but gets a char it goes into a failed state. All operations on a failed stream are null and void so first we must clear the error flags. This is what the cin.clear does. After that we can proceed to remove any garbage entered. The cin.ignore line basically says ignore as many chars as you can from the stream or up to the next newline char.This lets us proceed to getting an int from the user. Back in main we declare an int and initialise it with the return value of GetInput.
Need any further elaboration?

Hi,
while waiting for help, I help myself a bit (LOL that sounds so akward). ANYWAY.

Instead of the original code, which is to ask for the price of 12 rows:

//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 changed it to this:


void main ()
{
	int choice;
	char response = 'Y';

	float seatprices[4] = { 4.0, 5.0, 6.0, 7.0 }; //just some defaults here: ASWL
	char seattypes[4][12] = { "Aisle", "Regular", "Window", "Leg Room" }; //this makes it possible to do input with a loop


	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
		}
	}

	//seatypes inputs
	for (int i = 0; i < 4; i++)
	{
	cout << "Please enter price for " << seattypes[i] << " seats: ";
	cin >> seatprices[i];
	cout << endl;
	}

and now I have to find a new way to display this in the DisplayPrices () function, and I don't think I did it right.

void DisplayPrices(float seatprices[], float seattypes[])
{
	cout.precision(2);
	cout.setf(ios::fixed | ios::right);
	cout << "\n\tTicket Prices By Seat Types:  " << endl << endl;
	cout << "\tSeat Types			Price" << endl;
	cout << "\t------			-------" << endl << endl;
	for (int m = 0; m < 4; m++)
		seattypes[m];
	for (int n = 0; n < 4; n++)
		seatprices[n];
	
char keyin;
cout << endl << endl;
cout << "\nPress an alphanumeric key to continue.";
cin >> keyin;
}

can you tell me what I did wrong in the code above?

Karen

OK, I'll explain it a little. GetInput takes a string to print to the console and returns an int that was entered. If there is a bad input then an error message is printed and the garbage removed from the stream so we can try recieve input again. When for instance cin is expecting an int but gets a char it goes into a failed state. All operations on a failed stream are null and void so first we must clear the error flags. This is what the cin.clear does. After that we can proceed to remove any garbage entered. The cin.ignore line basically says ignore as many chars as you can from the stream or up to the next newline char.This lets us proceed to getting an int from the user. Back in main we declare an int and initialise it with the return value of GetInput.
Need any further elaboration?

wow, that was certainly a lot of information in one paragraph! I got to digest all that slowly (i'm a bit slow, sorry). I think I understand what you coded...but I'm not really familiar with it...and my project is due in 2 days...so it's safer to stick to what I know right now....But your information is certainly great for future reference though (i'm sure more projects are coming my way...sighnnn).

anyway, I just posted my new code. Can you check that out and give me suggestions?

btw. add #include<string> to top of that code. Forgot that.

Your code is incomplete. If you post a complete example I can look over in my compiler then i'll take a look. I would urge you to at least check out the string type rather than use char arrays. Always remember main never returns void. It always returns int.Your loops look messy.Stick to the KISS principle and you wont go far wrong.

Hi, This is my complete code:

//Airplanes Seating Allocation System

//libraries included
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <string>

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';

	float seatprices[4] = { 4.0, 5.0, 6.0, 7.0 }; //just some defaults here: ASWL
	char seattypes[4][12] = { "Aisle", "Regular", "Window", "Leg Room" }; //this makes it possible to do input with a loop


	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
		}
	}

	//input the Seat prices
//did I do this right?
	for (int i = 0; i < 4; i++)
	{
	cout << "Please enter price for " << seattypes[i] << " seats: ";
	cin >> seatprices[i];
	cout << endl;
	}


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 *seatprices[], float *seattypes[])
{
	cout.precision(2);
	cout.setf(ios::fixed | ios::right);
	cout << "\n\tTicket Prices By Seat Types:  " << endl << endl;
	cout << "\tSeat Types			Price" << endl;
	cout << "\t------			-------" << endl << endl;
	for (int m = 0; m < 4; m++)
		*seattypes[m];
	for (int n = 0; n < 4; n++)
		*seatprices[n];
	// I don't know what to do here!

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
{
//Right now I can only ask the user to enter the row number,
//I don't know how to tell the user to enter the seat type (window, aisle...) and the row number as well
	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 been 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;
}

yeah, I'm aware that's it's a bit (ok, a lot) messy. But since I'm a beginner, I don't know how to take any other shortcuts.

Can you take a look at the DisplayPrices() and the PurchaseTickets() functions? I post my questions there as well.

thanks a lot,
Karen

I looked at your code. It really could benefit from a rewrite. I got this far then had to go out so rest left as exercise for you. see how you do. Post later what you come up with and ill look it over.

// You have shown enough effort for me to help you rewrite this
// We will use standard headers and not the deprecated ones you were using.
// I am assuming you are running under a windows OS so we can use a few
// facilities provided by the OS to do things like clearing the screen.

#include<iostream>
#include<string>
#include<limits>
#include<windows.h>
// windows.h defines a max macro that will make our life hell so we undef it
#undef max

// the functions and objects in the standard headers are all declared within namespace
// std. We will bring them all into the global scope so we dont have to prefix everything
// with std:: with this simple line.
using namespace std;

// here is how to clear the screen on a windows console. You do not need to
// necessarily understand this to use it.Suffice to say that a call to this
// will clear the screen and reset the cursor pos to the top left corner.
void clrscr()
{
    COORD                       coordScreen = { 0, 0 };
    DWORD                       cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO  csbi;
    DWORD                       dwConSize;
    HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
}

// Lets introduce a struct to represent our seats. A struct is an aggregate type made up
// of smaller types.
// You declare one like so :-
// struct STRUCTNAME { members };
// you make an object of your struct like declaring an int.
// STRUCTNAME obj;
// You access the members with the dot operator like so...
// struct mystruct{inta;intb;};
// mystruct astruct;
// astruct.a = 0;astruct.b = 0;
struct Seat
{
   string seattype;
   float seatprice;
   int row;
   int seatnumber;
   bool taken; // a bool has 2 states true and false. When this is true the seat is taken
};

// Now we will make a global array of seats to represent the plane.
// We will use this all over the place so global as a convenience.
// There are 12 rows of 4 seats so...
Seat seatmap[12][4];

// Lets write a function to get the prices of seats
float GetInput(string s)
{
   cout<<s;
   float input;
   while (!(cin>>input))
   {
      cerr<<endl<<"error! re-enter"<<endl;
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(),'\n');
   }
   return input;
}

// armed with that we can write a function to initalise the seatmap
void InitSeatMap()
{
   float Legroomprice = GetInput(string("Enter cost of a leg-room seat ? "));
   float Windowprice = GetInput(string("Enter cost of a window seat ? "));
   float Aisleprice = GetInput(string("Enter cost of an aisle seat ? "));
   for (int i=0;i<12;++i)
      for(int j=0;j<4;++j)
      {
         seatmap[i][j].row = i+1;
         seatmap[i][j].seatnumber = j+1;
         seatmap[i][j].taken = false; // no seat is taken yet
         if (i==0) // legroom seats
         {
            seatmap[i][j].seattype = "legroom";
            seatmap[i][j].seatprice = Legroomprice;
         }
         if((i != 0) && (j==0 || j==3)) // we have a windowseat
         {
            seatmap[i][j].seattype = "window";
            seatmap[i][j].seatprice = Windowprice;
         }
         if((i != 0) && (j==1 || j==2)) // we have an aisle seat
         {
            seatmap[i][j].seattype = "aisle";
            seatmap[i][j].seatprice = Aisleprice;
         }
      }
}

// a quick function to output a sorry message
void Sorry()
{
   cout<<endl<<"Sorry but that type of seat is not available!!!"<<endl;
}

// now we can write a function to allocate a seat
void AllocSeat(string type)
{
   // left as exercise to reader
   // you can check strings for equality like
   // if (type == "legroom") 
}

void Menu()
{
   clrscr();
   // exercise for reader
}

void DisplaySeatMap()
{
   clrscr();
   for (int i=0;i<12;++i)
      for (int j=0;j<4;++j)
      {
         if (seatmap[i][j].seattype == "legroom")
         {
            cout << ((seatmap[i][j].taken) ? "*\t" : "L\t");
         }
         if (seatmap[i][j].seattype == "window")
         {
            cout << ((seatmap[i][j].taken) ? "*\t" : "W\t");
         }
         if (seatmap[i][j].seattype == "aisle")
         {
            cout << ((seatmap[i][j].taken) ? "*\t" : "A\t");
         }
         if (j==3)
            cout<<endl;
      }
}




int main()
{
   InitSeatMap();
   Menu();

   // exercise for reader

   return 0;
}

You will still need to write the bits I left as an exercise and also add any more functions you deem necessary. Its reasonably simple stuff but some of it you may not have come across yet. Try follow whats been done so far. It should be reasonably easy for you to finish it off.

OMG! You're asking me to rewrite my code, which I've spent days (over a week already) doing. Please don't be that cruel. i'm only a beginner and I've slaved over this project so much I can't bear to start over again.
I looked over the code that you're written so far...and to be honest...I can follow it but I can't do that on my own...I have no idea what to do next!
Can you please just help me with my code? with the parts where I got stuck on? Please?
Right now, I've rewritten parts of it. and there is one mistake that I should mention. There are only 3 types of seats: leg room, Window, and aisle seats. There are no "regular seats" because airplanes have windows on both sides *duh*.

My modification: the DisplaySeats() and the DisplayPrices() functions.

My Problem: the PurchaseTicket() and the DisplaySales() functions. Since each type of seat has different prices, I've trying to ask for the user to enter the seattype and then the row and the seat numbers. I'm only able to code the program to ask for the row and seat numbers.

Can you tell me what's wrong with my DisplayPrices() function? Why doesn't display anything when I tested it?

//Airplanes Seating Allocation System

//libraries included
#include <iostream>
#include <stdlib.h>
#include <iomanip.h>
#include <string>
#include<windows.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 *, char [][12]);
void DisplaySales ();
void PurchaseTicket (float[]);
float getSeatPrice(char type);

void clrscr()
{
    COORD                       coordScreen = { 0, 0 };
    DWORD                       cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO  csbi;
    DWORD                       dwConSize;
    HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
}

void main ()
{
	int choice;
	char response = 'Y';

	float seatprices[3] = { 4.0, 5.0, 6.0 }; //just some defaults here: AWL
	char seattypes[3][12] = { "Aisle", "Window", "Leg Room" }; //this makes it possible to do input with a loop


	cout << "WELCOME TO C++ AIRPLANES SEATING ALLOCATION SYSTEM!\n";
	cout <<	"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n";

	//initialize airplane with labels (A, 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] = 'W';		//Window 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
		}
	}

	//input the Seat prices
	for (int i = 0; i < 3; i++)
	{
	cout << "Please enter price for " << seattypes[i] << " seats: ";
	cin >> seatprices[i];
	cout << endl;
	}

while (response = 'Y')
{
	//display menu of choices
	clrscr();
	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 << "Airplane Seating Chart\n";
		DisplaySeats();
		break;
	case 2:
		DisplayPrices(seatprices, seattypes);
		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)
{
	clrscr(); 
	
	cout << "\n\tSEATS\n";
	cout << "	1\t2\t3\t4";
	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] << "\t";
			}
	}
cout << "\n\n\n\tLegend:\t* = Sold";
cout << "\n\t\tA = Aisle Seats (Available)";
cout << "\n\t\tW = Window Seats (Available)";
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 *seatprices, char seattypes[][12])
{
	clrscr();

	cout.precision(2);
	cout.setf(ios::fixed | ios::right);
	cout << "\n\tTicket Prices By Seat Types:  " << endl << endl;
	cout << "\tSeat Types		Price" << endl;
	cout << "\t------			-------" << endl << endl;
	for (int m = 0; m < 3; m++)
	{
		cout << "\t" << seattypes[m] << "\t\t\t" << seatprices[m] << endl;
		cout << endl;
	}

char keyin;
cout << endl << endl;
cout << "\nPress an alphanumeric key to continue.";
cin >> keyin;
}

void PurchaseTicket(float price[])
{
	clrscr();

	int a, b = 0;
	char response;

	cout << "\n\tC++ Airplane Seating Allocation System" << endl << 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 been 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'm so sorry I'm not any brighter at this. It's really hard to learn this stuff.

Karen

You should really try to finish my code. I can help you so dont panic. There was too many errors in your original code to make it worthwhile to fix rather than rewrite. Also your design doesn't lend to code brevity. Notice in mine all the data you need to do any calculations is all stored in an array of structs. I gave in the comments a little info on structs, certainly enough for you to be able to grasp what i had written. Notice how it makes things easy and cuts down in general on the amount of loops you need to write.It enhances code readability and therefore makes it easier for you to understand.If there is any part of my code you dont understand just point it out and ill help. Try first to write the AllocSeat function. You ask for wanted seattype. You can then iterate the array for the first of that seattype whose taken member is also false. Set taken to true or call Sorry() and that ones done. There is a few examples of iterating that array of structs already in the code so that shouldn't phase you. There are also examples of comparing strings and assigning struct members. Most of the code is already written for you. Theres only a few funcs to add and maybe one or two to add a line to.
Dont put yourself down for not being bright. I know quite a few people who describe themselves in that manner and some of those are very good coders. Slow and steady is better than fast and falling flat on your face. C++ is hard to learn, I wont lie to you but its not impossible to grasp the simple constructs I have shown you here. std::strings are a much easier type to work with than char array strings and should be taught before the latter. There is enough information in the code to allow you to use the struct array confidently. loops ifs and function calls are about all you need. If you can follow what I have written then you can finish it. I'll be around for about 4 hrs from time of this post.

OK, I took your advice and gave it a try.

void AllocSeat(string type)
{
   
	int a, b;

	do
	{
		cout << "What type of seat would you like?\n";
		cin >> type;
		if (type == "legroom")
		{
			do
			{
				for (int y =0; y < 1; y++)			
				for (int q = 0; q <4; q++)
				cout << "\nPlease enter seat number (1-4): ";
				cin >> b;
				if (string(b, 'L') == 0)
				{
					seatmap[y][b] == '*';
				}
				else 
				{
					Sorry();
				}
			} while ( b < 1  || b > 4);
		}
		if (type == "aisle")
		{	
			do
			{
				for (int z = 0; z < 4; z++)
				{
					for (int v = 1; v < 3; v++)
					{
						cout << "\nPlease enter row number (1-12): ";
						cin >> a;
					} while (a <1 || a > 12);
					do
					{
					cout << "\nPlease enter seat number (2-3): ";
					cin >> b;
					if (string(b, 'A') ==0)
					{
						seatmap[z][b] == '*';
					}
					else 
					{
						Sorry();
				} while ( b < 1  || b > 4);
			}
		}
		if (type == "window")
		{
			do
			{
				for (int z = 0; z < 4; z++)
				{
					for (int x = 0; x < 1; x++)
					for (int w = 3; w <4; w++)
					{
					cout << "\nPlease enter row number (1-12): ";
						cin >> a;
					} while (a <1 || a > 12);
					do
					{
					cout << "\nPlease enter seat number (1 or 4): ";
					cin >> b;
					if (string(b, 'W') ==0)
					{
						seatmap[z][b] == '*';
					}
					else 
					{
						Sorry();
					}
				} while ( b < 1  || b > 4);
			}
		}
		}

This is my best (miserable) attempt.

now compare yours with mine. Ive changed a couple of things, displaying now displays row and seatnumbers. Sorry has gone. There are 2 overloads of AllocSeat. one lets you pick a specific seat and another a type of seat. Have you covered overloading of functions yet?
Starting to see how this is coming together?

// You have shown enough effort for me to help you rewrite this
// We will use standard headers and not the deprecated ones you were using.
// I am assuming you are running under a windows OS so we can use a few
// facilities provided by the OS to do things like clearing the screen.

#include<iostream>
#include<iomanip>
#include<string>
#include<limits>
#include<windows.h>
// windows.h defines a max macro that will make our life hell so we undef it
#undef max

// the functions and objects in the standard headers are all declared within namespace
// std. We will bring them all into the global scope so we dont have to prefix everything
// with std:: with this simple line.
using namespace std;

// here is how to clear the screen on a windows console. You do not need to
// necessarily understand this to use it.Suffice to say that a call to this
// will clear the screen and reset the cursor pos to the top left corner.
void clrscr()
{
    COORD                       coordScreen = { 0, 0 };
    DWORD                       cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO  csbi;
    DWORD                       dwConSize;
    HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
}

// Lets introduce a struct to represent our seats. A struct is an aggregate type made up
// of smaller types.
// You declare one like so :-
// struct STRUCTNAME { members };
// you make an object of your struct like declaring an int.
// STRUCTNAME obj;
// You access the members with the dot operator like so...
// struct mystruct{inta;intb;};
// mystruct astruct;
// astruct.a = 0;astruct.b = 0;
struct Seat
{
   string seattype;
   float seatprice;
   int row;
   int seatnumber;
   bool taken; // a bool has 2 states true and false. When this is true the seat is taken
};

// Now we will make a global array of seats to represent the plane.
// We will use this all over the place so global as a convenience.
// There are 12 rows of 4 seats so...
Seat seatmap[12][4];

// Lets write a function to get the prices of seats
float GetInput(string s)
{
   cout<<s;
   float input;
   while (!(cin>>input))
   {
      cerr<<endl<<"error! re-enter"<<endl;
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(),'\n');
   }
   return input;
}

// armed with that we can write a function to initalise the seatmap
void InitSeatMap()
{
   float Legroomprice = GetInput(string("Enter cost of a leg-room seat ? "));
   float Windowprice = GetInput(string("Enter cost of a window seat ? "));
   float Aisleprice = GetInput(string("Enter cost of an aisle seat ? "));
   for (int i=0;i<12;++i)
      for(int j=0;j<4;++j)
      {
         seatmap[i][j].row = i+1;
         seatmap[i][j].seatnumber = j+1;
         seatmap[i][j].taken = false; // no seat is taken yet
         if (i==0) // legroom seats
         {
            seatmap[i][j].seattype = "legroom";
            seatmap[i][j].seatprice = Legroomprice;
         }
         if((i != 0) && (j==0 || j==3)) // we have a windowseat
         {
            seatmap[i][j].seattype = "window";
            seatmap[i][j].seatprice = Windowprice;
         }
         if((i != 0) && (j==1 || j==2)) // we have an aisle seat
         {
            seatmap[i][j].seattype = "aisle";
            seatmap[i][j].seatprice = Aisleprice;
         }
      }
}

// now we can write a function to allocate a seat
void AllocSeat(string type)
{
   for(int i=0;i<12;++i)
      for(int j=0;j<4;++j)
      {
         if (seatmap[i][j].seattype == type && !seatmap[i][j].taken)
         {
            seatmap[i][j].taken = true; // seats free so allocate it taken
            return;
         }
      }
   cout<<endl<<"Sorry but that type of seat is not available!!!"<<endl;
}

// an overload to take a specific seat
void AllocSeat(int row, int seatnum)
{
   if (!seatmap[row-1][seatnum-1].taken)
   {
      seatmap[row-1][seatnum-1].taken = true;
      return;
   }
   cout<<endl<<"Sorry but that particular seat is already taken!!!"<<endl;
}

void Menu()
{
   clrscr();
   // exercise for reader
}

void DisplaySeatMap()
{
   clrscr();
   for (int i=0;i<12;++i)
      for (int j=0;j<4;++j)
      {
         if (!i && !j)
         {
            cout<<"  "<<setw(3)<<1<<setw(3)<<2<<setw(3)<<3<<setw(3)<<4<<endl;
         }
         if (j==0)
         {
            cout<<setw(4)<<left<<seatmap[i][j].row;
         }
         if (seatmap[i][j].seattype == "legroom")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "L");
         }
         if (seatmap[i][j].seattype == "window")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "W");
         }
         if (seatmap[i][j].seattype == "aisle")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "A");
         }
         if (j==3)
            cout<<endl;
      }
}

int main()
{
   InitSeatMap();
   
   // exercise for reader

   return 0;
}

Ok, I've compared yours with mine and they're not EVEN close to being similar to each other.

I don't understand why you have 2 AlloSeat() functions, are you allowed to do that? How do we know which function to use in the main function?

And no, I've learned about overloading functions yet.

OMG! My final (for another class) is in 30 min! I have to go to that class! When will you be gone?
This airplane project is due tomorrow, cause tomorrow is my final in this C++ class!

yes you are allowed to do that its called function overloading. If we called it like this...

string s="legroom";
AllocSeat(s);

then the one that takes a string will be called. This will automatically search for the first available seat of that type and allocate it. I should have added a message telling you seatnumber and row, you can do that i am sure.
Alternatively if we call it like so

int row,seatnum;
cout<<"enter row and seatnumber separated by a space"<<endl;
cin>>row>>seatnum;
AllocSeat(row,seatnum);

then that overload will try to take the specific seat pointed at by row/seatnum.

So you should now be able to write a function that asks user whether he would like to pick a seat or auto get one and call the correct overload of AllocSeat.
Again dont panic, I know this is due soon but we will get it done and my hope is I teach you a little something on the way too.

'K I'll try to have everything done (hopefully not too many misktakes) tonight. When can you check it tomorrow?

karen

here I cleaned it up a bit and added some while smoking a joint. Theres not much left for you to do now. Make sure you understand everything. If you are not sure then ask.

// You have shown enough effort for me to help you rewrite this
// We will use standard headers and not the deprecated ones you were using.
// I am assuming you are running under a windows OS so we can use a few
// facilities provided by the OS to do things like clearing the screen.

#include<iostream>
#include<iomanip>
#include<string>
#include<limits>
#include<cstdlib>
#include<windows.h>
// windows.h defines a max macro that will make our life hell so we undef it
#undef max

// the functions and objects in the standard headers are all declared within namespace
// std. We will bring them all into the global scope so we dont have to prefix everything
// with std:: with this simple line.
using namespace std;

// here is how to clear the screen on a windows console. You do not need to
// necessarily understand this to use it.Suffice to say that a call to this
// will clear the screen and reset the cursor pos to the top left corner.
void clrscr()
{
    COORD                       coordScreen = { 0, 0 };
    DWORD                       cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO  csbi;
    DWORD                       dwConSize;
    HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
}

// Lets introduce a struct to represent our seats. A struct is an aggregate type made up
// of smaller types.
// You declare one like so :-
// struct STRUCTNAME { members };
// you make an object of your struct like declaring an int.
// STRUCTNAME obj;
// You access the members with the dot operator like so...
// struct mystruct{inta;intb;};
// mystruct astruct;
// astruct.a = 0;astruct.b = 0;
struct Seat
{
   string seattype;
   float seatprice;
   int row;
   int seatnumber;
   bool taken; // a bool has 2 states true and false. When this is true the seat is taken
};

// Now we will make a global array of seats to represent the plane.
// We will use this all over the place so global as a convenience.
// There are 12 rows of 4 seats so...
Seat seatmap[12][4];

// Lets write a function to get the prices of seats
float GetInput(string s)
{
   cout<<s;
   float input;
   while (!(cin>>input))
   {
      cerr<<endl<<"error! re-enter"<<endl;
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(),'\n');
   }
   return input;
}

// armed with that we can write a function to initalise the seatmap
void InitSeatMap()
{
   float Legroomprice = GetInput(string("Enter cost of a leg-room seat ? "));
   float Windowprice = GetInput(string("Enter cost of a window seat ? "));
   float Aisleprice = GetInput(string("Enter cost of an aisle seat ? "));
   for (int i=0;i<12;++i)
      for(int j=0;j<4;++j)
      {
         seatmap[i][j].row = i+1;
         seatmap[i][j].seatnumber = j+1;
         seatmap[i][j].taken = false; // no seat is taken yet
         if (i==0) // legroom seats
         {
            seatmap[i][j].seattype = "legroom";
            seatmap[i][j].seatprice = Legroomprice;
         }
         if((i != 0) && (j==0 || j==3)) // we have a windowseat
         {
            seatmap[i][j].seattype = "window";
            seatmap[i][j].seatprice = Windowprice;
         }
         if((i != 0) && (j==1 || j==2)) // we have an aisle seat
         {
            seatmap[i][j].seattype = "aisle";
            seatmap[i][j].seatprice = Aisleprice;
         }
      }
}

// now we can write a function to allocate a seat
void AllocSeat(string type)
{
   for(int i=0;i<12;++i)
      for(int j=0;j<4;++j)
      {
         if (seatmap[i][j].seattype == type && !seatmap[i][j].taken)
         {
            seatmap[i][j].taken = true; // seats free so allocate it taken
            cout<<endl<<"Seat allocated. Row :- "<<seatmap[i][j].row<< "Seatnumber :- "<<seatmap[i][j].seatnumber<<endl;
            return;
         }
      }
   cout<<endl<<"Sorry but that type of seat is not available!!!"<<endl;
}

// an overload to take a specific seat
void AllocSeat(int row, int seatnum)
{
   if (!seatmap[row-1][seatnum-1].taken)
   {
      seatmap[row-1][seatnum-1].taken = true;
      cout<<endl<<"Seat allocated."<<endl;
      return;
   }
   cout<<endl<<"Sorry but that particular seat is already taken!!!"<<endl;
}

void Menu()
{
   clrscr();
   cout<<"1 - View available seats"<<endl
      <<"2 - View seating prices"<<endl
      <<"3 - View ticket sales"<<endl
      <<"4 - Purchase a ticket"<<endl
      <<"5 - Quit"<<endl;
}

void DisplaySeatMap()
{
   clrscr();
   for (int i=0;i<12;++i)
      for (int j=0;j<4;++j)
      {
         if (!i && !j)
         {
            cout<<"  "<<setw(3)<<1<<setw(3)<<2<<setw(3)<<3<<setw(3)<<4<<endl;
         }
         if (j==0)
         {
            cout<<setw(4)<<left<<seatmap[i][j].row;
         }
         if (seatmap[i][j].seattype == "legroom")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "L");
         }
         if (seatmap[i][j].seattype == "window")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "W");
         }
         if (seatmap[i][j].seattype == "aisle")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "A");
         }
         if (j==3)
            cout<<endl;
      }
   system("PAUSE"); // lousy but just what we need
}

void PurchaseSeat()
{
   // offer pick a seat or type of seat.
   // call correct AllocSeat
   // display cost
}

void DisplaySales()
{
   int sales[3]={0};
   for (int i=0;i<12;++i)
      for (int j=0;j<4;++j)
      {
         if (seatmap[i][j].seattype == "legroom" && seatmap[i][j].taken)
         {
            ++sales[0];
         }
         if (seatmap[i][j].seattype == "window" && seatmap[i][j].taken)
         {
            ++sales[1];
         }
         if (seatmap[i][j].seattype == "aisle" && seatmap[i][j].taken)
         {
            ++sales[2];
         }
      }
   clrscr();
   cout<<"Legroom seats sold :- "<<sales[0]<<" at $"<<seatmap[0][0].seatprice<<endl
      <<"Window seats sold :- "<<sales[1]<<" at $"<<seatmap[1][0].seatprice<<endl
      <<"Aisle seats sold :- "<<sales[2]<<" at $"<<seatmap[1][1].seatprice<<endl;
   double revenue = (sales[0] * seatmap[0][0].seatprice) + (sales[1] * seatmap[1][0].seatprice)
      + (sales[2] * seatmap[1][1].seatprice);
   cout<<"Total revenues for this flight are $"<<revenue<<endl;
   system("PAUSE");
}

void DisplayPricing()
{
   clrscr();
   cout << "Legroom seat :- $"<<seatmap[0][0].seatprice<<endl
      <<"Window seat :- $"<<seatmap[1][0].seatprice<<endl
      <<"Aisle seat :- $"<<seatmap[1][1].seatprice<<endl;
   system("PAUSE"); // lousy but does the job
}


int main()
{
   InitSeatMap();
   while(1) // infinite loop
   {
      Menu();
      cout<<"Enter choice :- ";
      int input;
      while (!(cin>>input) || input<0 || input>5)
      {
         cerr<<endl<<"error! re-enter"<<endl;
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(),'\n');
      }
      switch(input)
      {
         case 1:  DisplaySeatMap();
                  break;
         case 2:  DisplayPricing();
                  break;
         case 3:  DisplaySales();
                  break;
         case 4:  PurchaseSeat();
                  break;
         case 5:  cout<<"Exiting.........Goodbye!!!"<<endl;
                  Sleep(2000); // a small wait of 2 secs
                  return 0;
      }
   }
}

gotta go work now so heres how mine looks finished.

// You have shown enough effort for me to help you rewrite this
// We will use standard headers and not the deprecated ones you were using.
// I am assuming you are running under a windows OS so we can use a few
// facilities provided by the OS to do things like clearing the screen.

#include<iostream>
#include<iomanip>
#include<string>
#include<limits>
#include<cstdlib>
#include<windows.h>
// windows.h defines a max macro that will make our life hell so we undef it
#undef max

// the functions and objects in the standard headers are all declared within namespace
// std. We will bring them all into the global scope so we dont have to prefix everything
// with std:: with this simple line.
using namespace std;

// here is how to clear the screen on a windows console. You do not need to
// necessarily understand this to use it.Suffice to say that a call to this
// will clear the screen and reset the cursor pos to the top left corner.
void clrscr()
{
    COORD                       coordScreen = { 0, 0 };
    DWORD                       cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO  csbi;
    DWORD                       dwConSize;
    HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
}

// Lets introduce a struct to represent our seats. A struct is an aggregate type made up
// of smaller types.
// You declare one like so :-
// struct STRUCTNAME { members };
// you make an object of your struct like declaring an int.
// STRUCTNAME obj;
// You access the members with the dot operator like so...
// struct mystruct{inta;intb;};
// mystruct astruct;
// astruct.a = 0;astruct.b = 0;
struct Seat
{
   string seattype;
   float seatprice;
   int row;
   int seatnumber;
   bool taken; // a bool has 2 states true and false. When this is true the seat is taken
};

// Now we will make a global array of seats to represent the plane.
// We will use this all over the place so global as a convenience.
// There are 12 rows of 4 seats so...
Seat seatmap[12][4];

// Lets write a function to get the prices of seats
float GetInput(string s)
{
   cout<<s;
   float input;
   while (!(cin>>input))
   {
      cerr<<endl<<"error! re-enter"<<endl;
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(),'\n');
   }
   return input;
}

// armed with that we can write a function to initalise the seatmap
void InitSeatMap()
{
   float Legroomprice = GetInput(string("Enter cost of a leg-room seat ? "));
   float Windowprice = GetInput(string("Enter cost of a window seat ? "));
   float Aisleprice = GetInput(string("Enter cost of an aisle seat ? "));
   for (int i=0;i<12;++i)
      for(int j=0;j<4;++j)
      {
         seatmap[i][j].row = i+1;
         seatmap[i][j].seatnumber = j+1;
         seatmap[i][j].taken = false; // no seat is taken yet
         if (i==0) // legroom seats
         {
            seatmap[i][j].seattype = "legroom";
            seatmap[i][j].seatprice = Legroomprice;
         }
         if((i != 0) && (j==0 || j==3)) // we have a windowseat
         {
            seatmap[i][j].seattype = "window";
            seatmap[i][j].seatprice = Windowprice;
         }
         if((i != 0) && (j==1 || j==2)) // we have an aisle seat
         {
            seatmap[i][j].seattype = "aisle";
            seatmap[i][j].seatprice = Aisleprice;
         }
      }
}

// now we can write a function to allocate a seat
void AllocSeat(string type)
{
   for(int i=0;i<12;++i)
      for(int j=0;j<4;++j)
      {
         if (seatmap[i][j].seattype == type && !seatmap[i][j].taken)
         {
            seatmap[i][j].taken = true; // seats free so allocate it taken
            cout<<endl<<"Seat allocated. Row :- "<<seatmap[i][j].row<< "  Seatnumber :- "<<seatmap[i][j].seatnumber<<endl;
            cout<<"Cost of seat is $"<<seatmap[i][j].seatprice<<endl;
            return;
         }
      }
   cout<<endl<<"Sorry but that type of seat is not available!!!"<<endl;
}

// an overload to take a specific seat
void AllocSeat(int row, int seatnum)
{
   if (!seatmap[row-1][seatnum-1].taken)
   {
      seatmap[row-1][seatnum-1].taken = true;
      cout<<endl<<"Seat allocated."<<endl;
      cout<<"Cost of seat is $"<<seatmap[row-1][seatnum-1].seatprice<<endl;
      return;
   }
   cout<<endl<<"Sorry but that particular seat is already taken!!!"<<endl;
}

void Menu()
{
   clrscr();
   cout<<"1 - View available seats"<<endl
      <<"2 - View seating prices"<<endl
      <<"3 - View ticket sales"<<endl
      <<"4 - Purchase a ticket"<<endl
      <<"5 - Quit"<<endl;
}

void DisplaySeatMap()
{
   clrscr();
   for (int i=0;i<12;++i)
      for (int j=0;j<4;++j)
      {
         if (!i && !j)
         {
            cout<<"  "<<setw(3)<<1<<setw(3)<<2<<setw(3)<<3<<setw(3)<<4<<endl;
         }
         if (j==0)
         {
            cout<<setw(4)<<left<<seatmap[i][j].row;
         }
         if (seatmap[i][j].seattype == "legroom")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "L");
         }
         if (seatmap[i][j].seattype == "window")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "W");
         }
         if (seatmap[i][j].seattype == "aisle")
         {
            cout <<setw(3)<<left<<((seatmap[i][j].taken) ? "*" : "A");
         }
         if (j==3)
            cout<<endl;
      }
   system("PAUSE"); // lousy but just what we need
}

bool Valid(char c)
{
   c = tolower(c);
   if( c == 'a' || c == 'w' || c == 'l')
      return true;
   else
      return false;
}

void PurchaseSeat()
{
   clrscr();
   cout<<"Do you wish to pick a particular seat(Y/N) ? ";
   char input;
   while(!(cin>>input))
   {
      cerr<<endl<<"error! re-enter"<<endl;
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(),'\n');
   }
   if (tolower(input) == 'y')
   {
      int row,seatnum;
      cout<<"Enter row followed by a space then seat number :- ";
      while (!(cin>>row>>seatnum) || row<1 || row>12 || seatnum<1 || seatnum>4)
      {
         cerr<<endl<<"error! re-enter"<<endl;
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(),'\n');
      }
      AllocSeat(row,seatnum);
   }
   else
   {
      cout<<endl<<"What type of seat would you like (W,L,A) ? ";
      while(!(cin>>input) || !Valid(input))
      {
         cerr<<endl<<"error! re-enter"<<endl;
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(),'\n');
      }
      string type;
      if(tolower(input) == 'l')
      {
         type = "legroom";
      }
      else if(tolower(input) == 'w')
      {
         type = "window";
      }
      else
      {
         type = "aisle";
      }
      AllocSeat(type);
      system("PAUSE");
   }
}

void DisplaySales()
{
   int sales[3]={0};
   for (int i=0;i<12;++i)
      for (int j=0;j<4;++j)
      {
         if (seatmap[i][j].seattype == "legroom" && seatmap[i][j].taken)
         {
            ++sales[0];
         }
         if (seatmap[i][j].seattype == "window" && seatmap[i][j].taken)
         {
            ++sales[1];
         }
         if (seatmap[i][j].seattype == "aisle" && seatmap[i][j].taken)
         {
            ++sales[2];
         }
      }
   clrscr();
   cout<<"Legroom seats sold :- "<<sales[0]<<" at $"<<seatmap[0][0].seatprice<<endl
      <<"Window seats sold :- "<<sales[1]<<" at $"<<seatmap[1][0].seatprice<<endl
      <<"Aisle seats sold :- "<<sales[2]<<" at $"<<seatmap[1][1].seatprice<<endl;
   double revenue = (sales[0] * seatmap[0][0].seatprice) + (sales[1] * seatmap[1][0].seatprice)
      + (sales[2] * seatmap[1][1].seatprice);
   cout<<"Total revenues for this flight are $"<<revenue<<endl;
   system("PAUSE");
}

void DisplayPricing()
{
   clrscr();
   cout << "Legroom seat :- $"<<seatmap[0][0].seatprice<<endl
      <<"Window seat :- $"<<seatmap[1][0].seatprice<<endl
      <<"Aisle seat :- $"<<seatmap[1][1].seatprice<<endl;
   system("PAUSE"); // lousy but does the job
}


int main()
{
   InitSeatMap();
   while(1) // infinite loop
   {
      Menu();
      cout<<"Enter choice :- ";
      int input;
      while (!(cin>>input) || input<1 || input>5)
      {
         cerr<<endl<<"error! re-enter"<<endl;
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(),'\n');
      }
      switch(input)
      {
         case 1:  DisplaySeatMap();
                  break;
         case 2:  DisplayPricing();
                  break;
         case 3:  DisplaySales();
                  break;
         case 4:  PurchaseSeat();
                  break;
         case 5:  cout<<"Exiting.........Goodbye!!!"<<endl;
                  Sleep(2000); // a small wait of 2 secs
                  return 0;
      }
   }
}

Did you manage to make those changes on your own?
Anything you didn't understand?

Hi, Stone_Coder;
thank you so much for helping me out.
I don't know if this is hard work for you or not (prob not), but it was certainly was for me. And I'm glad that you help me through it.
Now I'm not going to lie and say I understood your code. I said I can follow it, not nessarily understood everything. Now that the class is over and it's not rushed, I'm going to go through your code slowly. And it might take me a bit of time to digest everything. So if I'm not posting my questions right away yet, please don't think I'm abandoning it because the project's over and done with (plus I don't think you'd appreciate it if I post everything question I have, 'cause it's quite a lot).
When you said "hopefully" you'd teach me something along the way, you don't know how right you are! I certainly learn a lot from doing this, both from my own experience and from your help.

Oh, I forgot. My PurchaseTicket() function, again, did not look like yours at all. I keep having problems with the structure data thing. And I couldn't get it linked to the DisplaySales() functions. But I understand what I did wrong now...I think. ;)

So I know I said it alot already, but Thanks again!

Karen

yeah, I was about to do that tonight. I just got it done today.
but thanks for the reminder though.

This article has been dead for over six months. Start a new discussion instead.