# Assignment 4 - Inheritance - Alt. Solution 2

itsLu
c_cpp
7 months ago
2.2 kB
3
Indexable
Never
```#include <iostream>
using namespace std;

class vehicle
{
protected:
int manufacturerID, noCylinders;
public:
vehicle()
{
manufacturerID = 0;
noCylinders = 0;
}
vehicle(int mID, int nCyl)
{
manufacturerID = mID;
noCylinders = nCyl;
}
void setmID (int mID)
{
manufacturerID = mID;
}
void setnCyl (int nCyl)
{
noCylinders = nCyl;
}
int getmID ()
{
return manufacturerID;
}
int getnCyl ()
{
return noCylinders;
}
};

class truck: public vehicle
{
public:
truck(int mID, int nCyl, double lCap, double tCap)
{
setmID(mID);
setnCyl(nCyl);
towingCapacity = tCap;
}
void setlCap(double lCap)
{
}
void settCap(double tCap)
{
towingCapacity = tCap;
}
double getlCap()
{
}
double gettCap()
{
}
};

int main()
{
vehicle vehicle1(9, 3);
cout << "Vehicle 1's Manufacturer ID: " << vehicle1.getmID() << "\tVehicle 1's Number of Cylinders: " << vehicle1.getnCyl() << endl;
vehicle1.setmID(5);
vehicle1.setnCyl(8);
cout << "Vehicle 1's Manufacturer ID: " << vehicle1.getmID() << "\tVehicle 1's Number of Cylinders: " << vehicle1.getnCyl() << endl;
truck truck1(1, 8, 9.4, 5.5);
cout << "Truck 1's Manufacturer ID: " << truck1.getmID() << "\tVehicle 1's Number of Cylinders: " << truck1.getnCyl() << endl;
cout << "Truck 1's Load Capacity: " << truck1.getlCap() << "\tTruck 1's Towing Capacity: " << truck1.gettCap() << endl;
truck1.setmID(6);
truck1.setnCyl(8);
truck1.setlCap(1.2);
truck1.settCap(7.9);
cout << "Truck 1's Manufacturer ID: " << truck1.getmID() << "\tVehicle 1's Number of Cylinders: " << truck1.getnCyl() << endl;
cout << "Truck 1's Load Capacity: " << truck1.getlCap() << "\tTruck 1's Towing Capacity: " << truck1.gettCap() << endl;
}
```