3 Replies - 2223 Views - Last Post: 12 October 2012 - 12:08 PM Rate Topic: -----

#1 Hossein1822  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 05-March 11

Program that can be used to assign seats for a commercial airplane

Posted 12 October 2012 - 06:07 AM

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

//function prototypes
void menuOptions();
void typeCheck( char ticketType ,int &row, char &seat);


char getChoice() 
    {
        menuOptions();
        char choice;
        cout << "\n\nENTER CHOICE ---> [";
        cin >> choice;
        system("cls");
        return choice;
    }

// if false, exit program
bool doMenu() 
  {
    switch(getChoice())
      {
        case 'F':
        case 'f':
             typeCheck();
             break;
              
        case 'B':
        case 'b':
             typeCheck();
             break;
    
        case 'E':
        case 'e':
             typeCheck();
             break;
        
        case 'X':
        case 'x':
            return false;
             break;
             
        default:
             cout << "\nInvalid choice..." << endl;
             cout << "Choose again.\n";
  }
     return true;
}
//main function
int main()
{
    system("Title Hossein Patterson");
    system("color 58");
	int i, j;
	char ticketType;
	char availability [13][6];
	int seats = (13 - 1) * (6 - 1);
	int row = 0;
	char seat;
	int seatsTaken = 0;
    int rowIndex, seatIndex;
	char response = 'y';

  while (seatsTaken < seats && response == 'y')
    {
        
	cout << "This program assigns seats for a commercial airplane." << endl << "The current seat assignment is as follows." << endl << endl << "\t\tA\tB\tC\tD\tE\tF" << endl;

	for (i=0; i<13; i++){
		cout << "Row " << i+1 << "\t\t";
		for (j=0; j<6; j++){
			cout << "*" << "\t";
			availability[i][j]='*';
		}
		cout << endl;
	}
}

	cout << endl << "* -- available seat" << endl 
		<< "X -- occupied seat" << endl << endl
 	    << "Rows 1 and 2 are for first class passengers."<< endl
		<<"Rows 3 through 7 are for business class passengers."<< endl
		<<"Rows 8 through 13 are for economy class passengers."<< endl;
		cout << endl;
		
      rowIndex = row;  
      seatIndex = toupper(seat) - 'A' + 1;

      // Check to see if seat is taken
      if (availability[rowIndex][seatIndex] == 'X')
	cout << "Sorry, " << row << seat << " is already taken." << endl;
      else
	{
	  cout << "OK, you've got " << row << seat << endl;
	  availability[rowIndex][seatIndex] = 'X';
	  seatsTaken++;
	}
      
      // If there are seats left, check we should keep going
      if (seatsTaken < seats)
	{
	cout << "Choose another seat? (y/n) ";
	cin >> response;
	}
      else
	cout << "Plane is now full!" << endl;
    		
 	  system("pause");
	return 0;
}

void menuOptions ()
  {
     cout <<"                             MENU OPTIONS                          \n";
     cout <<"                       ***********************                    \n\n\n";
     cout << "PRESS [F] - FOR FIRST CLASS" << endl;
     cout << "PRESS [B] - FOR BUSINESS CLASS" << endl;
     cout << "PRESS [E] - FOR ECONOMY CLASS " << endl;
     cout << "PRESS [X] - TO EXIT PROGRAM" << endl;

  }//end of menuOptions function


