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

#include<iostream> using namespace std; class ResistorClass { public: string m_c

ID: 3621900 • Letter: #

Question

#include<iostream>
using namespace std;
class ResistorClass
{
public:
string m_cResistorName;
void DisplayResistor(void)
{
cout<<"Values for ResistorOne 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 EnterResistance (void)
{
int tol_int;
cout<<" Current values are Resistor Nominal Value = "<<m_dResValue<<endl;
cout<<"ohmsResistorTolerance = "<<m_dTolerance*100<<" %"<<endl<<endl;

do
{
cout<<"Enter Nominal Value :";
cin>>m_dResValue;
}

while(!(m_dResValue >= 0 && m_dResValue < 10000000) );
do
{
cout<<"Enter Tolerance:";
cin>>m_dTolerance;
tol_int = (int)m_dTolerance;
}
while(m_dTolerance != tol_int);
m_dTolerance = m_dTolerance/100;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout<<endl;
}
void 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;
}

private: //- sign member

double m_dResValue;
double m_dTolerance;
double m_dMinResistance;
double m_dMaxResistance;
};
int main(void)
{
ResistorClass rc1,rc2,rc3;
rc1.EnterResistance();
rc1.DisplayResistor();
rc2.EnterResistance();
rc2.DisplayResistor();
rc3.AddSeries(rc1,rc2);
cout<<"After AddSeries the new register values are :"<<endl;
rc3.DisplayResistor();system("pause");
}

And this is the assignment:

Objective: Create a C++ console application that utilizes the core concepts of
designing and creating classes, objects, properties and methods.

Overview: Add two constructor functions and a destructor function to the Resistor
class from last week's lab assignment.

Resistor Class UML Diagram (new members are in bold font):

Class: ResistorClass
+ string : m_cResistorName;
- double : m_dResValue;
- double : m_dTolerance;
- double : m_dMinResistance;
- double : m_dMaxResistance;
+ void : DisplayResistor(void)
+ void : EnterResistance (void )
+ void : AddSeries (ResistorClass Resistor1, ResistorClass Resistor1)

+ ResistorClass(void)
+ ResistorClass(string Name, double nominalResistance, double Tolerance)
+ResistorClass(const ResistorClass &ResistorObject)
+ ~ResistorClass(void)

Resistor Class Member Specifications:

Member Variables Specification
string m_cResistorName Stores the resistors name
double m_dResValue Stores the resistor's nominal value
double m_dTolerance The resistor's ohm tolerance stored as a decimal value
double m_dMinResistance The resistor's minimum resistance in ohms
double m_dMaxResistance The resistor's maximum resistance in ohms



New Member Functions Specification
ResistorClass( ) Prompt the user to input a name for the resistor object. Store
the name in the member variable m_cResistorName.
Initialize the resistor data members to the following values:

Set m_dResValue = 1000.0
Set m_dTolerance = 0.10

The value of m_dMinResistance and m_dMaxResistance should be calculated using the
member variables m_dResValue and m_dTolerance. Use the formula from week 3's lab
assignment.

This function should output the message: “Default Constructor Called”
ResistorClass(string Name, double nominalResistance, double Tolerance) This is a
parameterized constructor that accepts arguments for the resistor's name, nominal
resistance and tolerance.

The parameters nominalResistance and Tolerance will be used to initialize the
member variables m_dResValue and m_dTolerance.
The value of m_dMinResistance and m_dMaxResistance should be calculated using the
member variables m_dResValue and m_dTolerance. Use the formula from week 3's lab
assignment.

This function should output the message: “Parameterized Constructor Called”
ResistorClass(const ResistorClass &ResistorObject) This is a copy constructor used
to copy the values of an already existing Resistor object.

The nominal, tolerance, minimum and maximum values should be copied from the
resistor object passed to the function as an argument.

This function will prompt the user to enter a new name for the Resistor object
receiving the copied values. The name will be stored in the member variable

m_cResistorName.

This function should output the message: "Copy Constructor Called"

~ResistorClass( ) This is the destructor function. This function will output the
message “Destructor Called for " and complete the message by displaying the
resistor's name as stored in the member variable m_cResistorName.

Note: Begin work on this program by first creating the class declaration. Then
code and test the default and then the parameterized constructor functions. Code
and test the rest of the functions one at a time. To avoid compiler complaints,
comment out the member function prototypes in the class declaration that have not
yet been completed.













Explanation / Answer

To understand how the constructors work. They allow you to pre-assgin values by passing the values that you want that object to have when it is created. If you have an explicit value constructor in some cases you might want to have a default constructor so you can create instances of the object without having to assign any values to the object. Next destructors are only used when you dynamically allocate memory. I didn’t see any so I just made a default one.


#include
using namespace std;
class ResistorClass
{

public:
string m_cResistorName;

ResistorClass(){}//default constructor used if there is an expilcit value constuctor
//constructor that is used to preassign values of the resistor
ResistorClass(string ResistorName,double ResValue, double Tolerance,double MinResistance, double MaxResistance)
{
m_cResistorName = ResistorName;
m_dResValue = ResValue;
m_dTolerance = Tolerance;
m_dMinResistance = MinResistance;
m_dMaxResistance = MaxResistance;
}
~ResistorClass(){} //default distructor normally done by complier only need when there is dynamicly
//allocated memory
void DisplayResistor(void)
{
cout<<"Values for ResistorOne are:"<cout<<"Resistor Nominal Value = "<cout<<"ohmsResistorTolerance = "<cout<<"Mininimum Resistance = "<cout<<"Maximum Resistance = "<cout<}
void EnterResistance (void)
{
int tol_int;
cout<<" Current values are Resistor Nominal Value = "<cout<<"ohmsResistorTolerance = "<
do
{
cout<<"Enter Nominal Value :";
cin>>m_dResValue;
}

while(!(m_dResValue >= 0 && m_dResValue < 10000000) );
do
{
cout<<"Enter Tolerance:";
cin>>m_dTolerance;
tol_int = (int)m_dTolerance;
}
while(m_dTolerance != tol_int);
m_dTolerance = m_dTolerance/100;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout<}
void 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<}

private: //- sign member

double m_dResValue;
double m_dTolerance;
double m_dMinResistance;
double m_dMaxResistance;
};
int main(void)
{
ResistorClass rc1,rc2,rc3;
rc1.EnterResistance();
rc1.DisplayResistor();
rc2.EnterResistance();
rc2.DisplayResistor();
rc3.AddSeries(rc1,rc2);
cout<<"After AddSeries the new register values are :"<rc3.DisplayResistor();system("pause");
}