// BT03.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include using namespace std; class Vehicle { protected: float m_lit; //int m_distance; int m_goods; public: Vehicle(); void addAWeightOfGoods(float kg); void removeAWeightOfGoods(float kg); void addAmountOfFuel(float fuels); float leftFuel(); }; void Vehicle::addAmountOfFuel(float fuels) { this->m_lit += fuels; } void Vehicle::removeAWeightOfGoods(float kg) { if (this->m_goods >= kg) { this->m_goods -= kg; } } void Vehicle::addAWeightOfGoods(float kg) { this->m_goods += kg; } Vehicle::Vehicle() { this->m_lit = 0; this->m_goods = 0; } float Vehicle::leftFuel() { return this->m_lit; } class Motorbike :public Vehicle { public: double runLengthOfKM(); }; double Motorbike::runLengthOfKM() { double distance = 0; do { distance += 100; this->m_lit -= 2; if (this->m_lit < 2) { return distance; } if (this->m_goods / 10 != 0) { this->m_lit -= 0.1; } } while (this->m_lit > 0); return distance; } class Truck :public Vehicle { public: double runLengthOfKM(); }; double Truck::runLengthOfKM() { double distance = 0; do { distance += 100; this->m_lit -= 20; if (this->m_lit < 20) { return distance; } if (this->m_goods / 1000 != 0) { this->m_lit -= 1; } } while (this->m_lit > 0); return distance; } int main() { Truck a; a.addAmountOfFuel(100); a.addAWeightOfGoods(100000); cout << a.runLengthOfKM() << endl; cout << a.leftFuel(); }