void typeCheck( char ticketType ,int &row, char &seat )
{
     bool Input;
     if ( ticketType == 'F')
    {  Input = true;
  while(Input)
  {
     cout << "Enter the row(1-2) and seat(A-F) you would like (e.g., 3D): ";
                  cin >> row >> seat;
                  cout << "\n";
                  seat = toupper(seat);
                  if ((row >= 1) && (row <= 2))
                  {
                           
                           
                             if( seat == 'A')
                             Input = false;
                             else if ( seat == 'B')
                             Input = false;
                             else if ( seat == 'C')
                             Input = false;
                             else if ( seat == 'D')
                             Input = false;
                             else if (seat == 'E' )
                             Input = false;
                             else if ( seat == 'F')
                             Input = false;
                             else
                             {Input = true;
                             cout << "Invalid input. try again " << endl;}
                             cout << "\n";
                              }
                              else 
                              {
                              cout << "\n";}
                  }
                  }
          else if ( ticketType == 'B')    
           {Input = true;
  while(Input)
  {
     cout << "Enter the row(3-7) and seat(A-F) you would like (e.g., 3D): ";
                  cin >> row >> seat;
                  cout << "\n";
                  seat = toupper(seat);
                  if ((row >= 3) && (row <= 7))
                  {
                           
                           
                             if( seat == 'A')
                             Input = false;
                             else if ( seat == 'B')
                             Input = false;
                             else if ( seat == 'C')
                             Input = false;
                             else if ( seat == 'D')
                             Input = false;
                             else if (seat == 'E' )
                             Input = false;
                             else if ( seat == 'F')
                             Input = false;
                             else
                             {Input = true;
                             cout << "Invalid input. try again " << endl;}
                              cout << "\n";}
                              else 
                              {
                              cout << "\n";}
                  } 
                  }
                  else if ( ticketType == 'E')
                  {Input = true;
  while(Input)
  {
     cout << "Enter the row(8-13) and seat(A-F) you would like (e.g., 3D): ";
                  cin >> row >> seat;
                  cout << "\n";
                  seat = toupper(seat);
                  if ((row >= 8) && (row <= 13))
                  {                         
                             if( seat == 'A')
                             Input = false;
                             else if ( seat == 'B')
                             Input = false;
                             else if ( seat == 'C')
                             Input = false;
                             else if ( seat == 'D')
                             Input = false;
                             else if (seat == 'E' )
                             Input = false;
                             else if ( seat == 'F')
                             Input = false;
                             else
                             {Input = true;
                             cout << "Invalid input. try again " << endl;}
                              cout << "\n";}
                              else 
                             {
                             cout << "\n";}
                  } 
                  }
                  
                  }







What am i doing wrong here....i keep getting too few arguments here void typeCheck( char ticketType ,int &row, char &seat);



Is This A Good Question/Topic? 0
  • +

Replies To: Program that can be used to assign seats for a commercial airplane

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4286
  • View blog
  • Posts: 13,452
  • Joined: 25-December 09

Re: Program that can be used to assign seats for a commercial airplane

Posted 12 October 2012 - 06:37 AM

How many arguments does your function call have?
            typeCheck();

How many arguments does your function require?
typeCheck( char ticketType ,int &row, char &seat);

Your function call must have the same number of parameters as your function implementation.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 Hossein1822  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 05-March 11

Re: Program that can be used to assign seats for a commercial airplane

Posted 12 October 2012 - 10:21 AM

I removed the arguments and now the program crashing....what do i do to fix this?

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

//function prototypes
void menuOptions();
void typeCheck();


char getChoice() 
    {
        menuOptions();
        char choice;
        cout << "\n\nENTER CHOICE ---> [";
        cin >> choice;
        system("cls");
        return choice;
    }

// if false, exit program
bool doMenu() 
  {
    switch(getChoice())
      {
        case 'F':
        case 'f':
             typeCheck();
             break;
              
        case 'B':
        case 'b':
             typeCheck();
             break;
    
        case 'E':
        case 'e':
             typeCheck();
             break;
        
        case 'X':
        case 'x':
            return false;
             break;
             
        default:
             cout << "\nInvalid choice..." << endl;
             cout << "Choose again.\n";
  }
     return true;
}
//main function
int main()
{
    system("Title Hossein Patterson");
    system("color 58");
	int i, j;
	char ticketType;
	char availability [13][6];
	int seats = (13 - 1) * (6 - 1);
	int row = 0;
	char seat;
	int seatsTaken = 0;
    int rowIndex, seatIndex;
	char response = 'y';

  while (seatsTaken < seats && response == 'y')
    {
        
	cout << "This program assigns seats for a commercial airplane." << endl << "The current seat assignment is as follows." << endl << endl << "\t\tA\tB\tC\tD\tE\tF" << endl;

	for (i=0; i<13; i++){
		cout << "Row " << i+1 << "\t\t";
		for (j=0; j<6; j++){
			cout << "*" << "\t";
			availability[i][j]='*';
		}
		cout << endl;
	}
}

	cout << endl << "* -- available seat" << endl 
		<< "X -- occupied seat" << endl << endl
 	    << "Rows 1 and 2 are for first class passengers."<< endl
		<<"Rows 3 through 7 are for business class passengers."<< endl
		<<"Rows 8 through 13 are for economy class passengers."<< endl;
		cout << endl;
		
      rowIndex = row;  
      seatIndex = toupper(seat) - 'A' + 1;

      // Check to see if seat is taken
      if (availability[rowIndex][seatIndex] == 'X')
	cout << "Sorry, " << row << seat << " is already taken." << endl;
      else
	{
	  cout << "OK, you've got " << row << seat << endl;
	  availability[rowIndex][seatIndex] = 'X';
	  seatsTaken++;
	}
      
      // If there are seats left, check we should keep going
      if (seatsTaken < seats)
	{
	cout << "Choose another seat? (y/n) ";
	cin >> response;
	}
      else
	cout << "Plane is now full!" << endl;
    		
 	  system("pause");
	return 0;
}

