Exercises 2 4 build on the code of each previous exercise.
1: | Write four classes called ElectronicDevice, Radio, Computer, and MobilePhone. Let ElectronicDevice be the base class for the other three classes and include the following three class members in its definition:
Also include two methods called SwitchOn (which must write "On" and set isOn to true) and SwitchOff (which must write "Off" and set isOn to false). The three subclasses remain empty for now. Write the appropriate code to test that even though the three subclasses have empty definitions, you can utilize their inherited class members. |
2: | Override the SwitchOn and SwitchOff methods in each of the subclasses so that they apart from the actions they perform in the ElectronicDevice also write the name of the device that is being switched on or off. For example when you call the SwitchOn method for Radio you should see the following output on the screen On Radio and isOn should still be assigned the value true. (Hint: Use the base access to achieve this functionality.) |
3: | Equip the ElectronicDevice class with two constructors:
Add the following instance variables to the program:
Add the following two constructors to each of the Radio, Computer and MobilePhone classes:
|
4: | Write a class called LaptopComputer that is derived from the Computer class. Define the instance variable maxBatteriLife of type uint for this class and provide two constructors:
|