0% found this document useful (0 votes)
78 views7 pages

Airplane Board Pass Code (In C ++)

The document describes an airplane boarding pass program with the following key aspects: 1. It defines a structure to store passenger details and constants for the seating plan dimensions. 2. Functions are created to output the seating plan, reserve a seat, input passenger info, and print the boarding pass. 3. The main function initializes an empty seating plan, reserves a seat by calling the relevant functions, and prints the boarding pass.

Uploaded by

kittycatt922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views7 pages

Airplane Board Pass Code (In C ++)

The document describes an airplane boarding pass program with the following key aspects: 1. It defines a structure to store passenger details and constants for the seating plan dimensions. 2. Functions are created to output the seating plan, reserve a seat, input passenger info, and print the boarding pass. 3. The main function initializes an empty seating plan, reserves a seat by calling the relevant functions, and prints the boarding pass.

Uploaded by

kittycatt922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Ayesha Khalid Reg. No.

: FA23-BEE-032

Airplane Boarding Pass


Algorithm:
Include necessary libraries:

Include iostream, iomanip, and string.

Define a structure for passenger information:

Create a structure named PassInfo.

Declare constant values for seating plan dimensions:

Declare constants for the number of rows and columns.

Define a function to output the seating plan:

Create a function named OutputSeatingPlan to print the seating plan.

Define a function to reserve a seat:

Create a function named ReservedSeat to reserve a seat and return true if successful.

Define a function to input passenger information:

Create a function named PassengerInfo to input details about the passenger.

Define a function to print boarding pass information:

Create a function named BoardingPass to print the passenger's information.

Implement the main function:

Declare a seating plan array and variables for the reserved seat's row and column.
Call ReservedSeat to reserve a seat. If successful:
Create a PassInfo structure for the passenger.
Adjust the seat number based on the row and column.
Call PassengerInfo to input passenger details.
Call OutputSeatingPlan to display the updated plan.
Call BoardingPass to print the boarding pass information.

End.

Code:
#include <iostream>

#include <iomanip>
#include <string>

using namespace std;

//Structure for passenger info:

struct PassInfo

string name;

char gender;

int age;

string seatClass;

int seatNo;

string baggage;

string meal;

};

//These values will remain constant throughout the program:

const int rows = 13;

const int colm = 6;

void OutputSeatingPlan(const char SeatingPlan[rows][colm])

cout << " Seating Plan: \n";

for (int i = 0; i < rows; i++)

for (int j = 0; j < colm; j++)

{
cout << setw(5) << SeatingPlan[i][j] << setw (5) << endl;

cout << endl;

bool ReservedSeat(char SeatingPlan[rows][colm], int &row, int &col)

cout << "Enter row of your seat: ";

cin >> row;

cout << "Enter column of your seat: ";

cin >> col;

if ( row < 0 || row > rows || col < 0 || col >= colm)

cout << "Invalid Seat Selection. Please try again! \n";

return false;

//'X' represents the reserved seats

if (SeatingPlan[row-1][col]== 'X')

cout << "Seat is taken. Please try again! \n";

return false;

SeatingPlan [row-1][col] = 'X';


return true;

void PassengerInfo(PassInfo& passenger)

cout << "Enter Name: \n";

cin.ignore();

getline(cin, passenger.name);

cout << "Enter Gender (M/F): \n";

cin >> passenger.gender;

cout << "Enter Age: \n";

cin >> passenger.age;

cout << "Enter Class (Economy/Business/First): \n";

cin >> passenger.seatClass;

cout << "Enter Seat Number: \n";

cin >> passenger.seatNo;

cout << "Enter Baggage Info: \n";

cin >> passenger.baggage;

cout << "Enter meal: \n";

cin >> passenger.meal;

}
void BoardingPass(const PassInfo& passenger)

cout << "Boarding Pass Information: \n";

cout << "Name: " << setw(3) << passenger.name << endl;

cout << "Gender : " << setw(3) << passenger.gender << endl;

cout << "Age: " << setw(3) << passenger.age << endl;

cout << "Seat Class: " << setw(3) << passenger.seatClass << endl;

cout << "Seat Number: " << setw(3) << passenger.seatNo << endl;

cout << "Baggage: " << setw(3) << passenger.baggage << endl;

cout << "Meal: " << setw(3) << passenger.meal << endl;

int main()

char SeatingPlan[rows][colm] = {};

int row, col;

if (ReservedSeat(SeatingPlan, row, col))

PassInfo passenger;

passenger.seatNo = row * 10 + col;

PassengerInfo(passenger);

OutputSeatingPlan(SeatingPlan);

BoardingPass(passenger);

return 0;
}

Explanation:
Data Structure:

The program defines a structure called PassInfo to store information about passengers. It includes
fields such as name, gender, age, seat class, seat number, baggage information, and meal
preferences.

Constants:

Constants are set for the number of rows (13) and columns (6) in the airplane seating plan.

Functions:

a. OutputSeatingPlan:

This function displays the current seating plan of the airplane. The seating plan is represented by
a 2D array of characters ('X' indicates reserved seats).

b. ReservedSeat:

Allows a user to reserve a seat by entering the row and column numbers. It checks for seat
availability, validates input, and marks the seat as reserved.

c. PassengerInfo:

Gathers input from the user for passenger details, such as name, gender, age, seat class, seat
number, baggage information, and meal preferences.

d. BoardingPass:

Generates and displays a boarding pass with the passenger's information, including name, gender,
age, seat class, seat number, baggage information, and meal preferences.

Main Function:

Initializes an empty seating plan represented by a 2D array of characters.


Prompts the user to reserve a seat by calling the ReservedSeat function.
If the seat is successfully reserved, it creates a PassInfo object, collects passenger information
using the PassengerInfo function, updates the seating plan, and displays the boarding pass using
the BoardingPass function.

Seat Number Calculation:

The seat number is calculated as row * 10 + col and is assigned to the passenger's seatNo field.

User Interaction:
The program interacts with the user by requesting input for seat reservation and passenger
information.

Output Formatting:

The output is formatted using setw to align and space out the displayed information.

Array Initialization:

The seating plan array is initialized as an empty array, and 'X' is used to represent reserved seats.

You might also like