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

STEP 1: Create a Multifile Project Objective: Create a C++ console application t

ID: 3640147 • Letter: S

Question

STEP 1: Create a Multifile Project


Objective: Create a C++ console application that will model the characteristics of a resistor.

Create a multifile project. Create and add to the project an h file containing the resistor-class definition.
Create and add to the project a cpp file containing the implementation of the class-member functions.
Create and add to the project a ccp file containing the main() function, which will instantiate a resistor object and test its member functions.
STEP 2: Required Class Members


The resistor class will, at minimum, have members that do the following.

store the nominal resistance value of a resistor
store the tolerance of a resistor
initialize any and all nominal-resistance values to correct, EIA, nonzero values that are greater than 0 and less than 1,000,000 ohms
initialize any and all resistance-tolerance values to correct, E12, E24, E48, or E96 resistance-tolerance values
allow the nominal-resistance and tolerance values of a resistor object to be changed by the user
All member functions should have a test message stating the name of the function. All the test messages should be displayed or not displayed, depending on the value of a Boolean variable declared in main().
If the Boolean value = true, display the message.
If the Boolean value = false, do not display the message.
STEP 3: Program Operations


Function main() should instatiate two objects of class resistor.
Function main() should display the current values of all resistor objects.
Function main() should also calculate and display the minimum and maximum in-tolerance resistance values of each resistor object from the resistor data members.
Function main() should allow the user to change the values of the nominal resistance and the resistor tolerance of both resistor objects, and it should also correctly handle out of numeric-range input. Main() is also responsible for making sure that the user can successfully enter only correct, EIA resistance and tolerance values.
The user should be given the following data-entry choices:
accept current EIA values for resistance and tolerance;
The function main() should display the new, modified values of the resistor object, including the new min and max in-tolerance resistance values.
The function main() should be executed twice: once with the test messages displayed and once without.


#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class ResistorClass
{
private:
double m_dResValue;
double m_dTolerance;
double m_dMinResistance;
double m_dMaxResistance;
public:
string m_cResistorName;
void DisplayResistor( void );
void EnterResistance (void );
void AddSeries ( ResistorClass Resistor1, ResistorClass Resistor2 );
ResistorClass( );
ResistorClass( string Name, double nominalResistance, double Tolerance );
ResistorClass( const ResistorClass &ResistorObject );
~ResistorClass( );
};
int main( void )
{
ResistorClass oResOne;
Resistor tolerance = 20%
ResistorClass oResTwo("Resistor 2",4700,20);
ResistorClass oResThree(oResTwo);
oResOne.DisplayResistor();
oResTwo.DisplayResistor();
oResThree.DisplayResistor();
system("pause");
return 0;
}
void ResistorClass:: DisplayResistor ( void )
{
cout << fixed << setprecision (2);
cout<<"Values for "<<m_cResistorName<<" are: "<<endl;
cout<<"Resistor Nominal Value = "<<m_dResValue<<endl;
cout<<"ohmsResistorTolerance = "<<m_dTolerance*100<<" %"<<endl;
cout<<"Mininimum Resistance = "<<m_dMinResistance<<" ohms"<<endl;
cout<<"Maximum Resistance = "<<m_dMaxResistance<<" ohms"<<endl;
cout<<endl;
}
void ResistorClass::EnterResistance (void)
{
m_dResValue = -1;
while (m_dResValue < 1)
{
cout << "Enter Resistor Value: " <<endl;
cin >> m_dResValue;
if (m_dResValue < 1 || m_dResValue > 10000000)
{
cout << "Input Error Resistor Value must be > 1" << endl;
cout << "Please Enter a value that is > 1: " << endl;
cin >> m_dResValue;
}
else break;
}
m_dTolerance = -1;
while (m_dTolerance < 1)
{
cout << "Enter Resistor Tolerance: " << endl;
cin >> m_dTolerance;
if (m_dTolerance < 1 || m_dTolerance > 10000000)
{
cout << "Input Error Resistor Tolerance Value must be > 1: " << endl;
cout << "Please Enter a value that is > 1: " << endl;
cin >> m_dTolerance;
}
else break;
}
m_dTolerance = m_dTolerance/100;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout<<endl;
}
void ResistorClass:: AddSeries ( ResistorClass Resistor1, ResistorClass Resistor2)
{
if( Resistor1.m_dTolerance > Resistor2.m_dTolerance )
m_dTolerance = Resistor1.m_dTolerance;
else
m_dTolerance = Resistor2.m_dTolerance;
m_dResValue = Resistor1.m_dResValue + Resistor2.m_dResValue;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout<<endl;
}
ResistorClass::ResistorClass( )
{
cout << "Enter Resistor Name <default>: " ;
getline(cin, m_cResistorName, ' ');
m_dResValue = 1000.0;
m_dTolerance = 0.10;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout <<endl<< "Default Constructor Called:" <<endl;
}

