I'll type the assignment I've been given. Then I'll tell you what my problem is, then I'll post my code. I'm sure the answer is probably so freaking stupid and would bite me if it had teeth. :mrgreen:

A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).

Your program should display the following menu of alternatives - Please type 1 for "First Class" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first class section (seats 1-5). If the person types 2, your program should assign a seat in the economy section (seats 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is the first class or economy section of the plane.

Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.

Your program should, of course, never assign a seat that has already been assigned. When the first class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours."


Here is what I can't figure out. I can't seem to figure out how to loop back to where the customer can input what seat type they want again once a seat has been allowed. That's the only way that it will ever fill more than just one seat. Also, I don't know how I'd print a boarding pass. Can someone please help? Here's what I have so far: (Somehow it has no errors. That's good, right?) :D

#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int Seats [ 10 ] = { 0 };
int First_Class = 1;
int Economy = 1;
int Customer_Input;
char Yes_No;


for (int i = 1; i < 10; i++ )
{
 cout << endl;
 cout << "Please type 1 for \"First Class\"" << endl;
 cout << "Please type 2 for \"Economy\"" << endl;
 
 cin >> Customer_Input;

 if ( Customer_Input == 1 ) {
  if ( First_Class << 5 ){

   cout << "Your First Class seat is: " << First_Class << endl;
   First_Class++;
  }

  else if ( First_Class >= 5 ) {

   
   cout << "The First Class section is full.\n" 
    << "Would you like to sit in the Economy Section?\n"
    << "Press 1 for yes, 2 for no.";

   cin >> Yes_No;

   if ( Yes_No == 2 ) {
    
    cout << "Next flight leaves in 3 hours." << endl;
   }

   else if ( Yes_No == 1 ) {

    if ( Economy << 10 ) {

     cout << "Your Economy seat is: " << Economy << endl;
     Economy++;
    }

    else if ( Economy >= 10 ) {

     cout << "The Economy section is also full.\n"
      << "Next flight leaves in 3 hours." << endl;
 }}}}

   if ( Customer_Input == 2 ) {
    if ( Economy << 10 ) {

     cout << "Your Economy seat is: " << Economy << endl;
     Economy++;
    }

    else if ( Economy >= 10 ) {

     cout << "The Economy section is full.\n"
      << "Would you like to sit in the First Class Section?\n"
      << "Type 1 for yes, 2 for no.";

     cin >> Yes_No;

     if ( Yes_No == 2 ) {
    
    cout << "Next flight leaves in 3 hours." << endl;
   }

   else if ( Yes_No == 1 ) {

    if ( First_Class << 5 ) {

     cout << "Your First Class seat is: " << First_Class << endl;
     First_Class++;
    }

    else if ( First_Class >= 5 ) {

     cout << "The First Class section is also full.\n"
      << "Next flight leaves in 3 hours." << endl;
   }}}}

    return 0;
}}

This is an example i did for your question. It's a simple source code, hope you can understand. As for print a boarding pass, run the program and see whether it is this way. If isn't, please let me know the answer.

#include <iostream>
#include <cstdlib>

using namespace std;


// THIS FUNCTION is CALLED when FIRST CLASS is FULL
void econ(int tempSeat[]){

	for(int j=5; j<10; j++){
		if(tempSeat[j]==0){
			tempSeat[j] = 1;

			cout<<"\n**********Boarding Pass **********"<<endl;
			cout<<"Your Seat Number is "<<j+1<<endl;
			cout<<"Economy Class Airline Ticket."<<endl;
			break;

		}

	}

}

// THIS FUNCTION is CALLED when EConomy CLASS is FULL
void first(int tempSeat[]){

		for(int j=0; j<5; j++){
		if(tempSeat[j]==0){
			tempSeat[j] = 1;

			cout<<"\n**********Boarding Pass **********"<<endl;
			cout<<"Your Seat Number is "<<j+1<<endl;
			cout<<"Economy Class Airline Ticket."<<endl;
			break;

		}

	}

}


void main(){

	char answer = 'Y';
	int seatNo[10] = {0};  // initailize the seat to 0;
	int num = 0;   // the loop will exit if num = 3
	int choice =0; // choose whether fist class or economy
	bool full = true;  // boolean function to check whether economy && First Class seat is empty
	bool EconEmpty = false; // check whether the economy is empty 
	bool FirstCEmpty = false; // check whether the first class is empty

	cout<<"Welcome to MyAirline Automated reservations system"<<endl;
	cout<<"=================================================="<<endl;
	
	while(num != 3){

		cout<<"\nPlease type 1 for \"First Class\"" << endl;
		cout << "Please type 2 for \"Economy\"" << endl;
		cin>>choice;

		if (choice == 1){
			
			bool empty = false;
			for(int j=0; j<5; j++){
				if(seatNo[j] == 0)
					empty = true;
			}

			if(empty){

				for(int i=0; i<5; i++)
				{
					if(seatNo[i] == 0){
						seatNo[i] = 1;

						cout<<"\n**********Boarding Pass **********"<<endl;
						cout<<" Your Seat Number is "<<i+1<<endl;
						cout<<" First Class Airline Ticket."<<endl;
						break;

					}

				}

			}

			else
			{
				cout<<"Sorry, first class is full"<<endl;
				cout<<"Do you want to book for economy section ?[y/n]";
				cin>>answer;

				if(toupper(answer)=='Y'){
					

					for(int Ino=5; Ino <10; Ino++){
						if(seatNo[Ino]==0)
							EconEmpty = true;
					}

					if(EconEmpty == true)
						econ(seatNo);

					else{
						cout<<"Sorry the airline ticket is fully book."<<endl;
						do{

							cout<<"\n\nFisrt Class and Economy Class is Full."<<endl;
							cout<<"Press (3) to exit."<<endl;
							cin>>num;

						}while(num != 3);
					}

				}

				else
					cout<<"Next flight leaves in 3 hours."<<endl<<endl;
			}

		}
		
		if(choice == 2){
		
			bool empty = false;
			for(int j = 5; j<10; j++){
				if(seatNo[j] == 0)
					empty = true;
			}

			if(empty){

				for(int i=5; i<10; i++)
				{
					if(seatNo[i] == 0){
						seatNo[i] = 1;

						cout<<"\n**********Boarding Pass **********"<<endl;
						cout<<" Your Seat Number is "<<i+1<<endl;
						cout<<" Economy Class Airline Ticket."<<endl;
						break;

					}

				}

			}

			else
			{
				cout<<"Sorry, Economy class is full"<<endl;
				cout<<"Do you want to book for First class section ?[y/n]";
				cin>>answer;

				if(toupper(answer)=='Y'){

					for(int Tno=0; Tno <5; Tno++){
						if(seatNo[Tno]==0)
							FirstCEmpty = true;
					}

					if(FirstCEmpty == true)
						first(seatNo);
					else
					{
						cout<<"Sorry the airline ticket is fully book."<<endl;
						
						do{

							cout<<"\n\nFirst Class and Economy Class is Full."<<endl;
							cout<<"Press (3) to exit."<<endl;
							cin>>num;

						}while(num !=3);
					}
				}

				else
					cout<<"Next flight leaves in 3 hours."<<endl<<endl;
			}
		}

		if(num == 3){
			cout<<"Thank You........"<<endl;
		}

	}

}

Wow. :eek: Yeah, what you wrote works. Now I just have to sit down and figure out how to take what you wrote and put it into my own program. A lot of the stuff you used seems over my head, and I don't think we got to that in class yet. I don't want to just take your program and use it as my own (as tempting as it is). Thank you so much. If anything, I can just sit down and dissect your code and figure it out for myself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.