If I have a program like this
#include <iostream>
#include <string>
using namespace std;
class Vehicle {
protected:
int Number;
int Year;
string Make;
string BodyStyle;
string Model;
string Color;
int Cost;
public:
Vehicle() {}
Vehicle(int num, int year1, string make1, int bStyle1,
int model1, int color1, int cost1)
{
Number = num;
Year = year1;
Make = make1;
BodyStyle = bStyle1;
Model = model1;
Color = color1;
Cost = cost1;
}
void display() {
cout << "---This is Vehicle Class.---" << endl;
cout << "Number: " << Number << endl;
cout << "Year: " << Year << endl;
cout << "Make: " << Make << endl;
cout << "BodyStyle: " << BodyStyle << endl;
cout << "Model: " << Model << endl;
cout << "Color: " << Color << endl;
cout << "Cost: " << Cost << endl;
}
};
Vehicle
class is implemented by three classes
- Truck Vehicle
- Motorcycle Vehicle
- Trailer Vehicle.
First class that implements Vehicle
class.
class TruckVehicle : Vehicle {
protected:
int Passengers;
int Mileage;
int GrossWeight;
string PoweredBy;
int TempGross;
public:
TruckVehicle(int number, int year, string make, string model,
string bStyle, string color, int cost,
int passengers, int mileage, int gWeight,
string pBy, int tGross)
{
Number = number;
Year = year;
Make = make;
BodyStyle = bStyle;
Model = model;
Color = color;
Cost = cost;
Passengers = passengers;
Mileage = mileage;
GrossWeight = gWeight;
PoweredBy = pBy;
TempGross = tGross;
}
void display() {
cout << "---This is TruckVehicle class.---" << endl;
cout << "Number: " << Number << endl;
cout << "Year: " << Year << endl;
cout << "Make: " << Make << endl;
cout << "BodyStyle: " << BodyStyle << endl;
cout << "Model: " << Model << endl;
cout << "Color: " << Color << endl;
cout << "Cost: " << Cost << endl;
cout << "Passenger: " << Passengers << endl;
cout << "Mileage: " << Mileage << endl;
cout << "GrossWeight: " << GrossWeight << endl;
cout << "PoweredBy: " << PoweredBy << endl;
cout << "TempGross: " << TempGross << endl;
}
};
Second class that implements Vehicle
class.
class MotorcycleVehicle : Vehicle {
protected:
int Passengers;
int Mileage;
public:
MotorcycleVehicle(int number, int year, string make, string model,
string bStyle, string color, int cost,
int passenger, int mileage)
{
Number = number;
Year = year;
Make = make;
BodyStyle = bStyle;
Model = model;
Color = color;
Cost = cost;
Passengers = passenger;
Mileage = mileage;
}
void display() {
cout << "---This is Motor Cycle Class.---" << endl;
cout << "Number: " << Number << endl;
cout << "Year: " << Year << endl;
cout << "Make: " << Make << endl;
cout << "BodyStyle: " << BodyStyle << endl;
cout << "Model: " << Model << endl;
cout << "Color: " << Color << endl;
cout << "Cost: " << Cost << endl;
}
};
Third Class that implements Vehicle
class.
class TrailerVehicle : protected Vehicle {
protected:
int GrossWeight;
public:
TrailerVehicle() {
GrossWeight = 0;
}
TrailerVehicle(int number, int year, string make, string model,
string bStyle, string color, int cost, int gWeight)
{
Number = number;
Year = year;
Make = make;
BodyStyle = bStyle;
Model = model;
Color = color;
Cost = cost;
GrossWeight = gWeight;
}
void display() {
cout << "---This is Trailer Vehicle Class.---" << endl;
cout << "Number: " << Number << endl;
cout << "Year: " << Year << endl;
cout << "Make: " << Make << endl;
cout << "BodyStyle: " << BodyStyle << endl;
cout << "Model: " << Model << endl;
cout << "Color: " << Color << endl;
cout << "Cost: " << Cost << endl;
cout << "GrossWeight: " << GrossWeight << endl;
}
};
Trailer Vehicle class is implemented by TravelTrailerVehicle
.
class TravelTrailerVehicle : TrailerVehicle {
protected:
int Passengers;
int Mileage;
string PoweredBy;
int BodyNumber;
int Length;
public:
TravelTrailerVehicle(int number,int year,string make, string model,
string bStyle,string color,int cost,
int gWeight,int passengers,int mileage)
{
GrossWeight = gWeight;
Passengers= passengers;
Mileage= mileage;
Year = year;
Make = make;
Model = model;
BodyStyle = bStyle;
Color = color;
Number = number;
Cost = cost;
}
void display() {
cout << "----This is Travel Trailer Class.----" << endl;
cout << "Number: " << Number << endl;
cout << "Year: " << Year << endl;
cout << "Make: " << Make << endl;
cout << "Model:" << Model << endl;
cout << "BodyStyle: " << BodyStyle << endl;
cout << "Color: " << Color << endl;
cout << "Cost:" << Cost << endl;
cout << "GrossWeigth: " << GrossWeight << endl;
cout << "Passengers: " << Passengers << endl;
cout << "Mileage: " << Mileage << endl;
}
};
Main Method.
int main() {
TruckVehicle Truck1(111111, 2014,"Toyota", "Tacoma","4x4","Black",25000, 2, 15000, 333333,"Gas", 222222);
MotorcycleVehicle Motorcycle1(2222222,2015,"Honda", "Gold Wing","Coupe","Red",5000, 1, 3250);
TravelTrailerVehicle Trailer1(123456789, 2015, "Toyota", "Camry","Coupe","Red", 20000, 666666, 5, 9855);
Truck1.display();
Motorcycle1.display();
Trailer1.display();
system("pause");
return 0;
}
can someone give me a hint of what is meant by "Use default function parameters and member list to minimize the the code needed for all the constructors".