Question: C++ Programing help: Consider the below code. Identify the potential problem(s) if any in two methods: DoWork1() DoWork2() #include #include using namespace std; class Automobile

C++ Programing help: Consider the below code. Identify the potential problem(s) if any in two methods:

DoWork1()

DoWork2()

#include

#include

using namespace std;

class Automobile

{

private:

string Make;

int Year;

string Model;

public:

Automobile()

{

Make = "";

Model = "";

Year = 0;

cout << "Automobile default constructor is called." << endl;

}

Automobile(string make, string model, int year) :

Make(make),

Model(model),

Year(year)

{

cout << "Automobile constructor is called." << endl;

}

Automobile(const Automobile & src)

{

Make = src.Make;

Model = src.Model;

Year = src.Year;

cout << "Automobile copy-constructor is called." << endl;

}

public:

~Automobile()

{

cout << "Automobile destructor is called." << endl;

}

public:

const Automobile & operator=(const Automobile & src)

{

Make = src.Make;

Model = src.Model;

Year = src.Year;

cout << "Automobile assignment operator (=) is called." << endl;

return *this;

}

public:

static Automobile * CreateAutomobiles(int count)

{

return new Automobile[count];

}

static Automobile * CreateAutomobiles()

{

Automobile autoMobiles[3];

return autoMobiles;

}

};

static void DoWork1()

{

Automobile * p1 = Automobile::CreateAutomobiles(3);

Automobile * p2 = Automobile::CreateAutomobiles();

}

static void DoWork2()

{

Automobile * pAutomobiles = Automobile::CreateAutomobiles(3);

delete pAutomobiles;

}

int main()

{

DoWork1();

DoWork2();

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!