Help with a cinema program

Oct 8, 2012 at 6:35pm
Hi Guys/girls

Need help yet again. Basically i have been given an assignment where i need to create a cinema booking system. Now i dont want someone to give me the code, but i do want some help to make sure i am going in the right direction.

My program needs to have a columns, A,B,C,D,E and rows 1,2,3,4,5. Displayed with a O for an empty seat and X when one has been taken. Basically the user needs to be able to select there seats, depending on how many people and book the seats. then the O needs to be replaced with an X.

I am very new to programming so if someone could explain without going too complex.

Thanks in advance
Oct 8, 2012 at 6:44pm
Do you need help with

1) Logic or
2) Program structure or
3) User Input or
4) Output if rows and columns?
Oct 8, 2012 at 7:03pm
My game works similarly like you need http://cplusplus.shinigami.lt/2012/04/21/game-snake-v1/
Oct 8, 2012 at 7:19pm
Hi in answer to your question codewalker. That would be all of it.

Thanks
Oct 8, 2012 at 8:24pm
Since you have said you dont want the code I am assuming that you know the basics of C++, like includes, declaring variables and defining main function. (Otherwise please read a book or tutorial first)

Here is one simple logic and general flow of the program
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
//declare column header array
char columnHeader[maxCols];

//Fill in the headers
for( int col = 0; col < maxCols; col++ )
    columnHeader[col] = col + 65; //This will start at 'A' since the ascii of 'A' is 65 and continue till desired # of columns 

//declare an array of chars with size col x rows 
char plan[maxRows][maxCols];

//initialize entire array by "O' character
for( int row = 0; row < maxRows; row++ )
    for( int col = 0; col < maxCols;  col++ )
        plan[row][col] = 'O';

//in a do-while loop 

//Print the current availability 
for( int col = 0; col <maxCols; col++ )
    cout << setw(4) << columnHeader[col]; //print columns headers
cout << endl; 

//Print the plan
for( int row = 0; row < maxRows; row++ )
    for( int col = 0; col < maxCols;  col++ )
        cout << setw(4) << plan[row][col];

cout << endl;

//ask user the seat
cout << "enter your choice as column<space>row. E.g. for A1 enter A 1" << endl;

//validate if the column and row are lesser than max col and max row

//see if the seat is available 
//If yes mark as "X" else print error

//End condition of the do-while loop 


Try this logic and flow
Oct 27, 2012 at 5:45pm
Hi i have managed to create majority of this program, but i still need a little help with this code:
#include <iostream>
using namespace std;

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
int main(){
	char grid[6][6] = {
        {' ','A','B','C','D','E'},
        {'1','O','O','O','O','O'},
        {'2','O','O','O','O','O'},
        {'3','O','O','O','O','O'},
        {'4','O','O','O','O','O'},
        {'5','O','O','O','O','O'}};
	char character = 'X';
    
	int position[6] = {6,6};
    
	// Draw the grid once
	for (int i =0; i < 6; i ++){
		for (int j =0; j < 6; j++){
			if (i == position[4] && j == position[4])
				cout << character;
			else
				cout << grid[i][j];
			cout << " ";
		}
		cout << endl;
	}
    
	return 0;
}


would you be able to explain how i can get the value of the grid changed by the user. So for example changing the O in C3 to an x?

Thanks
Oct 27, 2012 at 6:44pm
changing the O in C3 to an x?
grid [3][3] = 'X';

Or maybe like this, to change D2 to an X:
1
2
3
    int row = 2;
    char col = 'D';
    grid [row][col - 'A' + 1] = character;
Nov 8, 2012 at 11:51am
Thats great, thanks you so much, can i just ask how do i get the user to put the input of the row and collum.

Thanks
Nov 15, 2012 at 2:10pm
bump
Nov 15, 2012 at 2:29pm
I'd like to offer help, but your question is vague. Can you give more details and someone may be able to respond.
Nov 15, 2012 at 2:33pm
Hi, Thanks for your respond. I have created a grid that displays a seating plan of a cinema. One of the guys who has pasted a way of changing the value inside the table but i would like the user to do it rather than have the value i wanrt to change pre built into the code

I hope that makes sense
Nov 15, 2012 at 2:58pm
That will depend on how the user is to input the information. For example the user may input the row and columns as two separate pieces of information, "A" and "1". Or they might supply it as a single string, such as "A1".

When you are clear about which is required, you could code suitable variable(s) to hold the input, and the corresponding prompt message asking the user for input, together with the cin statement. After that, we can see what the next steps will be.
Last edited on Nov 15, 2012 at 3:00pm
Nov 15, 2012 at 3:01pm
Hi

Thanks for your reponse. I would like it a two seperate reponse so rather than A1, A as one reponse and 1 as the other

Thanks
Nov 15, 2012 at 3:09pm
Do you need help with coding those input statements? If not, have a go and post the code that you come up with.

Hint: I'd use a type char for the letter, and an int for the number.
Help with getting input:
http://www.cplusplus.com/doc/tutorial/basic_io/


Then we will be able to proceed with the next steps, actually using the input to set the value in the grid.
Last edited on Nov 15, 2012 at 4:00pm
Dec 2, 2012 at 2:05pm
Hi i managed to solve the problem. but i then changed the output of the grid as it wasn't meeting the needs of the program.

Thanks for your help
Topic archived. No new replies allowed.