GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Nov-2009, 01:31
ImBa.ZaIzAI| ImBa.ZaIzAI| is offline
New Member
 
Join Date: Nov 2009
Posts: 3
ImBa.ZaIzAI| is on a distinguished road

How to create cinema seating using array?


How to create cinema seat using array.if the seat is avaible it will show 0 and if the sit is not avaible it will show -1.
  #2  
Old 14-Nov-2009, 07:56
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 846
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: C++ programming question.Come help...


The size of the smallest standard data type is 1 byte and called type "char".
So start with an array of arrays of type char:
CPP / C++ / C Code:
#define ROWS 15
#define COLS 20
  char seat[ROWS][COLS] = {{0}};  //initial array to zero
Then build the tools you need to manipulate that data structure.
- assign a -1 to a particular seat to indicate it is occupied
- print the value of a particular seat
- print the values of all the seats!

You should be able to come up with something like:
Code:
------------------------------------------------------------- Seating report: (by scan_seats()) seat[2][2] is occupied. seat[6][16] is occupied. seat[11][11] is occupied. seat[15][3] is occupied. ------------------------------------------------------------- ----------------------------------------------------------------- col-> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 row 1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 2: 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 3: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 4: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 5: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 6: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 row 7: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 8: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 9: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 10: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 11: 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 row 12: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 13: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 row 15: 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ----------------------------------------------------------------- Note: row and column numbers are adjusted +1 from array index values. Tickets! ...Next... Adults- $15, Children under 12- $10, Seniors $5, Senioritas- free! : How many plleaase? :
Nested for loops will be important to know:
CPP / C++ / C Code:
for(each row)
  for(each_element_item_in_the_current_row)
    do_something;
See what you can do and post back WITH your code so we can see where you are.
AND WE THANK YOU IN ADVANCE FOR USING THE C++ TAGS FOR YOUR CODE.
Last edited by Howard_L : 14-Nov-2009 at 09:13.
  #3  
Old 15-Nov-2009, 05:05
ImBa.ZaIzAI| ImBa.ZaIzAI| is offline
New Member
 
Join Date: Nov 2009
Posts: 3
ImBa.ZaIzAI| is on a distinguished road

Re: C++ programming question.Come help...


thx for helping...after i finish my dinner i go try the code ^^ if cant i will ask again
  #4  
Old 15-Nov-2009, 11:42
ImBa.ZaIzAI| ImBa.ZaIzAI| is offline
New Member
 
Join Date: Nov 2009
Posts: 3
ImBa.ZaIzAI| is on a distinguished road

Re: C++ programming question.Come help...


sry to said that. i still cant get what i want.i think i better post my question and my coding at here. my question is to ask me create a Cineme TIcketing system. the cinema name is TARC screen cinema. using two dimensional array to create the seating plan.(4 x 6). row a and b cost 20 and row c and c cost 35.for seat available show 0 while for seat sold show -1 on the sit.and it also will print the ticket.ticket format should include the following seat number,price and movie name.at last it will show total of today sales.

here is my coding.i haven finish.i just finish some.

CPP / C++ / C Code:
#include<stdio.h>
#include<stdlib.h>
#define ROW 4
#define COL 6

int displayMenu();
void whereGotGhost();
void pokerKing();
void transformer2();
void ticket();
void sit();
void looping();
void displaywGGmenu();
void displaypokerkingmenu();
void displaytransformer2menu();


int response,i;

