write c++ program using a dynamic arrays to assign seats to pessenger
#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);
}
Comments
Leave a comment