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;
}

Recommended Answers

All 5 Replies

1) Ask user if he wants a seat, if so then
2) Check if there are seats to fill
3) If full, then give an error, else
4) get any random seat from the list of unfilled seat array

1) Ask user if he wants a seat, if so then
2) Check if there are seats to fill
3) If full, then give an error, else
4) get any random seat from the list of unfilled seat array

Hi, but i forgot to state i can't assign any random seat... Let's say the user inputs he wants 6 seats we have to try and assign him to the table that has 6 seats together or at least side by side... Btw if i wanna do your 4) statement what is command I must use?Thanks

rand() will give you random number from 0 to 0x7fff.
You can manipulate rand the give you what you want. To get random
number every time you will need to seed the random number
generator.

If you can't use random number then try something like this :
1) Get user input for how many seats
2) From 0 till seatRecivedCounter reaches seat, search the
array for empty seat.

That would be sequential.

rand() will give you random number from 0 to 0x7fff.
You can manipulate rand the give you what you want. To get random
number every time you will need to seed the random number
generator.

If you can't use random number then try something like this :
1) Get user input for how many seats
2) From 0 till seatRecivedCounter reaches seat, search the
array for empty seat.

That would be sequential.

Hi...Thanks for the constant help...But need to clarify more things...sorry...

I'm not too sure regarding ur 2) From 0 till seatRecivedCounter reaches seat, search the array for empty seat....Is it I must have a new counter to check the Input "Seat" the user type and compare it with seatRecivedCounter? After tt assign the seat number to the user...

I mean ask the user for input, and then have a counter variable
that determines how many seats the user has gotten. If none
then search from Array[0] to Array[MAX], until the counter has reached
the needed number of seats.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.