#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string seatPlan [5][5];
string cols ;
string rows;
cout<<"A "<<"B "<<"C "<<"D "<<"E "<<endl;
for (int i=0;i<5;i++){
for (int j=0;j<5;j++){
cout<<seatPlan[i][j];
cout<<' * ';
}
cout<<endl;
}
cout<<"Please enter seat row and column you wish to reserve: \n";
cout<<endl;
for (int i=0;i<5;i++){
cin>>rows;
cin>>cols;
seatPlan[rows][cols];//--- there is problem here ??!!
}
}
here i want to make the user chose the seat as A5 or A6
but i dont know how to do it?? what datatype i should use ??!!
and how i make the seat like this ((THE NUMBER OF ROWS))
- A B C D E
1 * * * * *
2 * * * * *
3 * * * * *
4 * * * * *
5 * * * * *
int main()
{
int rows = 0;
int cols = 0;
//init all to false - NOT taken
bool seatplan[ 5 ][ 5 ] = { false };
cin >> rows;
cin >> cols;
//take one away, because if a user enters
//5, you will get an access violation.
// seatplan[ 5 ][ 5 ] - elements are 0 - 4!
seatplan[ --rows ][ --cols ] = true;
cout << "Seatplan:\n\n";
//loop rows
for( int i = 0; i < 5; ++i )
{
//loop columns
for( int j = 0; j < 5; ++j )
cout << seatplan[ i ][ j ] << ' ';
cout << endl;
}
return 0;
}
i want to change the zero(s) in the arrays to (*) how???
and how can i make the user input A3 which A is the coulmn and 3 is row ??!! what data type i should use??
int main()
{
char rows = '*';
int cols = 0;
char seatplan[ 5 ][ 5 ] = { '*' };
//init each element to *'s
//loop rows
for( int i = 0; i < 5; ++i )
{
//loop columns
for( int j = 0; j < 5; ++j )
seatplan[ i ][ j ] = '*';
}
cout << "Seatplan:\n\n";
//loop rows
for( int i = 0; i < 5; ++i )
{
//loop columns
for( int j = 0; j < 5; ++j )
cout << seatplan[ i ][ j ] << ' ';
cout << endl;
}
cout << endl << endl;
//get input
cin >> rows;
cin >> cols;
//take one away, because it a use enters
//5, you will get an access violation.
// seatplan[ 5 ][ 5 ] - elements are 0 - 4!
//typecast to an int( rows )
seatplan[ ( (int)--rows - 96 ) ][ --cols ] = 'O';
cout << "Seatplan:\n\n";
//loop rows
for( int i = 0; i < 5; ++i )
{
//loop columns
for( int j = 0; j < 5; ++j )
cout << seatplan[ i ][ j ] << ' ';
cout << endl;
}
return 0;
}
When typecasting, it will give you the decimal value of the letter.
If you look at the ascii table, the lower case letter 'a' has a decimal value of 97. That's why, on line 41, I take away 96.