#include class Product { public: Product(double price) : price { price } { } virtual double total_price() { return price * 1.4; } protected: double price; }; class Fuel : public Product { public: Fuel(double price, double efficiency) : Product { price }, efficiency { efficiency } { } double total_price() override { return price * (1.2 + 0.1 / efficiency); } private: double efficiency; }; class Food : public Product { public: using Product::Product; double total_price() override { return price * 1.1 + 20.0; } }; int main() { Product coffee { 20.0 }; Product pan { 199.0 }; Fuel electricty { 2.0, 0.8 }; Fuel petrol { 4.0, 0.5 }; Food potato { 1.5 }; Food tomato { 5.0 }; std::cout << "Total prices: " << std::endl; std::cout << "coffee: " << coffee.total_price() << std::endl; std::cout << "pan: " << pan.total_price() << std::endl; std::cout << "electricty: " << electricty.total_price() << std::endl; std::cout << "petrol: " << petrol.total_price() << std::endl; std::cout << "potato: " << potato.total_price() << std::endl; std::cout << "tomato: " << tomato.total_price() << std::endl; }