я создал структуру, которая имеет одно из своих полей, двухмерный массив для хранения забронированных мест ... в основном разделе я создал массив структур для хранения всей информации. Когда я вхожу в строку иномер столбца, программа должна проверить, было ли это место уже забронировано .. у меня проблема в том, что моя программа не проверяет должным образом для этого случая .. я пытался проверить весь массив, но я не знаю, как правильно сделатьэто ... пожалуйста, помогите мне, так как я все еще новичок ..
Я попытался проверить весь массив, как вы увидите в моем коде ... я прокомментировал эту часть, потому что я также пытался проверять толькотолько один экземпляр массива структур
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
struct Simulate
{
string seats[3][3] = {};
string name = "";
int age = 0;
int rowNum, colNum;
};
``````````````````````````````````````````
void getinput(Simulate &book)
{
cout<<"Enter your name: "<<endl;
cin>>book.name;
cout<<"Enter your age: "<<endl;
cin>>book.age;
cout<<"enter row number: "<<endl;
cin>>book.rowNum;
cout<<"enter column number: "<<endl;
cin>>book.colNum;
}
void setSeats(Simulate &book)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
book.seats[i][j] = "o";
}
}
}
void bookMap(Simulate &book)
{
for (int i = 0; i < 3; i++)
{
//cout<<i<<endl;
cout<<endl<<"\t";
for (int j = 0; j < 3; j++)
{
cout<<book.seats[i][j]<<" ";
}
cout<<endl;
}
}
void bookMapUpdated(Simulate &book)
{
for (int i = 0; i < 3; i++)
{
cout<<endl<<"\t";
for (int j = 0; j < 3; j++)
{
cout<<book.seats[i][j]<<" ";
}
cout<<endl;
}
}
/*
bool checkBooking(Simulate book[])
{
//assuming only 2 structs created
for (int i = 0; i < 2; i++) {
{
if (book[i].seats[book[i].rowNum][book[i].colNum] == "o")
{
return true;
}
else
{
return false;
}
}
*/
bool checkBooking(Simulate book)
{
if (book.seats[book.rowNum][book.colNum] == "o")
{
return true;
}
else
{
return false;
}
}
````````````````````````````````````````````````
int main()
{
Simulate bookings[2];
int i = 0;
char answer;
getinput(bookings[i]);
setSeats(bookings[i]);
bookMap(bookings[i]);
if (checkBooking(bookings[i]) == true )
{
bookings[i].seats[bookings[i].rowNum][bookings[i].colNum] = "x";
}
else
{
cout<<"seat booked please choose another seat"<<endl;
cin>>bookings[i].rowNum>>bookings[i].colNum;
}
cout<<"do you want to make another booking y/n"<<endl;
cin>>answer;
while (answer == 'y' || answer =='Y')
{
i++;
getinput(bookings[i]);
bookMapUpdated(bookings[i]);
if (checkBooking(bookings[i]) == true )
{
bookings[i].seats[bookings[i].rowNum][bookings[i].colNum] = "x";
}
else
{
cout<<"seat booked please choose another seat"<<endl;
cin>>bookings[i].rowNum;
cin>>bookings[i].colNum;
}
cout<<"do you want to make another booking y/n"<<endl;
cin>>answer;
}
system("pause");
getch();
return 0;
}