I am trying to use a multidimensional dynamic array as an argument in a function. I want to display the seating chart of an airplane. The chart is to have a number of rows specified by the user. Each row has 4 columns. All of the seats in the first column are labeled, A; the second column, B; the third, C; and the fourth, D. For example:
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
When I call the function on line 35 output_seat_chart(seat_chart, num_of_rows);I get a red error line under the argument, seat_chart. When I try to run the program I get the error message, Error (active) argument of type "CharArrayPtr *" is incompatible with parameter of type "char (*)[4]"
#include <iostream>
usingnamespace std;
void output_seat_chart(char seat_chart[][4], int num_of_rows);
typedefchar* CharArrayPtr;
//Defines type name CharArrayPtr that can be used to declare
//pointers to dynamic variables of type char
int main()
{
int num_of_rows;
cout << "Enter the number of rows on the plane: ";
cin >> num_of_rows;
CharArrayPtr *seat_chart = new CharArrayPtr[num_of_rows];
//Creates pointer (seat_chart) to an array of num_of_rows elements.
for (int i = 0; i < num_of_rows; i++)
seat_chart[i] = newchar[4];
//Creates a 4 element array for each seat_chart[0]
//through seat_chart[num_of_rows - 1].
for (int i = 0; i < num_of_rows; i++)
seat_chart[i][0] = 'A';
for (int i = 0; i < num_of_rows; i++)
seat_chart[i][1] = 'B';
for (int i = 0; i < num_of_rows; i++)
seat_chart[i][2] = 'C';
for (int i = 0; i < num_of_rows; i++)
seat_chart[i][3] = 'D';
output_seat_chart(seat_chart, num_of_rows);
system("pause");
return 0;
}
void output_seat_chart(char seat_chart[][4], int num_of_rows)
{
for (int i = 0; i < num_of_rows; i++)
{
cout << i + 1 << ' '
<< seat_chart[i][0] << ' ' << seat_chart[i][1] << ' '
<< seat_chart[i][2] << ' ' << seat_chart[i][3] << endl;
}
cout << endl << endl;
}