Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a C++ program that reads information about electronic components from the keyboard, stores that information using classes with inheritance, polymorphism and virtual functions then

Create a C++ program that reads information about electronic components from the keyboard, stores that information using classes with inheritance, polymorphism and virtual functions then prints information about the components. You must implement this project using multiple header files and source files, with the header files containing declarations and inline functions and with the source files containing the implementations of the remaining functions. You may inline member functions for trivial member functions but must NOT inline all the member functions of the classes implemented in this project.

Create a pure virtual base class to identify the functions that must be implemented by different electronic components. In this pure virtual base class, declare a virtual destructor and three pure virtual functions:

-A pure virtual function to get the value of the electronic component, returning a value of type double.

-A pure virtual function to get the units of the electronic component, returning a value of type string.

-A pure virtual function to get the printable description of the electronic component, returning a value of type string.

You must also overload the << operator so you can use cout << with variables that are a type of electronic component. In the implementation of the overloaded operator<< you should call the pure virtual function that returns the printable description of the electronic component.

Create a class, inheriting from the pure virtual electronic component class described above to hold information related to a resistor (a type of electronic component). You need to implement a destructor and the three virtual functions defined in the pure virtual electronic class described above. You need to add a constructor that takes one parameter, the value of the resistor. The value is of type double. The function that returns the printable description of the resistor should return a string consisting of the value of the resistor appended with Ohm(s).

Create classes, inheriting from the pure virtual electronic component class described above to hold information related to capacitors and batteries (types of electronic component). For each class, you need to implement a destructor and the three virtual functions defined in the pure virtual electronic class described above.

You need to add constructors for each class that takes one parameter, the value of the component. The function that returns the printable description of the capacitor should return the a string consisting of the value of the capacity appended with Farad(s) and the function that returns the printable description of the battery should return a string consisting of the value of the battery appended with Volt(s).

For the main function, create an array or vector of pointers to electronic components. Prompt the user for which type of component they want to select or if they want to terminate the program. If the user selected a type of component, dynamically create an instance of that component, add it to the array or vector, and prompt the user for the value of the component. Do this repeatedly until the user elects to terminate the program.

When the user elects to terminate the program, you should iterate through the array or vector of electronic components, calling the function on each object to get the printable description of each component and printing that to the screen.

Then, make a second pass through the array or vector of electronic components, outputting information on the component using the following code fragment:

cout << "Component " << count << " " << *components[index] << endl; 

Finally, delete all the dynamically allocated memory.

You should be diligent in validating the input provided by the user and ensure you protect against unexpected input.

Sample Input and Output

Here is some sample output, including the handling of erroneous data entered from the keyboard.

Please enter 1, 2, 3 or 4: 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 
 4 - Print component information and terminate the program xxx 
Entry not accepted. Please enter ONLY 1, 2, 3, or 4 
Please enter 1, 2, 3 or 4: 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
-1 Entry not accepted. Please enter ONLY 1, 2, 3, or 4 
Please enter 1, 2, 3 or 4: 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
1xxxxx Entry not accepted. Please enter ONLY 1, 2, 3, or 4 
Please enter 1, 2, 3 or 4: 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
1 Please enter a value for the component -98.6 Entry not accepted. Please enter ONLY a positive, floating point value 
Please enter a value for the component xxxx Entry not accepted. Please enter ONLY a positive, floating point value 
Please enter a value for the component 56.7xxxx Entry not accepted. Please enter ONLY a positive, floating point value 
Please enter a value for the component 5 Please enter 1, 2, 3 or 4: 
 1 - Enter information about a resistor 2 - Enter information about a capacitor 
3 - Enter information about a battery 
 4 - Print component information and terminate the program 2 
Please enter a value for the component 0.0001 Please enter 1, 2, 3 or 4: 
 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
3 Please enter a value for the component 9 Please enter 1, 2, 3 or 4: 
 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
1 Please enter a value for the component 6.5 Please enter 1, 2, 3 or 4: 
 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
3 Please enter a value for the component 11.1 Please enter 1, 2, 3 or 4: 
 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
2 Please enter a value for the component .000001 Please enter 1, 2, 3 or 4: 
 1 - Enter information about a resistor 2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
1 Please enter a value for the component 10000 Please enter 1, 2, 3 or 4: 
 1 - Enter information about a resistor 
2 - Enter information about a capacitor 3 - Enter information about a battery 4 - Print component information and terminate the program 
4 Component value is 5 Ohm(s) Component value is 0.0001 Farad(s) Component value is 9 Volt(s) Component value is 6.5 Ohm(s) Component value is 11.1 Volt(s) Component value is 1e-006 Farad(s) Component value is 10000 Ohm(s) 
Component 1 Resistor value (5 Ohm(s)) Component 2 Capacitor value (0.0001 Farad(s)) Component 3 Battery value (9 Volt(s)) Component 4 Resistor value (6.5 Ohm(s)) Component 5 Battery value (11.1 Volt(s)) Component 6 Capacitor value (1e-006 Farad(s)) Component 7 Resistor value (10000 Ohm(s)) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions