CJCoding With Joseph
15free / daySign inCreate account

Interface With Two Pure Virtual Methods

An interface is an abstract class made only of pure virtual methods. A concrete subclass must implement EVERY one of them.

Create an abstract class Device with TWO pure virtual methods:
- string name() const (returns the device name)
- int power() const (returns watts)

Then create a concrete class Laptop that implements name() returning "Laptop" and power() returning 65.

Device cannot be instantiated; the runner uses a Device* to a Laptop and prints the output shown in Expected Output.

Do NOT write a main function.

Expected Output:

Laptop 65

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.