The Up and the BMW fixed

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; /* * Create a Car class and if needed derived classes * * The system models cars with an engine, breaks and seats * Every care can return the number of cilinders of the engine, its type of breaks (drum/disc) and type of seats (leather/cotton) * * At least two types shall be avaible: * 1) an Up with 3 cilinders, drum breasks and cotton seats * 2) a BWM 530 with 6 cilinders, disk breaks and leather seats * */ class Engine { public: Engine(int cilinders) : m_cilinders(cilinders) {} int cilinders() const { return m_cilinders; } private: int m_cilinders; }; class Breaks { public: Breaks(std::string&& type) : m_type(type) {} std::string type() const { return m_type; } private: std::string m_type; }; class Seats { public: Seats(std::string&& type) : m_type(type) {} std::string type() const { return m_type; } private: std::string m_type; }; class Car { public: Car( Engine&& engine, Breaks&& breaks, Seats&& seats ) : m_engine(engine), m_breaks(breaks), m_seats(seats) {} int cilinders() const { return m_engine.cilinders(); } std::string breaks() const { return m_breaks.type(); } std::string seats() const { return m_seats.type(); } private: Engine m_engine; Breaks m_breaks; Seats m_seats; }; int main() { /* Create the Up instance and cout the cilinders, breaks, seats */ Car Up(std::move(Engine(3)),std::move(Breaks(std::move(std::string("drum")))),std::move(Seats(std::move(std::string("cotton"))))); std::cout<<"Up number of cilinders : "<<Up.cilinders()<<std::endl; std::cout<<"Up type of breaks : "<<Up.breaks()<<std::endl; std::cout<<"Up type of seats : "<<Up.seats()<<std::endl; /* Create the BMW instance and cout the cilinders, breaks, seats */ Car BMW(std::move(Engine(6)),std::move(Breaks(std::string("disc"))),std::move(Seats(std::string("leather")))); std::cout<<"BMW number of cilinders : "<<BMW.cilinders()<<std::endl; std::cout<<"BMW type of breaks : "<<BMW.breaks()<<std::endl; std::cout<<"BMW type of seats : "<<BMW.seats()<<std::endl; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines