I'm new to programing and any help would not only be appreciated but would probably help me pass this class.

Exercise 1: Implement a Resistor Class


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

Overview: Create and test a class that models a resistor.

Resistor Class UML Diagram:

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 Resistor2)


Resistor Class Member Specifications:

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

Member Functions Specification
void DisplayResistor(void) A function that displays the resistor's data members in the following format:

Values for ResistorOne are:
Resistor Nominal Value = 1000.0
ohmsResistorTolerance = 10.0 %
Mininimum Resistance = 900.0 ohms
Maximum Resistance = 1100.0 ohms
NOTE: All decimal points must be aligned and upper and lowercase letters shown. Also, note that the resistor's tolerance is stored as a decimal (0.10) it is displayed as a percentage (10%).


void EnterResistance (void) This function prompts the user to enter new values for both m_dResValue and m_dTolerance and then uses the display resistor function to display the current values of the resistor object.

The resistor value must be in the following range:
m_dResValue > 0 && m_dResValue < 10,000,000

The value entered for tolerance must be a decimal number and not a whole number.

The program should force the user to continue data entry until acceptable values are entered (use a loop).

After valid data has been entered for the nominal and tolerance members the function should calculate new values for m_dMinResistance and m_dMaxResistance. The formula's these calculations are as follows:

m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);

m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);

After all data entry and calculations are completed the DisplayResistor function will be called.

NOTE: Even though tolerance will be stored as a decimal the value it should be displayed in percentage format. For example, a value of 10% tolerance would be entered as .10<ENTER> , would be displayed as 10.0% and would be stored in the member variable m_dTolerance as 0.10.

void AddSeries (ResistorClass Resistor1, ResistorClass Resistor2) This function adds the values of two Resistor Class objects storing the result in a third Resistor Class object.
The objects to be summed are passed as arguments to the AddSeries function. The results are saved to the calling object's data members.

The sum of the two resistor objects' nominal values will be stored in m_dResValue.

The new tolerance value will be the larger of the two resistor objects' m_dTolerance members (you'll need an if-statement).

New values for m_dMinResistance and m_dMaxResistance will be calculated using the following formulas:

m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);

m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);

Here is what I have for the first part. Some from me some with help

#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, '\n');
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, '\n');
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;
}

Exercise 2: Test the Resistor Class


Objective: Create a program that tests each member of the Resistor Class to ensure that they work properly.

Complete the following Tasks:

Create a main function and instantiate three Resistor Class objects: Resistor1, Resistor2 and Resistor3.
The program will then call the EnterResistance function for Resistor1, Resistor2, Resistor3.
The program should then call Resistor3's AddSeries function. The function call will look like this: Resistor3.AddSeries(Resistor1, Resistor2);
The program will now display the current values for Resistor1, Resistor2 and Resistor3 using the DisplayResistor function.
End program

Here is a sample of the program output:

Attachments

So what exactly are you having trouble with? All that I see here is a wall of text containing 2 assignment dumps and a poorly-formatted (meaning hard-to-read) code dump.

Unless I missed it, I don't see a good description of what your issue is and what you would like us to help you with... If you have program output, it's obviously compiling. Are you getting invalid values?

Edited 5 Years Ago by Fbody: n/a

Sorry to trouble you stuck up, arrogant so called code experts. I fixed the problem myself. Thank you very much!!

Comments
It's not our fault you didn't explain yourself.

Sorry to trouble you stuck up, arrogant so called code experts. I fixed the problem myself. Thank you very much!!

It's not our fault you didn't explain yourself well... We honestly had no idea what you needed us to look at. There really is no way for us to know unless you tell us. We're not psychics...

Edited 5 Years Ago by Fbody: n/a

Sorry for the remark everyone I was a bit frustrated at the time and the LAZY comment made me mad. But I do get a lot of help from this site and I do appreciate it.

I come off as a douche-bag a lot, I think my personality is worse online.

Really, it's happened like 3-4 times now. I'm glad you were able to fix your problem. I would also like to give you a tip I think may be helpful, set breakpoints and press F5 for the "Debug" build of your application. It will pause execution and allow you to examine the contents of variables, and the debugger tool can also be used to track the flow-of-control. You can then narrow down the problem entirely.

This question has already been answered. Start a new discussion instead.