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

#include<iostream> #include<cstdlib> #include<cstddef> const int ROWS=7; typedef

ID: 3532138 • Letter: #

Question

#include<iostream>

#include<cstdlib>

#include<cstddef>



  


const int ROWS=7;

typedef char Seats[];

char* Seats=new int[4]//these two lines aren't being done properly

typedef Seats Seating[ROWS];

Seating Assignment;


int main()

{


using std::cout;

using std::cin;

using std::endl;

Seating plan;

char seat;

int row, r, s, seatnumber;

for(r=0; r<ROWS; r++)//nested Loop that initializes rows and seat

for(s=0;s<4;s++)

plan[r][s]= char('A'+s);

cout<<"Airline Seat Reservation "<<"'X' are the reserved seats, while others are available ";

for(r=1;r<ROWS; r++)// nested loops through rows and seats and displays them

{

for(s=0;s<4;s++)

{

cout<<plan[r][s]<<" ";

if(s==1)

cout<<" ";

}

cout<<endl;

}

char choice='a';

while(choice!='q'&& choice!='Q')

{

//inputting reservations for seats

cout<<"Airline Seat Reservation "<<"'X' are the reserved seats, while others are available ";

cout<<"Enter for a reservation in the form '1A' for row 1 seet A, number before letter please ";//has to be entered number before letter but you can put a space between the two

cout<<"There are "<<ROWS<<" rows. A,B,C,D ";

cin>>row>>seat;

seatnumber=seat-'A';

if('X'!=plan[row][seatnumber])

plan[row][seatnumber]='X';

else

cout<<"The seat is not available!!! "

<<"Please try another seat! ";

//nested loops to display the seats again

for(r=1;r<ROWS; r++)

{

for(s=0;s<4;s++)

{

cout<<plan[r][s]<<" ";

if(s==1)

cout<<" ";

int(*Seats)[7]=new int[4][7];

delete[] Seats[s];

delete[] Seats;


}

cout<<endl;

}


cout<<"to quit press 'Q' which is not case sensitive or press anything else other than enter to continue ";

cin>>choice;

}

system("pause");

return 0;

}



What do I need to change to get this working with a dynamic array?


Explanation / Answer

#include<iostream>

#include<cstdlib>

#include<cstddef>




const int ROWS=7;

const int SEATS=4;

typedef char Seats[ROWS][SEATS];

Seats Seating;


int main()

{


using std::cout;

using std::cin;

using std::endl;

char seat;

int row, r, s, seatnumber;

for(r=0; r<ROWS; r++)//nested Loop that initializes rows and seat

for(s=0;s<4;s++)

Seating[r][s]= char('A'+s);

cout<<"Airline Seat Reservation "<<"'X' are the reserved seats, while others are available ";

for(r=0;r<ROWS; r++)// nested loops through rows and seats and displays them

{

for(s=0;s<4;s++)

{

cout<<Seating[r][s]<<" ";

if(s==1)

cout<<" ";

}

cout<<endl;

}

char choice='a';

while(choice!='q'&& choice!='Q')

{

//inputting reservations for seats

cout<<"Airline Seat Reservation "<<"'X' are the reserved seats, while others are available ";

cout<<"Enter for a reservation in the form '1A' for row 1 seet A, number before letter please ";//has to be entered number before letter but you can put a space between the two

cout<<"There are "<<ROWS<<" rows. A,B,C,D ";

cin>>row>>seat;

seatnumber=seat-'A';

if('X'!=Seating[row-1][seatnumber])

Seating[row-1][seatnumber]='X';

else

cout<<"The seat is not available!!! "

<<"Please try another seat! ";

//nested loops to display the seats again

for(r=0;r<ROWS; r++)

{

for(s=0;s<4;s++)

{

cout<<Seating[r][s]<<" ";

if(s==1)

cout<<" ";



}

cout<<endl;

}


cout<<"to quit press 'Q' which is not case sensitive or press anything else other than enter to continue ";

cin>>choice;

}

system("pause");

return 0;

}