### 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.

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.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````#include #include #include 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<>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.