alright guys so am havign trouble finding a way to search for seats that are toghether, my pgram consists of a theater with 20 x 10 seats, i have created a seatSelection class and the theater file which has the main.

Ok so heres a sample output of how it should look like
Premium(1) or Regular (2): 1 # of tickets: 5
Your seats are: 1A 1B 1C 1D 1E

Premium(1) or Regular (2): 2 # of tickets: 4
Your seats are: 6A 6B 6C 6D

it groups the people toghter,

what i did was set up a 2d array and filled it with 0's i dont have trouble filling the first custumers to choose premium which are row 1-5 or regular 6-20

this is my outputs so far not printing the actual output yet:
"#" of tickets: 9
Premium(0) or Regular(1): 0
you choose premium
Your seats are:
1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

again? type y for yes or n for no: y

"#" of tickets: 10
Premium(0) or Regular(1): 1
you choose regular
Your seats are:
1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

my problem is finding a wat to seat them togheter and not just doing it linearly hence that could cause some people to be separated.

What is the code that you have? You need to search through the array and find a row that has enough open seats that are together.

This is my class, dint add the header

#include "seatSelection.h"
#include <iostream>
#include <iomanip>

seatSelection::seatSelection() 
{
    for(int row=0;row < 20;row++)
    {
        for(int col=0;col <10;col++)
        {
            seats[row][col] = 0;//setting all seats to 0, 0 people in seat
        }

    }   
    theaterEmpty = true ;
}
void seatSelection::setNumPeople(int p)
{
    numPl = p;
}
void seatSelection::premiumSearch(int rows, int nRows)
{
    startRow = rows;
    numRows = nRows;
    if(theaterEmpty)
    {
        for(int col =0;col<numPl;col++)
        {
            seats[startRow-1][col] = 1;
        }
        theaterEmpty =false;
    }
    else
    {
        for(startRow-1;startRow <numRows;startRow++)
        {
             for(int col=0;col <10;col++)
             {
                 if(seats[startRow][col]==0)
                 {
                     ;
                 }
             }

         }   
    }
}
void seatSelection::regularSearch(int rows, int nRows)
{
    startRow = rows;
    numRows = nRows;
    if(theaterEmpty || seats[startRow-1][0]==0)
    {
        for(int col =0;col<numPl;col++)
        {
            seats[startRow-1][col] = 1;
        }
        theaterEmpty =false;
    }
}
void seatSelection::seatPeople()
{

}
void seatSelection::printSeats()
{
    for(int row=0;row < 20;row++)
    {
        for(int col=0;col <10;col++)
        {
            std::cout << seats[row][col]<<" ";
            if(col == 9)
            {
                std::cout<<"\n";
            }
        }
    }
}
seatSelection::~seatSelection() 
{

}Inline Code Example Here

`
This is my main

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include "seatSelection.h"
using namespace std;

/*
 * 
 */
int main(int argc, char** argv) 
{
    int type;
    int numT;
    char answer;
    seatSelection seats;
    do{
    cout <<endl;
    cout << "# of tickets: " ;
    cin >> numT;
    seats.setNumPeople(numT);

    cout <<"Premium(0) or Regular(1): ";
    cin >> type;

    if(type == 0)
    {
        cout << "you choose premium"<<endl;
        seats.premiumSearch(1,5);
    }
    else 
    {
         cout << "you choose regular"<<endl;
         seats.regularSearch(6,20);
    }

    cout <<"Your seats are: "<<endl;
    seats.printSeats();
    cout <<endl;
    cout <<"again? type y for yes or n for no: " ;
    cin >>answer;
    }while(answer == 'y');

    return 0;

}

as you can see i only handled th first people that came in the theater

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.