void main()
{
	response = displayMenu();       
    while(response != 5)
	{
		looping();
	}
}
int displayMenu()                   
{	
	printf("\n"
	      "Welcome to TARC Screen Cinema.Plese select your movie:\n"  // make your selection
		  "(1) Where Got Ghost\n" // movie name
          "(2) Poker King\n"  // movie name
		  "(3) Transformer 2\n" // movie name
		  "(4) Ticket\n"
		  "(5) Exit\n"
		  "Please press a number to make your selection : ");
	fflush(stdin);
	scanf("%d",&response);

	return response;
}
void looping()
{	
	system("cls");
	if(response == 1)
	{
		whereGotGhost();
	}
	else if (response == 2) 
	{
		pokerKing();
	}
	else if (response == 3)
	{
		transformer2();
	}
	else if (response == 4)
	{
		ticket();
	}
	else
	{
		printf("You must select 1,2,3,4 or 5\n");

		displayMenu();
	}
}
void whereGotGhost()
{
	int row,col;                                        //start from here i don know how to do
	char seat[ROW][COL] = {{0}};
	printf("%d ",seat[ROW][COL]);
	printf("Please enter the sit by COL and ROW \n");
	printf("Enter the row > ");
	fflush(stdin);
	scanf("%d",&row);
	printf("Enter the col > ");
	fflush(stdin);
	scanf("%d",&col);
	
	
}
void pokerKing()
{
	printf("Haven do anything for this");
}
void transformer2()
{	
	printf("Haven do anything for this");
}
void ticket()
{
	printf("Haven do anything for this");	
}
Last edited by admin : 16-Nov-2009 at 02:36. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #5  
Old 15-Nov-2009, 23:49
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 846
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: C++ programming question.Come help...


Well I can see that you know how to call functions.
Personally I think a few too many.

But first I must ask -
This is the C++ forum; is your program supposed to be in C++?

But before that I must ask -
Why didn't you use the C++ code tags in your post???

Don't use any of they "system()" functions unless you absolutely need to. eg:
CPP / C++ / C Code:
//system("cls");    // do something else instead like 25 newlines:
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; 

See how that code is in a nice looking format?
That is because I enclosed it with the C++ tags. Use them next time.

As I said above I think you have too many functions for what you need to do.
I don't see the need for a separate function for each movie, just one function
to show "movie stuff" and supply that with different data.

So I would drop back to something like this: (using the apropriate language for the forum
CPP / C++ / C Code:
#include <iostream>

using namespace std;
#define ROW 4
#define COL 6

char M_name[3][64] = { "Where Got Ghost",
                        "Poker King",
                        "Transformer 2"
                      };

// you can chart seating for each of the three movies in this array:

char M_seats[3][ROW][COL] = {{{0}}} ;


int displayMenu();

int main(void)
{
  int row, col, response;              //start from here i don know how to do

  response = 0;
  while(response != 5)
  {
    response = displayMenu();

    //why not do all the processing in here?
    // You already have a selection, manipulate the corresponding arrays as needed for ticket purchases
    // Break out to new function for things you need to do repeatedly within one of these loop cycles.

  }
  return 0;
}

int displayMenu()
{
  int response;
  cout << "\n---------------------------------------------------------\n"
"Welcome to TARC Screen Cinema.  Please select your movie:\n\n"
"(1) " << M_name[0] << " \n"  // movie name
"(2) " << M_name[1] << " \n"  // movie name
"(3) " << M_name[2] << " \n"  // movie name
"(4) Ticket \n"
"(5) Exit \n\n"
"Please press a number to make your selection : " << flush ;
  // fflush(stdin);   // is not for use on stdin and may not work at all.
  cin >> response;    //scanf("%d", &response);

  return response;
}
I'm not sure if you said, but instead of arrays can you use structures? or classes???
That is what c++ is all about. (well not all, but a really neat feature)
Last edited by Howard_L : 16-Nov-2009 at 00:21.
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few questions for someone in the programming industry. WAEvans Miscellaneous Programming Forum 0 08-Oct-2006 09:19
Looking for opinions crystalattice Miscellaneous Programming Forum 6 27-Sep-2006 21:02
printer / font color / windows programming nicolas_qc MS Visual C++ / MFC Forum 0 03-Jan-2006 23:13
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
GUI programming crystalattice C++ Forum 5 14-Sep-2004 12:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:30.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.