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

This assignment covers classes, and strings (refer to chapters 10, 11, 12, and 1

ID: 3709922 • Letter: T

Question

This assignment covers classes, and strings (refer to chapters 10, 11, 12, and 14 in the assigned text and the related sample programs and the notes discussed in the class). Enough flexibility are provided for you to apply your knowledge of the basic C++ programing to develop a solution with enough information and documentation as needed for this assignment. Develop the program model of the problem you are developing. This is different from the flowcharting you have been doing throughout the semester. Make sure the program model reflects the problem statement. You then need to develop a C++ program to solve the problem stated by you. Define a class Automobile with appropriate data member(s) and member functions (at least constructors and a destructor for each class.) Define the class Truck derived from the class Automobile that will add data members for the manufacturer and model year and member functions (at least constructors and destructor for the class.) Define the class SUV derived from the class Automobile that will add data members for the manufacturer and the color and member functions (at least constructors and destructor for the class.) You will create an object of the class Truck and an object of the class suV using the default constructors and constructors with arguments. The default constructors initialize the two objects TI (Truck Object) and S1 (SUV Object). An overloaded constructors will obtain the appropriate data from the keyboard and create objects T2 (Truck Object) an S2 (SUV Object).

Explanation / Answer

#include <iostream>
using namespace std;

class Automobile // base class
{
private:
string manufacturer;

public:
Automobile()//default constructor
{
manufacturer = "Hyundai";
}
Automobile(string manufacturer)// argument constructor
{
this->manufacturer = manufacturer;
}
//set and get methods
void setManufacturer(string manufacturer)
{
this->manufacturer = manufacturer;
}
string getManufacturer()
{
return manufacturer;
}
};

class SUV : public Automobile   // derived class
{
private:
string color;

public:
SUV()
{
color = "black";
}
SUV(string manufacturer,string color) : Automobile(manufacturer)// passing argument to base class constructor
{
this->color = color;
}

//set and get methods
void setColor(string color)
{
this->color = color;
}
string getColor()
{
return color;
}

void printDetails()
{
cout<<" Manufacturer : "<<getManufacturer()<<" Color : "<<color;
}
};

class Truck : public Automobile
{
private:
int modelYear;

public:
Truck()
{
modelYear = 2000;
}
Truck(string manufacturer,int modelYear) : Automobile(manufacturer)// passing argument to base class constructor
{
this->modelYear = modelYear;
}
//set and get method
void setModelYear(int modelYear)
{
this->modelYear = modelYear;
}
int getModelYear()
{
return modelYear;
}
void printDetails()
{
cout<<" Manufacturer : "<<getManufacturer()<<" Model Year : "<<modelYear;
}
};

int main() {

Truck t1;
SUV s1;

string manufacturer1,manufacturer2,color;
int modelYear;

cout<<"Enter the manufacturer of the truck : ";
cin>>manufacturer1;
cout<<" Enter the model year of the truck : ";
cin>>modelYear;
Truck t2(t1);
t2.setManufacturer(manufacturer1);
t2.setModelYear(modelYear);
t2.printDetails();


cout<<" Enter the manufacturer of the SUV : ";
cin>>manufacturer2;
cout<<" Enter the color of the SUV : ";
cin>>color;
SUV s2(s1);
s2.setManufacturer(manufacturer2);
s2.setColor(color);
s2.printDetails();



return 0;
}

Output:

Enter the manufacturer of the truck :Mahindra
Enter the model year of the truck : 2015

Manufacturer : Mahindra Model Year : 2015
Enter the manufacturer of the SUV :Tata
Enter the color of the SUV : red

Manufacturer : Tata Color : red

Do ask if any doubt. Please upvote.

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