+ 6
How can I link a class object to another class objects ?
I am trying to make a booking counter for my Airline Reservation Program... Now I have a seat class to store the seats and mark them as booked/unbooked. I also have a passenger class to store passenger's data, which also has departure dates (object of struct date) and route( object of struct location to mark a location) Now , I wished to generate the seats and maintain the booking record seperately for each location and date, but I am unable to create such an object. How can I achieve my desired result?
27 Antworten
+ 6
from what I have learned in my short time in CPP Vectors are like arrays and how they store data but they're more dynamic you can keep adding data to them and they will attempt to grab the nearest memory address to add to the vector. in my example I have made a vector of objects of the base object all other objects will use.
+ 5
https://code.sololearn.com/cxNQLowD7JRz/?ref=app
this is one I'm currently working with
+ 5
from my understanding of his question he is setting up an airline which will have different booking at each Airport the plane arrives at so the plane has one set of seats but many bookings. my understanding is he is looking for a way to track this.
+ 5
@Luyanda
Sorry for the brief explanation, I only had 512 chars to explain...
I have a seat class to hold the number of seats in a plane for the passenger to book/unbook.
Now, this seat matrix depends on:
what route the person is using ,
- Eg - New York to Toronto will have a seperate seat matrix (bookings shall not be copied) than Toronto to New York
what date the person is travelling on,
- Eg - If Flight's seat 1A is booked on 30 05 2017, it must be shown unbooked on the date 31 05 2017
whether the flight is Domestic or International,
- The domestic plane is smaller than the international plane
the cabin of the passenger.
- First Class has lesser seats than Business which has far lesser seats than Economy
Now, I wished to create seperate instances for the seat class in accordance with all these factors and at the same time save them so that I can access them for cancellation or seat change charges...
I can only think of one solution, save the seat matrix in a file to maintain the records, but that makes the program slow...
Is there another simpler way?
+ 4
you could use something like a vector in the seats object to store the booking objects associated with it
+ 4
https://code.sololearn.com/cv0RV50x7kQy/?ref=app
This one is a good demonstration of vectors
+ 4
And yes, the seats are not airport dependent, just on the factors listed above...
+ 4
@Kinshuk I can't think of a simple way either.
+ 4
@Luyanda
So files seem to be the only way, with the name of the file containing the date as well as the route...
+ 4
@ Kinshuk yes files seem to be the solution in the c++ case
+ 4
@kinshuk
in you program : does every passenger have his or her own file file right?
+ 4
I guess you have could use the destructor to save the data to the file when the passenger leaves the airport.
+ 4
do you record the passenger names?
+ 4
@kinshuk good luck on your program
+ 3
Could you use pointers to do that?
I think using them can link objects,but, not the classes.
Also the : scope for deriving classes may help.
+ 3
Dude I can't visualise what you saying.
please explain maybe I will help.
+ 3
@Minual I mean the program the guy wants to write
+ 3
@ Everyone.
The guy wants to link the seats with the passengers along with the details?
+ 3
He has different airport?
One plain constant number of seats?
passengers change at the airports?
he wants to track the passenger and sit during and after the flight?
+ 3
@Michael Thank you,
For sharing the codes and explaining vectors.
I plan to try coding one in the future.