PLEASE USE C++ LANGUAGE ONLY!!!! im trying to create a function for my program t
ID: 3823553 • Letter: P
Question
PLEASE USE C++ LANGUAGE ONLY!!!!
im trying to create a function for my program that allows the user to see the statistics of the airplane seats. The statistics include:
Number of available seats, percentage of seats that are reserved, list of window seats that are available, list of aisle seats that are available.
This is what I have so far.
void stats() {
int q = 0;
for (int i = 0; i < COLS; i++)
for (int j = 0; j < ROWS; j++)
{
if (planeSeats[i][j] != "X")
{
q++;
}
}
cout << "The number of available seats are: " << q << endl;
cout << "The percentage of seats that are reserved is: " << (q - 10)/(ROWS*COLS) * 100 << "%" << endl;
cout << "The list of window seats that are available are: " << endl;
cout << "The list of aisle seats available are: " << endl;
The information is stored in an array that include the following information:
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
6 A B C D
7 A B C D
8 A B C D
9 A B C D
10 A B C D
}
PLEASE EDIT THE FUNCTION I HAVE SO FAR using loops arrays and cout and cin statements. This is the fourth time I have posted this question but no one is helping.
Explanation / Answer
#define ROWS=10
#define COLS=4
void stats(int planeSeats[ROWS][COLS])
{
int q = 0, k=0, l=0;
char availableWindowSeats[2*ROWS];
char availableAisleSeats[2*ROWS];
for (int i = 0; i < COLS; i++)
for(int j = 0; j < ROWS; j++)
{
if (planeSeats[i][j] != "X")
{
if(j==0 || j== COLS-1)
{
availableWindowSeats[k]=planeSeats[i][j];
k++;
}
if(j==1 || j===2)
{
availableAisleSeats[l]=planeSeats[i][j];
l++;
}
q++;
}
}
cout << " The number of available seats are: " << q << endl;
cout << " The percentage of seats that are reserved is: " << (ROWS*COLS- q)/(ROWS*COLS) * 100 << "%" << endl;
cout << " The list of window seats that are available are: " << endl;
for(int i=0;i<=j;i++)
cout<<availableWindowSeats[i]<<" ";
cout << " The list of aisle seats available are: " << endl;
for(int i=0;i<=j;i++)
cout<<availableAisleSeats[i]<<" ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.