Write a seating reservation program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tater1994
    New Member
    • Apr 2014
    • 2

    Write a seating reservation program

    C&M Airlines (Charlie and Mable) operates a small commuter airline with a single plane
    that seats 12 passengers. The plane makes one flight per day. Write a seating reservation
    program as described.

    The passenger information is stored in an array of 12 structures. This array should be
    maintained in the main() function. Each structure holds the seat ID, a marker that
    indicates if the seat has been assigned, a passenger first name and a passenger last name.

    _______________ _______________ _______________ _______
    (this is what i have, but im completely stomped. Please help)
    #include "stdafx.h"
    #include <string.h>

    void menu();
    void showEmptySeats( );

    int _tmain(int argc, _TCHAR* argv[])
    {


    typedef struct
    {
    char firstname[21];
    char lastname[20];
    int id;
    int taken;
    } info;


    info airplane[12];
    menu();

    return 0;
    }

    void menu()
    {


    char choice[10];


    printf("a.) Show number of empty seats\nb.) Show list of empty seats\nc.) Assign a seat\nd.) Delete a seat assignment\ne.) Quit\n\nPlease choose an option: ");
    scanf("%s", choice);

    /* Execute function */
    if(strcmp("a",c hoice)==0) showEmptySeats( );
    else if(strcmp("b",c hoice)==0) printf ("b");
    else if(strcmp("c",c hoice)==0) printf ("c");
    else if(strcmp("d",c hoice)==0) printf ("d");
    else if(strcmp("e",c hoice)==0) printf ("e");
    }


    void showEmptySeats( )
    {

    };
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Where is your main()?

    It looks like menu() is really your main().

    Get what you have to compile.

    Then implement one choice, like display the empty seats.
    Get that to work and then work on another choice. You should be able to out this together piecemeal just fine.

    Post again.

    Comment

    • tater1994
      New Member
      • Apr 2014
      • 2

      #3
      Alright so i just typed this up w/ my roomate and it somewhat works but i think the calculations are wrong. Please help me make it smoother and better... Using Visual Studios

      Code:
      #include "StdAfx.h"
      #include <iostream> 
      #include <string>
      #include <cstring>
      using namespace std;
      
      int assignSeat(int seat_num, int row_num, int pass_num);
      int num1(char*);
      int num2(char*);
      
      
      int NumSeats = 12;
      
      void Reserve();
      void Cancel();
      void ChangeSeat();
      void Display();
      void InitializeSeats();
      
      struct Seat 
        {
      	  char pass_name[20];
      	  int Available;
        };
        
        struct Seat SeatArray[6][2];
        
      int main()
      {	  
         char seatchioce = 0;
         int row_num = 6;
         char a = 0;
         char w = 0;
        
        int total_passenger = 12;
         
        char arr1[][6] = {"A","A","A","A","A","A"};
        char arr2[][6] = {"B","B","B","B","B","B"};
      	
        int MenuChoice;
       
        InitializeSeats();
        while(1)
        {
      	  cout << " 1. Reserve a seat" << endl;
      	  cout << " 2. Cancel a seat" << endl;
      	  cout << " 3. Change a Seat" << endl;
      	  cout << " 4. Display empty seats" << endl;
      	  cout << " 5. Exit" << endl;
      
      	  cout << "Enter your choice: ";
      	  cin >> MenuChoice;
      
      	if((MenuChoice < 0) && (MenuChoice > 5))
      	{
      	  cout << "Invalid" << endl;
      	 
      	}
      	else
      	{
      		switch(MenuChoice)
      		{
      			case 1: Reserve();
      				break;
      			case 2: Cancel();
      				break;
      			case 3: ChangeSeat();
      				break;
      			case 4: Display();
      				break;
      			case 5:
      				exit(1);
      		}
      	}
      	cin.get();  
        }
        
      return 0; 
      
      }
      void Reserve() /*reserve the seats*/
      {
      	int pass_num = 0;
      		 
      	 cout << "All " << NumSeats << " seats are available " << endl;
      	
      	 for(int i = 0; i < 6; i++)
      	 {
      		 for(int j = 0; j < 2; j++)
      		 {
      			 if(SeatArray[i][j].Available == 1)
      			 {
      				 cout << "Please enter the passenger name: ";
      				 cin >> SeatArray[i][j].pass_name;
      				 SeatArray[i][j].Available = 0;
      				 NumSeats--;
      				 return;
      			 }
      		 }
      		 
      	 }
      }
      void Cancel()/*Cancel the seat*/
      {
      	char CancelPassengerName[20];
      
      	cout << "Enter the Passenger to be cancelled: ";
      	cin >> CancelPassengerName;
      	for(int i =0; i <6; i++)
      	{
      		for(int j=0; j<2; j++)
      		{
      			
      			if(strcmp(SeatArray[i][j].pass_name, CancelPassengerName) == 0) 
      			{
      				NumSeats++;
      				SeatArray[i][j].Available = 1;
      				return;
      			}
      		}
      	}
      	cout << " Passenger not in the list" << endl;
      }
      void ChangeSeat()/*Change the seat*/
      {
      	char MovePassenger[20];
      	int SeatRow, SeatColumn;
      
      	cout << "Enter the passenger name to be moved: ";
      	cin >> MovePassenger;
      
      	for(int i = 0; i < 6; i++)
      	{	for(int j = 0; j < 2; j++)
      		{
      			if(strcmp(SeatArray[i][j].pass_name, MovePassenger) == 0) 
      			{
      				SeatRow = i;
      				SeatColumn = j;
      			}
      		}
      	}
      
      	if(NumSeats <= 0)
      	{
      		cout << "Seat unavailable" << endl;
      		return;
      	}
      	else{
      		for(int i = 0; i < 6; i++)
      		{
      			for(int j = 0; j < 2; j++)
      			{
      				if(SeatArray[i][j].Available == 1)
      				{
      					strcpy_s(SeatArray[i][j].pass_name, MovePassenger);
      					SeatArray[SeatRow][SeatColumn].Available = 1;
      					SeatArray[i][j].Available = 0;
      
      					return;
      				}
      			}
      		}
      	}
      }
      void Display()/*Display the seat assingment*/
      {
      	for(int i = 0; i < 6; i++)
      	{
      		for(int j = 0; j < 2; j++)
      		{
      			if(SeatArray[i][j].Available == 0)
      			{
      				cout << SeatArray[i][j].pass_name << " = " << NumSeats << endl;
      			}
      			else
      			{
      				if(j == 1)
      					cout << i+1 << "B" << endl;
      				else
      					cout << i+1 << "A" << endl;
      			}
      		}
      	}
      }
      
      void InitializeSeats()/*all available seats*/
      {
      	for(int i = 0; i < 12; i++)
      	{
      		for(int j = 0; j < 2; j++)
      			SeatArray[i][j].Available = 1;
      	}
      }

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This code:
        Code:
        #include "StdAfx.h"
        can be avoided by creating a console application rather than a Windows console application:

        1)create a Win32 project
        2)when the wizard appears, do not click finish
        3)instead click application settings
        4)select console application, select empty project
        5)click finish.

        This code:
        Code:
        struct Seat SeatArray[6][2];
        can be a one dimensional array of 12. The seat mapping does not have to match the actual aircraft. Maybe odd number elements are A (1,3,5,7,9,11) and even number elements are B (0,2,4,6,8,10). But what you have still works.

        This code:
        Code:
        char arr1[][6] = {"A","A","A","A","A","A"};
        char arr2[][6] = {"B","B","B","B","B","B"};
        does not appear to be used.

        This code:
        Code:
        [B]if((MenuChoice < 0) && (MenuChoice > 5))
        	{
        	  cout << "Invalid" << endl;
        [/B]	 
        	}
        	else
        	{
        		switch(MenuChoice)
        		{
        etc...
        looks like the default case of the switch.

        There are several other things of a lesser nature but the overall construction looks sound.

        What is it, exactly, that constitutes a wrong calculation?

        Comment

        Working...