Question regarding Arrays in classes

Could someone please tell me how to solve this because i was not able to get the idea of using arrays in classes
Here is the Question :

The PVR Cinemas manager approaches you to develop a system for ticket booking. It has 5 screens each with a capacity of 500 seats of which 100 are platinum, 100 are diamond and 300 are gold. The cost of platinum, diamond and gold tickets are Rs.150, Rs.125, and Rs.100 respectively.
• Construct a class to model a screen with an array of integers for each category of seats. Provide a constructor to initialize the array to 0.
• Include a member function bookSeat() that gets the category of the seat and number of tickets to be booked and then prints the seat numbers. The booked seats are marked by 1. If no seats are available then your program should display appropriate message.
Test the above class with a main program that creates an array of objects (size of array depends on the number of screens) and display the total amount to be paid by the visitor.


Thanks in Advance
What kind of class are you taking? I've never seen classes taught before std::vector
Can you elaborate it? Or simply, could you solve the above problem, please?
Last edited on
It looks like you only need fixed-size arrays as class members, which simplifies things for you. I'm not going to summarize the whole problem, and nobody is going to do your work for you, but I will help you understand it.

What's the first part of the problem you're struggling with?
Sorry for the late replay,

here is what i've made, But the the problem comes with the arrays initializing.
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
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class cinema
{
      private:
              int n1,n2,a[100],b[100],i,pt,dd;
      
      public:
             void platinum()
             {
                  cout<<"\nPlease Enter the Number of Tickets ";
                  cin>>n1;
                  for(i=pt;i>=pt+n1;i++)
                  a[i]=1;// The arrays seems not to be intilizing with the value
                  pt+=n1; //Here, some garbage value is printing
                  cout<<"\nTickets left "<<100-pt;
                  }
             void diamond()
             {    
                  cout<<"\nPlease Enter the Number of Tickets ";
                  cin>>n2;
                  for(i=dd;i>=dd+n2;i++)
                  b[i]=1;
                  //cout<<b[gd]<<endl;
                  dd+=n2;
                  cout<<"\nTickets left "<<100-dd;
                  
                  }};
int main()
{
    int n;
    cinema a;
    while(1)
    {
            cout<<"\nPlease enter your choice, for platinum 1; for diamond 2; ";
            cin>>n;
            switch(n)
            {
                     case 1:
                          {a.platinum();
                          break;}
                     case 2:
                         { a.diamond();
                          break;
                          }}
                          }
                          getch();
                          }
    


You never initialize pt and dd. When you call platinum() and diamond() i is holds some random number which is surely outside the bounds of the array.
But, when I run diamond() it prints perfectly except for that array. please spot my error
Last edited on
Topic archived. No new replies allowed.