kosom oop
itsLu
c_cpp
a year ago
2.1 kB
5
Indexable
#include <iostream> using namespace std; class vehicle { protected: int manufacturerID, noCylinders; public: vehicle(int mID, int nCyl) { manufacturerID = mID; noCylinders = nCyl; } void set_mID (int mID) { manufacturerID = mID; } void set_nCyl (int nCyl) { noCylinders = nCyl; } int get_mID () { return manufacturerID; } int get_nCyl () { return noCylinders; } }; class truck: public vehicle { double loadCapacity, towingCapacity; public: truck(int mID, int nCyl, double lCap, double tCap) { set_mID(mID); set_nCyl(nCyl); loadCapacity = lCap; towingCapacity = tCap; } void set_lCap(double lCap) { loadCapacity = lCap; } void set_tCap(double tCap) { towingCapacity = tCap; } double get_lCap() { return loadCapacity; } double get_tCap() { return towingCapacity; } }; int main() { vehicle vehicle1(9, 3); cout << "Vehicle 1's Manufacturer ID: " << vehicle1.get_mID() << "\tVehicle 1's Number of Cylinders: " << vehicle1.get_nCyl() << endl; vehicle1.set_mID(5); vehicle1.set_nCyl(8); cout << "Vehicle 1's Manufacturer ID: " << vehicle1.get_mID() << "\tVehicle 1's Number of Cylinders: " << vehicle1.get_nCyl() << endl; truck truck1(1, 8, 9.4, 5.5); cout << "Truck 1's Manufacturer ID: " << truck1.get_mID() << "\tVehicle 1's Number of Cylinders: " << truck1.get_nCyl() << endl; cout << "Truck 1's Load Capacity: " << truck1.get_lCap() << "\tTruck 1's Towing Capacity: " << truck1.get_tCap() << endl; truck1.set_mID(6); truck1.set_nCyl(8); truck1.set_lCap(1.2); truck1.set_tCap(7.9); cout << "Truck 1's Manufacturer ID: " << truck1.get_mID() << "\tVehicle 1's Number of Cylinders: " << truck1.get_nCyl() << endl; cout << "Truck 1's Load Capacity: " << truck1.get_lCap() << "\tTruck 1's Towing Capacity: " << truck1.get_tCap() << endl; }
Editor is loading...
Leave a Comment