Hi, I have a small doubt in C++ assignment. I have been assigned to do seat reservation in a certain foodcourt. I have already done the seat reservation thing using basic array and function. But my program can only do manual seat reservation. Which means the user gets to choose whichever seat he wants. But my lect wants it to be automatic as in like the prog will assign the user with the seat number when he says for e.g. "Seat for 5"... So I am confused in how to start with...how should be using the array to automatically assign the seat numbers? Please help me...Thanks a ton.
My code is reflected below:
#include <iostream>
using namespace std;
int seat,num,num1;
string table[55]={"0"," 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "," 10 "," 11 "," 12 "," 13 "," 14 "," 15 "," 16 "," 17 "," 18 "," 19 "," 20 "," 21 "," 22 "," 23 "," 24 "," 25 "," 26 "," 27 "," 28 "," 29 "," 30 "," 31 "," 32 "," 33 "," 34 "," 35 "," 36 "," 37 "," 38 "," 39 "," 40 "," 41 "," 42 "," 43 "," 44 "," 45 "," 46 "," 47 "," 48 "," 49 "," 50 "," 51 "," 52 "," 53 "," 54 "};
void Selectseat(string list[],int arraysize);
void Deselectseat(string list[],int arraysize);
void DisplayFC(void);
void Selectseat(string list[],int arraysize)
{
for(int i=0;i<seat;i++)
{
cout<<"Select the seat number that you want :";
cin>>num;
if(num==2 || num==4 || num==6 || num==8 || num==10 || num==12)
{
list[num]=" O ";
}
else
{
list[num]=" O ";
}
}
}
void Deselectseat(string list[],int arraysize)
{
for(int j=0;j<seat;j++)
{
string number[55]={"0"," 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "," 10 "," 11 "," 12 "," 13 "," 14 "," 15 "," 16 "," 17 "," 18 "," 19 "," 20 "," 21 "," 22 "," 23 "," 24 "," 25 "," 26 "," 27 "," 28 "," 29 "," 30 "," 31 "," 32 "," 33 "," 34 "," 35 "," 36 "," 37 "," 38 "," 39 "," 40 "," 41 "," 42 "," 43 "," 44 "," 45 "," 46 "," 47 "," 48 "," 49 "," 50 "," 51 "," 52 "," 53 "," 54 "};
cout<<"Enter the seat number that you sit just now : ";
cin>>num;
list[num]=number[num];
}
}
void DisplayFC(void)
{
cout<<" "<<table[1]<<"|"<<table[2]<<" "<<table[5]<<"|"<<table[6]<<" "<<table[9]<<"|"<<table[10]<<endl;
cout<<" -------"<<" -------"<<" ---------"<<endl;
cout<<" "<<table[3]<<"|"<<table[4]<<" "<<table[7]<<"|"<<table[8]<<" "<<table[11]<<"|"<<table[12]<<endl;
cout<<" Table 1"<<" Table 2"<<" Table 3"<<endl;
cout<<endl;
cout<<" "<<table[13]<<"|"<<table[14]<<"|"<<table[15]<<" "<<table[19]<<"|"<<table[20]<<"|"<<table[21]<<" "<<table[25]<<"|"<<table[26]<<"|"<<table[27]<<endl;
cout<<" --------------"<<" --------------"<<" --------------"<<endl;
cout<<" "<<table[16]<<"|"<<table[17]<<"|"<<table[18]<<" "<<table[22]<<"|"<<table[23]<<"|"<<table[24]<<" "<<table[28]<<"|"<<table[29]<<"|"<<table[30]<<endl;
cout<<" Table 4"<<" Table 5"<<" Table 6"<<endl;
cout<<endl;
cout<<" "<<table[31]<<"|"<<table[32]<<"|"<<table[33]<<"|"<<table[34]<<" "<<table[39]<<"|"<<table[40]<<"|"<<table[41]<<"|"<<table[42]<<" "<<table[47]<<"|"<<table[48]<<"|"<<table[49]<<"|"<<table[50]<<endl;
cout<<" -------------------"<<" -------------------"<<" -------------------"<<endl;
cout<<" "<<table[35]<<"|"<<table[36]<<"|"<<table[37]<<"|"<<table[38]<<" "<<table[43]<<"|"<<table[44]<<"|"<<table[45]<<"|"<<table[46]<<" "<<table[51]<<"|"<<table[52]<<"|"<<table[53]<<"|"<<table[54]<<endl;
cout<<" Table 7"<<" Table 8"<<" Table 9"<<endl;
return;
}
int main()
{
do
{
system("cls");
cout<<endl;
cout<<"Welcome to FC4"<<endl;
cout<<"--------------"<<endl;
cout<<endl;
cout<<"FC4 Layout"<<endl;
cout<<endl;
cout<<"O means the seat is occupied"<<endl;
cout<<"Please wait or go to other FC if all the table shown O."<<endl;
cout<<"Bags are not allow to occupy seats"<<endl;
cout<<endl;
DisplayFC();
cout<<endl;
cout<<"Press 1 for selecting seats,Press 2 for deselecting seats : ";
cin>>num1;
cout<<endl;
if(num1==1)
{
cout<<"Number of Seats you need : ";
cin>>seat;
cout<<endl;
DisplayFC();
cout<<endl;
Selectseat(table,54);
}
else
{
cout<<"Number of people who leaving : ";
cin>>seat;
cout<<endl;
Deselectseat(table,54);
}
}while(1);
return 0;
}