Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Reserve_seat: This function marks the seat as reserved (what attribute of seat d

ID: 3619507 • Letter: R

Question


Reserve_seat: This function marks the seat as reserved (what attribute of seat do you think you’ll use?) The function simply takes in the row and column of the seat they wish to mark as reserved. The function should return a 1 if the reservation is successful, a zero if the seat is already reserved, and a -1 if the row or column is out of range)


Passenger_info: This function simply prompts the user for passenger info (first name, last name, and age). It then populates the corresponding attributes inside the passenger seated at the location defined by row and column (the functions arguments). This function does not return anything, but you need to check row and column to ensure the numbers supplied to the function are in range.


Print_passengers: This function prints a list of passengers with their corresponding row/column

__________________________________________________________________________

Explanation / Answer

#include <iostream>
using namespace std;
/* These are constants that determine the capacity of an airplane. For now, these values
* are hard coded, but in assignment 4, we'll obtain their value from the command line.
*/
const int ROWS = 10;
const int COLUMNS = 4;
// Define our own types and declare global variables


/* This is where we define the struct passanger. It includes an integer age and two char
* arrays for first and last names.
*/
struct passenger {
char first_name [40];
char last_name [40];
int age;
};

/* This is where we define the struct seat. It includes a passenger and boolean variable
* that is used to determine if a seat is taken or not.
*/
struct seat {
passenger p;
bool taken;
} ;


/* Declare a 2-d array of seats using ROWS and COLUMNS from above. The array is
* global right now (which is dangerous), but we'll fix this in assignment 4.
*/
seat seat_chart[ROWS][COLUMNS];

// Define Functions

/*
* Function name: reserve_seat
* Arguments: two integers, row and column, that identify
* the seat being reserved
* Output: 0 if the seat is taken, 1 if reservation succeeds
* Purpose: This function updates the global seat_chart array when a seat
* is reserved.
*/

int reserve_seat (int row, int column)
{
bool answer = false;

if (row & column == 0)
{
answer = false;
}
else if (row & column == 1)
{
answer = true;
}

}

/*
* Function name: passenger_info
* Arguments: two integers, row and column, that identify
* the seat being reserved
* Output: nothing, but the global passenger at the seat located
* in the airplane at row, column is populated
* Purpose: Populate the contents of a passenger. The function
* requests info from the user.
*/
void passenger_info(int row, int column)
{cout<<"Making reservation. ";
cout<<"Enter your first name: ";
cin>>seat_chart[row-1][column-1].p.first_name;
cout<<"Enter your last name: ";
cin>>seat_chart[row-1][column-1].p.last_name;
seat_chart[row-1][column-1].taken = true;   // getting an error


}


/*
* Function name: print_passengers
* Arguments: none
* Output: A print out of passengers formated like
* "Seat: -: "
* Purpose: Prints a list of passengers
*/
void print_passengers ()
{cout<<"Passenger List ";

int i,j;
for(i=0;i<ROWS;i++)
   for(j=0;j<COLUMNS;j++)
        if(seat_chart[i][j].taken)
             cout<<"Row "<<i+1<<", seat "<<j+1<<" "<<seat_chart[i][j].p.first_name<<" "<<seat_chart[i][j].p.last_name<<endl;


}

int main ()
{

// Local variables to main
int num_taken = 0;
int row = 0;
int column = 0;
char response;
bool keep_going = 1;
int i;

// Here is where I ensure the memory I'm using no longer garbage
// I just set the memory to zero
memset (seat_chart, 0, sizeof(seat_chart));


// Present the menu
do {
cout<<"=================== SEATING AVAILABILITY ============================ ";


// Print availability
for (int i=0; i< ROWS; i++)
{
   num_taken = 0;
   for(int j=0; j<COLUMNS;j++)
      {
       if (seat_chart[i][j].taken)
        num_taken++;
      }
if(num_taken!=COLUMNS)
       cout<<"Row "<<i+1<<" has available seats. ";
}

// Prompt user
cout<<"Would you like to reserve a seat? (Y)es/(N)o: ";
cin>>response;


// Process the users response
switch (response)
{

// if the user said yes, we need to find out what seat and then attempt
// to make the reservation
case 'y':
case 'Y':
do
{
cout<<"What seat would you like to reserve? Row (1- "<<ROWS<<"): ";
cin>>row;
if(row<1||row>ROWS)
    cout<<"Invalid row ";
}while(row<1||row>ROWS);
do
{
cout<<" Seat (1- "<<COLUMNS<<"): " ;
cin>>column;
if(column<1||column>COLUMNS)
    cout<<"Invalid column ";
}while(column<1||column>COLUMNS);
if(seat_chart[row-1][column-1].taken)    // getting an error
cout<<"That seat is already reserved. Please try again. ";
else
{passenger_info(row,column);

break;
}
// Ask the user what seat and store answer

//Process the seat request using the reserve_seat function. Use the
// return value to determine if you should call the passenger_info function
// or output an error message.

// If they said no, print passengers (using print_passengers function) and exit
case 'n':
case 'N':
cout<< "Thanks. Good-bye!";


keep_going = false;
}
}
while(keep_going);
print_passengers();
system("pause");


return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote