class ResistorClass
{/*declearation of required variables and are declared as private specifier*/
private:
string m_cResistorName;
double m_dResValue;
double m_dTolerance;
double m_dMinResistance;
double m_dMaxResistance;
/*declearation of functions which re declared as public*/
public:
void DisplayResistor(void );
void EnterResistance (void);
void AddSeries (ResistorClass Resistor1, ResistorClass Resistor2);
};
/* defining fuctions, the functions will make the user to enter resistance and cjheck if the value is in required range or else to enter again*/
void ResistorClass:: EnterResistance (void)
{
int i=1,i1=1;
double m_r=0,m_r1=0;
cout<<"\n Enter Resistor name";
cin>>m_cResistorName;
cout<<"\n Enter resistor value"
cin>>m_r1;
/*while loop will make the user to enter the values reptively until unless value is in required range*/
while(i!=0)
{
/*if else condition for checking the condition*/
if(m_r1> 0 && m_r1 < 10,000,000 )
{
m_cResistorName=m_r1;
i=0
}
else
{
cout<<"\n Value out of Range";
cout<<"\n Enter resistor value"
cin>>m_r1;
}
cout<<"\n Enter resistor tolerance value"
cin>>m_r;
/*while loop will make the user to enter the values reptively until unless value is in required range*/
while(i1!=0)
{
/*if else condition for checking the condition*/
if(m_r< 0)
{
m_dTolerance=m_r/100;
i=0
}
else
{
cout<<"\n Value out of Range";
cout<<"\n Enter resistor tolerance value"
cin>>m_r;
}
/* calculate the minimum and mximum resistnce*/
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
}
/* function defination to display the enter values and caluculated vlues*/
void ResistorClass:: DisplayResistor(void )
{
cout<<"\n Values for ResistorOne are:";
cout<<" \nNAme is \t"<<m_cResistorName;
cout<<"\n Resistor Nominal Value \t"<<m_dResValue;
cout<<"\n ohmsResistorTolerance \t"<<m_dTolerance *100 <<"%";
cout<<"\n Mininimum Resistance \t"<<m_dMinResistance<<"ohm";
cout<<"\n Maximum Resistance \t"<<m_dMaxResistance<<"ohm";
}
/*defining the fuction*/
void ResistorClass::AddSeries (ResistorClass Resistor1, ResistorClass Resistor2)
{
ResistorClass r1;
r1.m_cResistorName=" ResultOne"
r1.m_dResValue=Resistor1.m_dResValue+Resistor2.m_dResValue;
r1.m_dTolerance=Resistor1.m_dTolerance+Resistor2.m_dTolerance;
r1.m_dMinResistance=r1.m_dResValue - (r1.m_dResValue * r1.m_dTolerance);
r1.m_dMaxResistance = r1.m_dResValue + (r1.m_dResValue * r1.m_dTolerance);
}
/*main function */
void main()
{
ResistorClass r1,r2,r3;/*declring objects of class*/
/*calling fuctions of the class*/
r1.EnterResistance();
r2.EnterResistance();
r1.DisplayResistor();
r2.DisplayResistor();
r3.AddSeries(r1,r2);
r3.DisplayResistor();
getche();
}