Question: C++ Write a program that creates a set of electronic components from a common base class. In the main function create an instance of the

C++

Write a program that creates a set of electronic components from a common base class. In the main function create an instance of the classes Wire, Component, Battery, Switch. Light, Resistor, and Capacitor classes. Assign each instance some non-default value. Using each of the overloaded << operator functions print out each instance Sample Program I/O:

Wire Instance: length = 2

Component Instance : type = something

Battery Instance: type = battery, voltage = 9V, current = 2.5A

Switch Instance: type = switch, state = closed

Light Instance: type = light, state = on

Resistor Instance: type = resistor, resistance = 210K Ohms

Capacitor Instance: type = capacitor, capacitance = 240 Farads

1. Make sure you have one header file and one *.cpp file for each class created for this lab. Place the class definitions in the corresponding header file and class member function definitions in the corresponding *.cpp file. (In total you should have eight (8) header files and nine (9) cpp file including main.cpp.)

2. As needed update the Cirucut Element, Wire and Component classes to include the following attributes:

- Accessors and mutators for the new member items.

- Two (2) constructors: a default constructor to initialize the class value to 0 a constructor with two (2) parameters specify the initial value

3. Create a Battery class that inherits from the Component class with the following attributes:

- A voltage member item.

- A current member item.

- Accessors and mutators for the the new member items.

- Two (2) constructor: a default constructor to initialize the class value to 0 a constructor with two (2) parameters specify the initial values

4. Create a Switch class that inherits from the Component class with the following attributes:

- A state member item, i.e. open/closed or on/off

- An accessor and mutator for the state.

- Two (2) constructor: a default constructor to initialize the class value to 0 a constructor with one (1) parameters specify the initial values

5. Create a Light class that inherits from the Component class with the following attributes:

- A state member item, i.e. on/off

- An accessor and mutator for the state.

- Two (2) constructor: a default constructor to initialize the class value to 0 a constructor with one (1) parameters specify the initial values

6. Create a Resistor class that inherits from the Component class with the following attributes:

- A resistance member item

- An accessor and mutator for the resistance.

- Two (2) constructor: a default constructor to initialize the class value to 0 a constructor with one (1) parameters specify the initial values

7. Create a Capacitor class that inherits from the Component class with the following attributes:

- An capacitance member item.

- An accessor and mutator for the capacitance.

- Two (2) constructor: a default constructor to initialize the class value to 0 a constructor with one (1) parameters specify the initial values

8. Overload the << operator for every class you have created.

9. In the main function create an instance of each class of the Wire, Component, Battery, Switch. Light, Resistor, and Capacitor classes. Assign each instance some non-default value. Using each of the overloaded << operator functions print out each instance.

C++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!