Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programing help: Q20: Define the function pointers that can be used to assig

ID: 3859755 • Letter: C

Question

C++ Programing help: Q20: Define the function pointers that can be used to assign the two overloading static methods of the Automobile class below to the function pointer variables.

#include <iostream>
#include <string>

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;
}
};

Explanation / Answer

functional pointer for

static Automobile * CreateAutomobiles(int count)
{
return new Automobile[count];
}

is

(Automobile *)(*fun)(int);

functional pointer for

static Automobile * CreateAutomobiles()
{
Automobile autoMobiles[3];
return autoMobiles;
}

is

(Automobile *)(*fun)(void);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote