Assuming that the two classes, a ParkingLot and a Vehicle, have already been def
ID: 3830149 • Letter: A
Question
Assuming that the two classes, a ParkingLot and a Vehicle, have already been defined, write code to implement a friend overload output operator for the ParkingLot class, which will output the Parking Lot "name", followed by the list of cars parked.
-A ParkingLot holds a handle to a dynamic rectangle matrix of Vehicles called "vehicles."
-The attrivutes "rows" and "columns" hold the size of the rectangle lot, in terms of spots for vehicles.
-Assume that the parking lot is full.
-Assume that the output operator for the vehicle has been provided, and that it outputs a car model, followed by its color, and needed for the report.
Explanation / Answer
friend ostream &operator<< (ostream & output, const ParkingLot &p)
{
int i,j;
output<<“Parking Lot’s Name: ”<<name;
output<<“List of parked cars: ”;
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
output<<vehicles[i][j];
}
}
}