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

Assume that the reservation for an airplane flight have been stored in a file ca

ID: 3621686 • Letter: A

Question

Assume that the reservation for an airplane flight have been stored in a file called flight . The plane contains 38 rows and 6 seats in each row. The seats in each row are numbered 1 – 6 as follows:

Window seat, left side
Center seat, left side
Aisle seat, left side
Aisle seat, right side
Center seat, right side
Window seat, right side
The file flight contains 38 lines of information corresponding to the 38 rows of the plane. Each line contains 6 values corresponding to 6 seats. The value for any seat is either 0 or 1, representing either an empty or an occupied seat.

Write a complete C++ program to read the flight information into a two dimensional array called seat . Find and print all pairs of adjacent seats that are empty. Adjacent aisle seats should not be printed. If all three seats on one side of the plane are empty, then two pairs of adjacent seats should be printed. Print this information in the following manner:

AVAILABLE SEAT PAIRS
Rows Seats
xx x, x
xx x, x
.... ....
.... ....










If no pairs of seats are available on a row, print an appropriate message (like No Empty Pairs ). Test your program using the following flight file.

flight
1 0 0 0 1 1
1 1 0 1 0 0
0 0 1 1 0 1
0 0 0 0 0 0
1 1 1 1 1 1
0 0 0 1 1 1
1 1 1 0 0 0
0 0 1 1 0 0
1 0 1 0 1 0
0 1 0 1 0 1
1 0 0 0 1 1
1 1 0 1 0 0
0 0 1 1 0 1
0 0 0 0 0 0
1 1 1 1 1 1
0 0 0 1 1 1
1 1 1 0 0 0
0 0 1 1 0 0
1 0 1 0 1 0
0 1 0 1 0 1
1 0 0 0 1 1
1 1 0 1 0 0
0 0 1 1 0 1
0 0 0 0 0 0
1 1 1 1 1 1
0 0 0 1 1 1
1 1 1 0 0 0
0 0 1 1 0 0
1 0 1 0 1 0
0 1 0 1 0 1
1 0 0 0 1 1
1 1 0 1 0 0
0 0 1 1 0 1
0 0 0 0 0 0
1 1 1 1 1 1
0 0 0 1 1 1
1 1 1 0 0 0
0 0 1 1 0 0

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const int ROWS = 38;
const int SEATS = 6;

void initArray( ifstream &file, int data[ROWS][SEATS] )
{
    // Read data until end of file.
    while ( !file.eof() )
    {
        for ( int i = 0; i < ROWS; i++ )
        {
            for ( int s = 0; s < SEATS; s++ )
            {
                int r = 0;
                file >> data[r][s];
            }// for
        }// for
    }// while
}// initArray

void printHeader()
{
    cout << "Available Seat Pairs" << endl;
    cout << "Rows   Seats" << endl;
    cout << "----- -----" << endl;
}


void printPairs( const int data[ROWS][SEATS] )
{
    for (int i = 0; i < ROWS; i++)
    {
        for ( int j = 0; j < SEATS-1; j++ )
        {
            int r = 0;
            if ( data[r][j] == data[r][j+1] && ( j != 3 && (j+1) != 4 ) )
                cout << setw(5) << i << " " << j << "," << j+1 << endl;
            r++;
        }
    }
}

int main()
{
    int flightSeats[ROWS][SEATS];
    ifstream plane;

    plane.open( "flight.txt" );
    initArray(plane, flightSeats);

    printHeader();
    printPairs(flightSeats);

    plane.close();

    system( "pause" );
    return 0;
}

The only thing for you to do is to add onto the printPairs() function and implement the statement if no pairs are found. The principle is the same as the rest of the loop, so it should be easy. Make sure you understand all of the code before you submit it to your instructor.

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