Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

READ THIS ASSIGNMENT CAREFULLY. THERE ARE A LOT OF DETAILED REQUIREMENTS. Create

ID: 3729559 • Letter: R

Question

READ THIS ASSIGNMENT CAREFULLY. THERE ARE A LOT OF DETAILED REQUIREMENTS. 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 Page 2 of 6 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. The first line of the source code should be a comment including the following information:

Ensure your program is well documented, well structured, and uses meaningful variable names. Use multiple functions as necessary for good structure and readability. 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 Page 3 of 6 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 Page 4 of 6 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 Page 5 of 6 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))

Explanation / Answer

Hi Sorry I am unable to upload the zip or files.

Please create a Win32 console project in visual studio and add following files.

// File 1: main function file

#include "EComponent.h"

#include "Resistor.h"

#include "Capacitor.h"

#include "Battery.h"

void main()

{

std::vector<EComponent*> componentList;

int componentChoice = 0;

do

{

cout<<"Please enter 1, 2, 3 or 4:" << endl << "1 - Enter information about a resistor" << endl << "2 - Enter information about a capacitor" << endl

<< "3 - Enter information about a battery" << endl << "4 - Print component information and terminate the program " << endl;

cin >> componentChoice;

if(componentChoice == 4)

{

// print all object's printdescription function

for(int index = 0; index < componentList.size(); index++)

{

componentList[index]->GetPrintDescriptionOfEComponent();

}

// iterate through vector and print like below

for(int index = 0; index < componentList.size(); index++)

{

int count = index + 1;

cout << "Component " << count << " " << componentList[index] << endl;

}

break;

}

else if( componentChoice >= 1 && componentChoice <= 3)

{

double componentValue;

do{

cout<< "Please enter a value for the component" << endl;

cin >> componentValue;

if(componentValue > 0)

{

if(componentChoice == 1)

{

Resistor *obj = new Resistor(componentValue);

componentList.push_back(obj);

}

else if(componentChoice == 2)

{

Capacitor *obj = new Capacitor(componentValue);

componentList.push_back(obj);

}

else if(componentChoice == 3)

{

Battery *obj = new Battery(componentValue);

componentList.push_back(obj);

}

}

else

{

cout << "Entry not accepted. Please enter ONLY a positive, floating point value " << endl ;

}

}while(componentValue < 0);

}

else

{

cout<< "Entry not accepted" << endl;

}

}while(componentChoice != 4);

}

// File 2 : Component class header file named EComponent.h

#pragma once

#include "stdafx.h"

#include <vector>

using namespace std;

class EComponent

{

public:

double mValue;

public:

EComponent(void);

virtual ~EComponent(void);

virtual double GetValueOfEComponent() = 0;

virtual string GetUnitsOfEComponent() = 0;

virtual string GetPrintDescriptionOfEComponent() = 0;

friend ostream & operator<<(ostream& output, EComponent* component);

};

// file 3 : component class code file EComponent.cpp

#include "StdAfx.h"

#include "EComponent.h"

EComponent::EComponent(void)

{

}

EComponent::~EComponent(void)

{

}

ostream & operator<<(ostream& output, EComponent* component)

{

output << component->GetPrintDescriptionOfEComponent() ;

return output;

}

// file 4 : register class header file named Resistor.h

#pragma once

#include "ecomponent.h"

class Resistor :

public EComponent

{

public:

Resistor(void);

Resistor(double value);

virtual ~Resistor(void);

double GetValueOfEComponent();

string GetUnitsOfEComponent();

string GetPrintDescriptionOfEComponent();

};

// file 5 : register class code file named Resistor.cpp

#include "StdAfx.h"

#include "Resistor.h"

Resistor::Resistor(void)

{

}

Resistor::~Resistor(void)

{

}

Resistor::Resistor(double value)

{

this->mValue = value;

}

double Resistor::GetValueOfEComponent()

{

return mValue;

}

string Resistor::GetUnitsOfEComponent()

{

string value;

std::ostringstream strStream;

strStream << GetValueOfEComponent();

value = strStream.str();

return value;

}

string Resistor::GetPrintDescriptionOfEComponent()

{

string msg;

msg.empty(); msg.append(GetUnitsOfEComponent()); msg.append(" "); msg.append("Ohm(s)");

return msg;

}

// file 6 : Capacitor class header file named Capacitor.h

#pragma once

#include "ecomponent.h"

class Capacitor :

public EComponent

{

public:

Capacitor(void);

virtual ~Capacitor(void);

Capacitor(double value);;

double GetValueOfEComponent();

string GetUnitsOfEComponent();

string GetPrintDescriptionOfEComponent();

};

// file 7 : Capacitor class code file named Capacitor.cpp

#include "StdAfx.h"

#include "Capacitor.h"

Capacitor::Capacitor(void)

{

}

Capacitor::~Capacitor(void)

{

}

Capacitor::Capacitor(double value)

{

this->mValue = value;

}

double Capacitor::GetValueOfEComponent()

{

return mValue;

}

string Capacitor::GetUnitsOfEComponent()

{

string value;

std::ostringstream strStream;

strStream << GetValueOfEComponent();

value = strStream.str();

return value;

}

string Capacitor::GetPrintDescriptionOfEComponent()

{

string msg;

msg.empty(); msg.append(GetUnitsOfEComponent()); msg.append(" "); msg.append("Farad(s)");

return msg;

}

// file 8 : Battery class header file named Battery.h

#pragma once

#include "ecomponent.h"

class Battery :

public EComponent

{

public:

Battery(void);

virtual ~Battery(void);

Battery(double value);;

double GetValueOfEComponent();

string GetUnitsOfEComponent();

string GetPrintDescriptionOfEComponent();

};

// file 9 : Battery class code file named Battery.cpp

#include "StdAfx.h"

#include "Battery.h"

Battery::Battery(void)

{

}

Battery::~Battery(void)

{

}

Battery::Battery(double value)

{

this->mValue = value;

}

double Battery::GetValueOfEComponent()

{

return mValue;

}

string Battery::GetUnitsOfEComponent()

{

string value;

std::ostringstream strStream;

strStream << GetValueOfEComponent();

value = strStream.str();

return value;

}

string Battery::GetPrintDescriptionOfEComponent()

{

string msg;

msg.empty(); msg.append(GetUnitsOfEComponent()); msg.append(" "); msg.append("Volt(s)");

return msg;

}