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

How do I edit this existing program to add a dynamic array? #include<iostream> #

ID: 3532132 • Letter: H

Question

How do I edit this existing program to add a dynamic array?


#include<iostream>

#include<cstdlib>

#include<cstddef>



const int ROWS=7;

typedef char Seats[4];

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 seats

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<<" ";

}

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;

}




Explanation / Answer

dynamic array means the location is dynamically allocated somewhere in memory.


You can use new int[]


so attypedef char Seats[];


you can make Seats a pointer..


and do something like char *Seats = new int[4];

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