|
in Flight.h i have this prototype :
bool reserveSeat(Passenger psngr, bool smoker);
and i have to do the implementation for it , i try to do it but i got an error :
"
error message :
task b\flight.cpp(15): error C2228: left of '.setPassportNumber' must have class/struct/union
1>type is ''unknown-type''
1> b\flight.cpp(16): error C2065: 'passenger' : undeclared identifier
1>b\flight.cpp(16): error C2228: left of '.setContactNumber' must have class/struct/union
1>type is ''unknown-type''
1> b\flight.cpp(17): error C2228: left of '.smokerSeat' must have class/struct/union
and here is my try
bool Flight::reserveSeat(Passenger psngr, bool smoker)
{
Passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
passenger.setContactNumber(psngr.getContactNumber());
reservations.smokerSeat=smoker;
}
note that Flight have an object of Reservation and here's the Reservation constuctor :
Reservation.cpp
Reservation::Reservation(Passenger& psngr, bool smoke)
{
passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
passenger.setContactNumber(psngr.getContactNumber());
smokerSeat=smoke;
}
and here's the whole Flight Header
#include "reservation.h"
#include "okReservation.h"
#include "waitReservation.h"
class Flight{
private:
int waitingListMax;
int seats;
int seatsCount;
Reservation** reservations;
public:
Flight(int capacity, int waitingMax);
bool reserveSeat(Passenger psngr, bool smoker);
void cancelReservation(string resNum);
okReservation confirmReservation(waitReservation* res);
void printWaitingList();
void printReservationList();
};
|
|
|
|
|
alaaan73 wrote: Passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
as far as i can tell, you have not declared any variables named "Passenger" or "passenger".
reservations.smokerSeat=smoker;
you have declared reservations as a pointer to a pointer to a Reservation.
Reservation** reservations;
so you can't use "reservations.smokerSeat". you would have to declare it as:
Reservation reservations;
etc..
|
|
|
|
|
You have:
bool Flight::reserveSeat(Passenger psngr, bool smoker)
{
Passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
passenger.setContactNumber(psngr.getContactNumber());
reservations.smokerSeat=smoker;
}
which makes little sense. you are using both Passenger (with upper case P), and passenger (with lower case p) to refer to something. But what, why would you try to set the value of an item in an object from the value taken from that object? Similarly the statement
reservations.smokerSeat=smoker;
make little sense as reservations is a pointer to a pointer (of something). I think you are a little confused about your classes and how they connect to each other.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
You can call a class method either by using the '. ' operator on an instance of that class, e. g.
psngr.SetPassengerName("SomeName");
Or by using the '::' operator on the class, if it is a static method, e. g.:
Passenger::SetPassengerName("SomeName");
I don't think either makes sense in this case however.
Your mistakes have already been pointed out, but from the information you gave us it's hard to derive what is actually needed to fix them. Looking at the declaration of class Flight , I suspect that reservations is supposed to be a list of, well, reservations. The prototype of cancelReservation(string resNum) indicates that you are supposed to use a string representing the reservation number as a key for retrieving a specific reservation. So your reservations may in fact be organized as a sorted tree - but that is something you have to find out for yourself.
In any case, the method reserveSeat() should create a new object of type Reservation and add it to that list. Probably you should apply these method calls on that new object in order to properly initialize it. The declaration of class Reservation should shed more light on this.
|
|
|
|