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

C++ Programing help: Write code to print out the Make, Model, and Year of the “c

ID: 3859753 • Letter: C

Question

C++ Programing help: Write code to print out the Make, Model, and Year of the “crossOver1” variable.

Consider the below code. In this code, there are 4 classes (Automobile, Truck, Sedan, and CrossOverVehicle). The Automobile class is the based class of the Truck class and the Sedan class. The CrossOverVehicle inherits from both the Truck class and the Sedan class as its non-virtual base classes.

#include <iostream>
#include <string>

using namespace std;


// CLASS: Automobile
class Automobile
{
private:

string Make;
int Year;
string Model;

public:

string GetMake() { return Make; }
int GetYear() { return Year; }
string GetModel() { return Model; }

void SetMake(string value) { Make = value; }
void SetYear(int value) { Year = value; }
void SetModel(string value) { Model = value; }

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


// CLASS: Truck
class Truck : public Automobile
{
public:

Truck() :
Automobile()
{
cout << "Truck default constructor is called." << endl;
}

Truck(string make, string model, int year) :
Automobile(make, model, year)
{
cout << "Truck constructor is called." << endl;
}

Truck(const Truck & src)
{
cout << "Truck copy-constructor is called." << endl;
}

public:

~Truck()
{
cout << "Truck destructor is called." << endl;
}

public:

const Truck & operator=(const Truck & src)
{
Automobile::operator=(src);
cout << "Truck assignment operator (=) is called." << endl;
return *this;
}
};


// CLASS: Sedan
class Sedan : public Automobile
{
public:

Sedan() :
Automobile()
{
cout << "Sedan default constructor is called." << endl;
}

Sedan(string make, string model, int year) :
Automobile(make, model, year)
{
cout << "Sedan constructor is called." << endl;
}

Sedan(const Sedan & src)
{
cout << "Sedan copy-constructor is called." << endl;
}

public:

~Sedan()
{
cout << "Sedan destructor is called." << endl;
}

public:

const Sedan & operator=(const Sedan & src)
{
Automobile::operator=(src);
cout << "Sedan assignment operator (=) is called." << endl;
return *this;
}
};


// CLASS: CrossOverVehicle
class CrossOverVehicle : public Truck, public Sedan
{
public:

CrossOverVehicle() :
Truck(),
Sedan()
{
cout << "CrossOverVehicle default constructor is called." << endl;
}

CrossOverVehicle(string make, string model, int year) :
Truck(make, model + " (Truck)", year),
Sedan(make, model + " (Sedan)", year)
{
cout << "CrossOverVehicle constructor is called." << endl;
}

CrossOverVehicle(const CrossOverVehicle & src)
{
cout << "CrossOverVehicle copy-constructor is called." << endl;
}

public:

~CrossOverVehicle()
{
cout << "CrossOverVehicle destructor is called." << endl;
}

public:

const CrossOverVehicle & operator=(const CrossOverVehicle & src)
{
Truck::operator=(src);
Sedan::operator=(src);
cout << "CrossOverVehicle assignment operator (=) is called." << endl;
return *this;
}
};


int main()
{
CrossOverVehicle crossOver1("Mercedes", "X6", 2017);

// Provide code to print out the out the Make, Model, and Year of the “crossOver1” variable.

return 0;
}


Explanation / Answer

#include <iostream>
#include <string>

using namespace std;


// CLASS: Automobile
class Automobile
{
private:

string Make;
int Year;
string Model;

public:

string GetMake() { return Make; }
int GetYear() { return Year; }
string GetModel() { return Model; }

void SetMake(string value) { Make = value; }
void SetYear(int value) { Year = value; }
void SetModel(string value) { Model = value; }

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


// CLASS: Truck
class Truck : public Automobile
{
public:

Truck() :
Automobile()
{
cout << "Truck default constructor is called." << endl;
}

Truck(string make, string model, int year) :
Automobile(make, model, year)
{
cout << "Truck constructor is called." << endl;
}

Truck(const Truck & src)
{
cout << "Truck copy-constructor is called." << endl;
}

public:

~Truck()
{
cout << "Truck destructor is called." << endl;
}

public:

const Truck & operator=(const Truck & src)
{
Automobile::operator=(src);
cout << "Truck assignment operator (=) is called." << endl;
return *this;
}
};


// CLASS: Sedan
class Sedan : public Automobile
{
public:

Sedan() :
Automobile()
{
cout << "Sedan default constructor is called." << endl;
}

Sedan(string make, string model, int year) :
Automobile(make, model, year)
{
cout << "Sedan constructor is called." << endl;
}

Sedan(const Sedan & src)
{
cout << "Sedan copy-constructor is called." << endl;
}

public:

~Sedan()
{
cout << "Sedan destructor is called." << endl;
}

public:

const Sedan & operator=(const Sedan & src)
{
Automobile::operator=(src);
cout << "Sedan assignment operator (=) is called." << endl;
return *this;
}
};


// CLASS: CrossOverVehicle
class CrossOverVehicle : public Truck, public Sedan
{
public:

CrossOverVehicle() :
Truck(),
Sedan()
{
cout << "CrossOverVehicle default constructor is called." << endl;
}

CrossOverVehicle(string make, string model, int year) :
Truck(make, model + " (Truck)", year),
Sedan(make, model + " (Sedan)", year)
{
cout << "CrossOverVehicle constructor is called." << endl;
}

CrossOverVehicle(const CrossOverVehicle & src)
{
cout << "CrossOverVehicle copy-constructor is called." << endl;
}

public:

~CrossOverVehicle()
{
cout << "CrossOverVehicle destructor is called." << endl;
}

public:

const CrossOverVehicle & operator=(const CrossOverVehicle & src)
{
Truck::operator=(src);
Sedan::operator=(src);
cout << "CrossOverVehicle assignment operator (=) is called." << endl;
return *this;
}
};


int main()
{
CrossOverVehicle crossOver1("Mercedes", "X6", 2017);

// Provide code to print out the out the Make, Model, and Year of the “crossOver1” variable.

return 0;
}

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