Okay so you have an auditorium with 3 tiers and seats on all tiers. Here is my advice.
Look at the problem from an object oriented perspective. Each tier of seats is akin to what type of data structure in programming? An array of course. So that means this:
Auditorium
..Tier 0
....Seats
..Tier 1
....Seats
..Tier 2
....Seats
Regardless of day or night this is what the auditorium is composed of. Okay so break those down into data structures.
We've already said that one tier of seats is akin to an array. I prefer to use a 1D array and access it in 2D.
So make a class that wraps an array. A vector is not needed here because you will never be adding seats. A simple array is all that is needed.
Ok, now there are several approaches to getting the day and night working. My personal preference would be to make each seat an object. Now each seat will also have a Customer state block which identified the customer using the seat. So create your base object for the entire system. We don't need a lot of special functions and stuff for seats....so we use a struct.
Code:
struct Customer
{
char Name[40];
char Address[40];
char Age[3];
char TimeOfPurchase[5];
};
struct Seat
{
//Customers for this seat
Customer DayCustomer;
Customer NightCustomer;
int Row;
int Column;
float Price;
Seat(void):Row(0),Column(0),Price(0.0f) {}
};
Okay so each seat now has day and night customers attached to it. If no one has the seat we will set Customer.Name to EMPTY. This way we know that the seat is not currently occupied.
So we have our customer object and seat object and now we need our collection of seats or array. We can now start to build the auditorium so to speak. But we need to build a class to handle a section of seats.
Code:
..
class CSeatSection
{
Seat *m_pSeatArray;
int m_iWidth;
int m_iHeight;
int m_iSize;
public:
CSeatSection(void):m_pSeatArray(NULL),m_iWidth(0),m_iHeight(0) {}
virtual ~CSeatSection(void)
{
if (SeatArray)
{
delete [] m_pSeatArray;
m_pSeatArray=NULL;
}
bool Create(int width,int height)
{
m_pSeatArray=new Seat[width*height];
if (m_pSeatArray)
{
m_iWidth=width;
m_iHeight=height;
m_iSize=width*height;
//Init seats row and column number
int row=0,col=0;
for (int offset=0;offset<m_iSize;offset++)
{
m_pSeatArray[i].Row=row;
m_pSeatArray[i].Col=col;
col++;
if (col>m_iWidth)
{
col=0;
row++;
}
}
return false;
} else return true; //error
}
bool GetSeatInfo(int row,int col,Seat *outSeat)
{
int offset=row*m_iWidth+col;
if (offset<m_iSize)
{
outSeat=&m_pSeatArray[offset];
return false;
}
outSeat=NULL;
return true; //error
}
bool SetSeatInfo(int row,int col,Seat *inSeat)
{
int offset=row*m_iWidth+col;
if (offset<m_iSize)
{
m_pSeatArray[offset]=inSeat;
return false;
}
return true; //error
}
};
Ok now we have a class that controls an entire seating section. Feel free to add functionality as you see fit.
So we have this:
CSeatSection
....SeatArray
........Seat
............Customer
Each Seat has a day and night customer.
Each CSeatSection is a collection of these seats.
When you break it into objects it gets much easier.
Ok now we are ready for the auditorium.
Code:
class CAuditorium
{
std::vector<CSeatSection *> SeatSections;
public:
virtual ~CAuditorium(void)
{
SeatSections.empty();
}
DWORD CreateSeatSection(int Width,int Height)
{
CSeatSection *temp=new CSeatSection();
temp->Create(Width,Height);
SeatSections.push_back(temp);
return SeatSections.size()-1;
}
bool GetSeatInfo(DWORD ID,int Row,int Col,CSeat *outSeat)
{
if (ID<SeatSections.size())
{
bool failed=SeatSections[ID]->GetSeatInfo(Row,Col,outSeat);
if (failed)
{
outSeat=NULL;
return true;
} else return false;
}
outSeat=NULL;
return true;
}
bool SetSeatInfo(DWORD ID,int Row,int Col,CSeat *inSeat)
{
if (ID<SeatSections.size())
{
bool failed=SeatSections[ID]->SetSeatInfo(Row,Col,inSeat);
if (failed)
{
return true;
} else return false;
}
return true;
}
};
Now you have a good beginning to a better data structure. I'm sure there are some pointer errors here and there and typos but you should be able to get it working.
Here is how to use it.
1. Create an auditorium object
2. Call CreateSeatSection with desired width and height of section.
3. Save the DWORD ID it returns for later use.
To set seat information
Call CAuditorium::SetSeatInfo() and pass the ID of the section (returned to you when you created the section), the row and column of the seat, and a Seat pointer that will contain the returned information.
To get seat information
Call CAuditorium::GetSeatInfo() and pass the ID of the section, the row and column of the seat, and a Seat pointer that points to the Seat information for the seat.
Both of these return non-zero if they fail, and zero if they succeed.
Now you need to add more functions to these to do what you want, but it's a good start.
All seat information should go through CAuditorium since it manages the entire auditorium. Add functions to CAuditorium to control each seat section - the seat section class then will control each seat it contains. Add functions to each seat so each seat can then control the customer information. Add functions to Customer so you can set the fields, get the fields, etc in the Customer object.
So the final auditorium is a vector of CSeatSections which are static arrays of Seats with Customer(s).
Now for the graphics, just call GetSeatInfo or some other function to find out whether or not it is occupied or not and if it's a day or night customer. Each seat now when you click on it could show its customer information. You are well on your way to having quite a robust scheduling, seating, and pricing program to track customer activity for any auditorium you may have.