void menuOptions ()
  {
     cout <<"                             MENU OPTIONS                          \n";
     cout <<"                       ***********************                    \n\n\n";
     cout << "PRESS [F] - FOR FIRST CLASS" << endl;
     cout << "PRESS [B] - FOR BUSINESS CLASS" << endl;
     cout << "PRESS [E] - FOR ECONOMY CLASS " << endl;
     cout << "PRESS [X] - TO EXIT PROGRAM" << endl;

  }//end of menuOptions function


void typeCheck()
{
     char ticketType;
     int row;
     int seat;
     bool Input;
     if ( ticketType == 'F')
    {  Input = true;
  while(Input)
  {
     cout << "Enter the row(1-2) and seat(A-F) you would like (e.g., 3D): ";
                  cin >> row >> seat;
                  cout << "\n";
                  seat = toupper(seat);
                  if ((row >= 1) && (row <= 2))
                  {
                           
                           
                             if( seat == 'A')
                             Input = false;
                             else if ( seat == 'B')
                             Input = false;
                             else if ( seat == 'C')
                             Input = false;
                             else if ( seat == 'D')
                             Input = false;
                             else if (seat == 'E' )
                             Input = false;
                             else if ( seat == 'F')
                             Input = false;
                             else
                             {Input = true;
                             cout << "Invalid input. try again " << endl;}
                             cout << "\n";
                              }
                              else 
                              {
                              cout << "\n";}
                  }
                  }
          else if ( ticketType == 'B')    
           {Input = true;
  while(Input)
  {
     cout << "Enter the row(3-7) and seat(A-F) you would like (e.g., 3D): ";
                  cin >> row >> seat;
                  cout << "\n";
                  seat = toupper(seat);
                  if ((row >= 3) && (row <= 7))
                  {
                           
                           
                             if( seat == 'A')
                             Input = false;
                             else if ( seat == 'B')
                             Input = false;
                             else if ( seat == 'C')
                             Input = false;
                             else if ( seat == 'D')
                             Input = false;
                             else if (seat == 'E' )
                             Input = false;
                             else if ( seat == 'F')
                             Input = false;
                             else
                             {Input = true;
                             cout << "Invalid input. try again " << endl;}
                              cout << "\n";}
                              else 
                              {
                              cout << "\n";}
                  } 
                  }
                  else if ( ticketType == 'E')
                  {Input = true;
  while(Input)
  {
     cout << "Enter the row(8-13) and seat(A-F) you would like (e.g., 3D): ";
                  cin >> row >> seat;
                  cout << "\n";
                  seat = toupper(seat);
                  if ((row >= 8) && (row <= 13))
                  {                         
                             if( seat == 'A')
                             Input = false;
                             else if ( seat == 'B')
                             Input = false;
                             else if ( seat == 'C')
                             Input = false;
                             else if ( seat == 'D')
                             Input = false;
                             else if (seat == 'E' )
                             Input = false;
                             else if ( seat == 'F')
                             Input = false;
                             else
                             {Input = true;
                             cout << "Invalid input. try again " << endl;}
                              cout << "\n";}
                              else 
                             {
                             cout << "\n";}
                  } 
                  }
                  
                  }



Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4286
  • View blog
  • Posts: 13,452
  • Joined: 25-December 09

Re: Program that can be used to assign seats for a commercial airplane

Posted 12 October 2012 - 12:08 PM

Why did you decide to remove the parameters from your function? To me it would seem better to add the proper variables to the function call after all it seems like your function needs these arguments to function properly.

Jim

This post has been edited by jimblumberg: 12 October 2012 - 12:08 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1