Write a printAll function that takes in a vector containing Cars and Trucks, and calls the print() function on every Car and Truck in the vector. printAll() should call Car::print() on every Car and Truck::print() on every Truck in the vector. You may assume that print() has been declared as a virtual function.
C++ programming plz help
Ans
code:-
void printAll(vector<Car> &Cars, vector<Truck> &Trucks){
for(int i=0;i<Cars.size();i++){
(Cars[i]).print();//for each Car
}//for each truck
for(int i=0;i<Trucks.size();i++){
(Trucks[i]).print();
}
}
.
.
If any doubt ask in the comments.
Please appreciate the work by giving a thumbs up.
Get Answers For Free
Most questions answered within 1 hours.