ResistorClass::ResistorClass( string Name, double nominalResistance, double Tolerance )
{
cout <<endl<<"Parameterized Constructor Called:" <<endl;
m_dResValue = nominalResistance;
m_dTolerance = double(Tolerance/100);
m_cResistorName = Name;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
}
ResistorClass::ResistorClass(const ResistorClass &ResistorObject)
{
cout<<endl <<"Enter Resister Name <copy>: ";
getline(cin, m_cResistorName, ' ');
m_dResValue=ResistorObject.m_dResValue;
m_dTolerance=ResistorObject.m_dTolerance;
m_dMaxResistance=ResistorObject.m_dMaxResistance;
m_dMinResistance=ResistorObject.m_dMinResistance;
cout <<endl<<"Copy Constructor Called:"<<endl;
}
ResistorClass:: ~ResistorClass( )
{
cout << "Destructor Called "<<endl;
}


1. List the complete reference-source information for where you found the EIA standard resistor value and tolerance information.
2. How was this reference discovered and where?

Explanation / Answer

#include<iostream>
using namespace std;
class Resistor
{
double nominalResistance;
double tolerance;
public:
Resistor(void);

//initialize any and all nominal-resistance values to correct, EIA, nonzero values that are greater than 0 and less than 1,000,000 ohms
//initialize any and all resistance-tolerance values to correct, E12, E24, E48, or E96 resistance-tolerance values

Resistor(double,double);
//allow the nominal-resistance and tolerance values of a resistor object to be changed by the user
void setNominalResistance(double,bool);
void setTolerance(double,bool);

double getNominalResistance(bool);
double getTolerance(bool);
~Resistor(void);
};

#include "Resistor.h"


Resistor::Resistor(void)
{
}


Resistor::~Resistor(void)
{
}

Resistor::Resistor(double nomRes,double tol)
{
nominalResistance=nomRes;
tolerance=tol;
}
void Resistor::setNominalResistance(double nomRes,bool value)
{
if(value)
{
cout<<endl<<"Method setNominalResistance()";
}
nominalResistance=nomRes;
}
void Resistor::setTolerance(double tol,bool value)
{
if (value)
{
cout<<endl<<"Method setTolerance()";
}
tolerance=tol;
}
double Resistor::getNominalResistance(bool value)
{
if(value)
{
cout<<endl<<"Method getNominalResistance()";
}
return nominalResistance;
}
double Resistor::getTolerance(bool value)
{
if(value)
{
cout<<endl<<"Methos getTolerance()";
}
return tolerance;
}

//The function main() should display the new, modified values of the resistor object, including the new min and max in-tolerance resistance values.
cout<<"Nominal Resistance for res1 : "<<res1.getNominalResistance(test);
cout<<endl<<"Tolerance for res1 : "<<res1.getTolerance(test);
cout<<endl<<"Nominal Resistance for res2 : "<<res2.getNominalResistance(test);
cout<<endl<<"Tolerance for res2 : "<<res2.getTolerance(test);
if(res1.getTolerance(test)<res2.getTolerance(test))
{
cout<<endl<<"Minimum tolerance : "<<res1.getTolerance(test);
cout<<endl<<"Maximum tolerance : "<<res2.getTolerance(test);
}
else
{
cout<<endl<<"Minimum tolerance : "<<res2.getTolerance(test);
cout<<endl<<"Maximum tolerance : "<<res1.getTolerance(test);
}

//The function main() should be executed twice: once with the test messages displayed and once without.
test=false;
//Function main() should instatiate two objects of class resistor.
//Resistor res1(1,.1), res2(2,.2);
//Function main() should display the current values of all resistor objects.
cout<<"Nominal Resistance for res1 : "<<res1.getNominalResistance(test);
cout<<endl<<"Tolerance for res1 : "<<res1.getTolerance(test);
cout<<endl<<"Nominal Resistance for res2 : "<<res2.getNominalResistance(test);
cout<<endl<<"Tolerance for res2 : "<<res2.getTolerance(test);
//Function main() should also calculate and display the minimum and maximum in-tolerance resistance values of each resistor object from the resistor data members.
if(res1.getTolerance(test)<res2.getTolerance(test))
{
cout<<endl<<"Minimum tolerance : "<<res1.getTolerance(test);
cout<<endl<<"Maximum tolerance : "<<res2.getTolerance(test);
}
else
{
cout<<endl<<"Minimum tolerance : "<<res2.getTolerance(test);
cout<<endl<<"Maximum tolerance : "<<res1.getTolerance(test);
}
//Function main() should allow the user to change the values of the nominal resistance and the resistor tolerance of both resistor objects, and it should also correctly handle out of numeric-range input. Main() is also responsible for making sure that the user can successfully enter only correct, EIA resistance and tolerance values.

//The function main() should display the new, modified values of the resistor object, including the new min and max in-tolerance resistance values.
cout<<"Nominal Resistance for res1 : "<<res1.getNominalResistance(test);
cout<<endl<<"Tolerance for res1 : "<<res1.getTolerance(test);
cout<<endl<<"Nominal Resistance for res2 : "<<res2.getNominalResistance(test);
cout<<endl<<"Tolerance for res2 : "<<res2.getTolerance(test);
if(res1.getTolerance(test)<res2.getTolerance(test))
{
cout<<endl<<"Minimum tolerance : "<<res1.getTolerance(test);
cout<<endl<<"Maximum tolerance : "<<res2.getTolerance(test);
}
else
{
cout<<endl<<"Minimum tolerance : "<<res2.getTolerance(test);
cout<<endl<<"Maximum tolerance : "<<res1.getTolerance(test);
}
system ("pause");
return 0;
}