Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; class Cars { protected: string type; public: Cars ( string _ type ) :type ( _ type ) { }

#include
#include
using namespace std;
class Cars
{
protected:
string type;
public:
Cars(string _type) :type(_type){}
void showCarInfo() const { cout << "Type:" << type << endl << endl; }
~Cars(){}
};
class ImportedCars : public Cars
{
private:
string model, country;
public:
ImportedCars(string _type, string _model, string _country) : Cars(_type), model(_model), country(_country){}
void showCarInfo() const
{
cout << "Type:" << type << endl;
cout << "Model:" << model << endl;
cout << "Country:" << country << endl << endl;
}
~ImportedCars(){};
};
class DomesticCars : public Cars
{
private:
string model;
int warranty;
public:
DomesticCars(const char *_type, string _model, int _warranty): Cars(_type), model(_model), warranty(_warranty){}
void showCarInfo() const
{ cout << "Type:" << type << endl;
cout << "Model:" << model << endl;
cout << "Warranty:" << warranty <<"years"<< endl << endl;
}
~DomesticCars(){}
};
class CarList
{
private:
Cars* carlist[50];
int carnum;
public:
CarList() : carnum(0){}
void addcar(Cars* mycar){ carlist[carnum++]= mycar; }
void ShowAllinfo() const
{
for (int i =0; i < carnum; i++) carlist[i]->showCarInfo();
}
//**Destructor for Carlist (1line)**
};
int main()
{
CarList mycars;
mycars.addcar(new Cars("Sedan"));
mycars.addcar(new ImportedCars("EV", "Tesla", "US"));
mycars.addcar(new DomesticCars("SUV", "Hyundai", 10));
mycars.ShowAllinfo();
return 0;
}
(1)Assuming the destructor for CarList is correctly implemented, what is the output of the above code?
(2)Does it print out all the information given for each car? If not, what(single) modification can you make?(write the line number of the code and give the correct modification.) What is the modified output?
(3)Give the correct implementation for the destructor for CarList in line 53. Give your implementation in a single line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions