+ 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?

24th May 2017, 5:30 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
27 Respuestas
+ 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.
24th May 2017, 6:30 PM
Michael Simnitt
Michael Simnitt - avatar
+ 5
https://code.sololearn.com/cxNQLowD7JRz/?ref=app this is one I'm currently working with
24th May 2017, 6:24 PM
Michael Simnitt
Michael Simnitt - avatar
+ 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.
24th May 2017, 6:39 PM
Michael Simnitt
Michael Simnitt - avatar
+ 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?
25th May 2017, 4:40 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
you could use something like a vector in the seats object to store the booking objects associated with it
24th May 2017, 5:49 PM
Michael Simnitt
Michael Simnitt - avatar
+ 4
https://code.sololearn.com/cv0RV50x7kQy/?ref=app This one is a good demonstration of vectors
24th May 2017, 7:47 PM
Michael Simnitt
Michael Simnitt - avatar
+ 4
And yes, the seats are not airport dependent, just on the factors listed above...
25th May 2017, 4:41 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
@Kinshuk I can't think of a simple way either.
25th May 2017, 4:52 AM
Luyanda
Luyanda - avatar
+ 4
@Luyanda So files seem to be the only way, with the name of the file containing the date as well as the route...
25th May 2017, 4:59 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
@ Kinshuk yes files seem to be the solution in the c++ case
25th May 2017, 5:15 AM
Luyanda
Luyanda - avatar
+ 4
@kinshuk in you program : does every passenger have his or her own file file right?
25th May 2017, 5:28 AM
Luyanda
Luyanda - avatar
+ 4
I guess you have could use the destructor to save the data to the file when the passenger leaves the airport.
25th May 2017, 1:47 PM
Luyanda
Luyanda - avatar
+ 4
do you record the passenger names?
25th May 2017, 4:28 PM
Luyanda
Luyanda - avatar
+ 4
@kinshuk good luck on your program
26th May 2017, 3:50 AM
Luyanda
Luyanda - avatar
+ 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.
24th May 2017, 5:44 PM
Manual
Manual - avatar
+ 3
Dude I can't visualise what you saying. please explain maybe I will help.
24th May 2017, 5:59 PM
Luyanda
Luyanda - avatar
+ 3
@Minual I mean the program the guy wants to write
24th May 2017, 6:22 PM
Luyanda
Luyanda - avatar
+ 3
@ Everyone. The guy wants to link the seats with the passengers along with the details?
24th May 2017, 6:38 PM
Luyanda
Luyanda - avatar
+ 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?
24th May 2017, 6:53 PM
Luyanda
Luyanda - avatar
+ 3
@Michael Thank you, For sharing the codes and explaining vectors. I plan to try coding one in the future.
24th May 2017, 8:01 PM
Manual
Manual - avatar