Ok, thanks for the quick reply. GCDEF asked for more code so this is class Car.
This is class parkingLot;Code://We fordward reference the parkingLot class because Class Car has yet to be defined //but our parkingLot class requires it. class parkingLot; using namespace std; class Car{ friend parkingLot; private: string plateNumber; public: Car (string argString){ this->plateNumber = argString; } string getPlateNumber(){ return plateNumber; } };
I just need class parkingLot to have the ability to call Car::getPlateNumber()Code:class parkingLot{ friend Car; private: int lot_number; // the identification number of the parking lot int capacity; // the maximum number of car it can accommodate int car_count; // the number of cars currently in the lot double hourly_rate; // the hourly rate double max_charge; // the maximum charge for each car double revenue; // the daily revenue of this rate Car ** parking_spots; // a dynamic array of pointers to Car, // representing parking spots in the lot public: parkingLot(int argNumber, int argCapacity, double hourlyRate, double maxCharge){ lot_number = argNumber; capacity = argCapacity; hourly_rate = hourlyRate; max_charge = maxCharge; revenue = 0; car_count = 0; parking_spots = new Car *[capacity]; } int enter(Car * argCar, int hour, int min){ if (car_count == capacity) return 1; //parking lot full for (int i = 0; i < capacity; ++i){ if (parking_spots[i] != NULL){ // we have to make sure its not null to compare license plates if (argCar->getPlateNumber() == parking_spots[i]->getPlateNumber()){ return 2; //2 = car already in parking lot } } } for (int i = 0; i < capacity; ++i){ if (parking_spots[i] == NULL){ parking_spots[i] = argCar; //found an empty spot, break, there's no use to keep looking break; } } argCar->park(this, hour, min); cout << argCar->toString() << " enters Lot " << lot_number << " at " << hour << ":" << min; ++car_count; return 0; // no error } };
Thanks,
Lang




Reply With Quote