Answer to Question #318621 in C++ for hamzii

Question #318621

write c++ program using a dynamic arrays to assign seats to pessenger


1
Expert's answer
2022-03-26T12:41:06-0400
#include <iostream>
#include <vector>

using namespace std;

void Display(vector< vector<char> >SeatScheme,int rows, int cols)
{
	cout << "We have this scheme of sits: " << endl;
	cout << "  ";
	for (int j = 0; j < cols; j++)
	{
		cout << j + 1 << " ";
	}
	cout << endl;
	for (int i = 0; i < rows; i++)
	{
		cout << i + 1 << " ";
		for (int j = 0; j < cols; j++)
		{
			cout << SeatScheme[i][j] << " ";
		}
		cout << endl;
	}
}

int main()
{
	int rows, cols;
	int seatRow, seatCol;
	cout << "Please, enter a number of rows: ";
	cin >> rows;
	cout << "Please, enter a number of cols: ";
	cin >> cols;
	vector< vector<char> >SeatScheme(rows,vector<char>(cols,'X'));
	Display(SeatScheme, rows, cols);
	do
	{
		cout << "Please, enter a row of seat( 0 - exit program) :";
		cin >> seatRow;
		if (seatRow == 0)break;
		cout << "Please, enter a col of seat:";
		cin >> seatCol;
		SeatScheme[seatRow - 1][seatCol - 1] = 'O';
		Display(SeatScheme, rows, cols);
	} while (true);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS