I have this little program that assign seat for ailine passenger, it's work, but I want to add so that it display the name of (passenger = seat number) so far I only got it to display the passenger name in the spot of that seat number. I try set_num then I get and error, if I use NumSeats it display that passenger name = 11, it suppost to display passenger name = 1A, 1B......etc. Can anyone tell me what I need to do here

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

//Declare function proto type
int assignSeat(int seat_num, int row_num, int pass_num);
int num1(char*);
int num2(char*);

int NumSeats = 12;

void InitializeSeats();
void Reserve();
void Cancel();
void ChangeSeat();
void Display();

struct Seat 
  {
      char pass_name[80];
      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] = {"1A","2A","3A","4A","5A","6A"};
  char arr2[][6] = {"1B","2B","3B","4B","5B","6B"};
    
  int MenuChoice;

  InitializeSeats();
  while(1)
  {
      cout << " 1. Reserve" << endl;
      cout << " 2. Cancel" << endl;
      cout << " 3. Change Seat" << endl;
      cout << " 4. Display" << endl;
      cout << " 5. Exit" << endl;

      cout << "Enter your choice: ";
      cin >> MenuChoice;

    if((MenuChoice < 0) && (MenuChoice > 5))
    {
      cout << "Invalid Choice" << endl;
      system("Pause Try Again");
    }
    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() //This function is for reserv the seats
{
    int pass_num = 0;

    cout << "Wellcome to CheapSkate Airline Passenger seat assignment" << endl;
         
     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()// This function is for Cancel the seat
{
    char CancelPassengerName[80];

    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()//This function is for Change the seat
{
    char MovePassenger[80];
    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 << "No seat available there for you cannot change seat" << 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 the all reservation
{
    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()//Initialy all seats are available
{
    for(int i = 0; i < 12; i++)
    {
        for(int j = 0; j < 2; j++)
            SeatArray[i][j].Available = 1;
    }
}

you declared arrays arr1 and arr2 but they are not used anywhere...anyway you want to access a seat which is supposed to be stored in an array..so to display this your supposed to access that array...i think the arr1 and arr2 should help you in this...your supposed to do some sort of handling so that when the name is input, a seat in the array is made unavailable and that seat is what should be displayed

Hello joshmo,

Thanks for your replied, actually I have added the

if (j == 0) 
                    { 
                    cout << "A" << endl; 
                    }  
                     else 
                        { 
                         cout << "B" << endl;
                        }

to display where I test "j" and added 1 to "i".

you declared arrays arr1 and arr2 but they are not used anywhere...anyway you want to access a seat which is supposed to be stored in an array..so to display this your supposed to access that array...i think the arr1 and arr2 should help you in this...your supposed to do some sort of handling so that when the name is input, a seat in the array is made unavailable and that seat is what should be displayed

Hello joshmo,

Thanks for your replied, actually I have added the

if (j == 0) 
                    { 
                    cout << "A" << endl; 
                    }  
                     else 
                        { 
                         cout << "B" << endl;
                        }

to display where I test "j" and added 1 to "i".

you declared arrays arr1 and arr2 but they are not used anywhere...anyway you want to access a seat which is supposed to be stored in an array..so to display this your supposed to access that array...i think the arr1 and arr2 should help you in this...your supposed to do some sort of handling so that when the name is input, a seat in the array is made unavailable and that seat is what should be displayed

is it working now??

yes, it work very good. Some one may need and can use this code.

Thanks,

is it working now??

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.