I don't know how I should go on to create two subclasses "TV" and "Fridge". Edevice is the superclass.
Each Edevice has a state "On" or "Off" and can be switched on or off.
(Here is a big problem the handling of the strings and to get it matched with the conceptual design of the remainder of the code)
An Edevice has a power input depending on specific characteristics (length, screen diagonal, cooling capacity).
Which procedures would you recommend to implement thePowerinput virtual? It yields as result the current power consumption of the Edevice but is implemented in the subclasses.
It's really hard for me to go on. My rudimentary knowledge comes to an end.
Inheritance in it's core is pretty simple.
The syntax for inheriting a super class is as follows
class derived_class_name: public base_class_name
Once that happens, your derived classes have access to all public and protected members/functions of the super class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Example {
private:
int hidden; //Cannot be changed except by itself
protected: //Hidden to all but the subclasses and itself
intprotected;
private:
void setHidden(int x); //Any object and subclass can use this
}
class Derived : public Example {
}