simple c++ and no std:: functions
class Vehicle {
public:
virtual void printInfo()= 0;
~Vehicle()
{
cout <<“Destructor of Vehicle is calledn”;
}
};
void main() {
Vehicle *arr[2];
arr[0] = newCar(“Nissan”,”Altima”,2017);
arr[1] = newTruck(“Volvo”,2016,50000.0,2.5);
for (int i = 0; i < 2; i++) {
arr[i]->printInfo();
}
for (int i = 0; i < 2; i++)
{
deletearr[i];
}
}
Exercise 2: You have the following class hierarchy: Vehicle Truck Car Vehicle is an abstract class and has only one pure virtual functions called printInfo) Car is a concrete class and has manufacturer ( char*), manuYear (int) and model (char*) as attributes Tuck is a concrete class and has, manufacturer (char*), manuYear (int), max_weight (float) and max_height (float) as attributes. You should write constructor and constructor with parameter for every concrete class also should implement the virtual function printInfo(). You should allocate memory for all c-strings in the constructors (assume it to be 50 characters) and deallocate the memory in the destructor You should write a destructor for cach class, in the destructor print a message with the following format: “Destructor of class [class_name] is called” Where class name is the class to which the destructor belongs. Test the Both Car and Truck classes in the main0), note that you have to call the printInfo() function using Vehicle pointer that points to objects of type Car or/and Truck Which destructor is called? How this can cause a problem? How to fix the problem (if any)? you You have to use the following code as a starting point ( you are not allowed to change it): Show transcribed image text Exercise 2: You have the following class hierarchy: Vehicle Truck Car Vehicle is an abstract class and has only one pure virtual functions called printInfo) Car is a concrete class and has manufacturer ( char*), manuYear (int) and model (char*) as attributes Tuck is a concrete class and has, manufacturer (char*), manuYear (int), max_weight (float) and max_height (float) as attributes. You should write constructor and constructor with parameter for every concrete class also should implement the virtual function printInfo(). You should allocate memory for all c-strings in the constructors (assume it to be 50 characters) and deallocate the memory in the destructor You should write a destructor for cach class, in the destructor print a message with the following format: “Destructor of class [class_name] is called” Where class name is the class to which the destructor belongs. Test the Both Car and Truck classes in the main0), note that you have to call the printInfo() function using Vehicle pointer that points to objects of type Car or/and Truck Which destructor is called? How this can cause a problem? How to fix the problem (if any)? you You have to use the following code as a starting point ( you are not allowed to change it):
Expert Answer
Answer to simple c++ and no std:: functions class Vehicle { public: virtual void printInfo()= 0; ~Vehicle() { cout printInfo(); } …