testing resistor classes.

Hi everyone.

I have to do something whereI create a class that models a resistor and then create a main function where it will call on three different resistors using resistor3's addseries function and display values for all three functions. This is all I have. any help?

#include <iostream>
using namespace std;

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)

}

int main (void)
{
return 0;

}
If this code compiles, then you're not using a proper C++ compiler. In fact, this reminds me a little bit of Objective C. O_o

Problems:

1) No [code] tags.

2) Line 4: class ResistorClass //Not "Class:"

3) Clear the +es and -es. I'm guessing that a + was meant to symbolize a public member and a - a private member. I suppose I could do the work for you on this as long as you read the comments. :)
1
2
3
4
5
6
7
8
9
10
11
12
13
{
public: //This is how you specify public members. The following elements will be public.
    string m_cResistorName;
    void DisplayResistor(); //Missed Semicolon. The void is redundant. :)
    void EnterResistance (); //Missed Semicolon. The void is redundant.
    void AddSeries (ResistorClass Resistor1, ResistorClass Resistor2); //Missed Semicolon.
    ResistorClass(); //You need a default constructor to set the values of everything to NULL.
private: //Cancels the previous tag; the following members are private.
    double m_dResValue;
    double m_dTolerance;
    double m_dMinResistance;
    double m_dMaxResistance; 
}; //Missed semicolon. :P 


To write the implementations of your functions, here's a neat little template you can use to write the implementations outside of your class or any other functions.

1
2
3
4
returntype classname::member(parameters)
{
    //Implementation.
}


For constructors, it is done like this:
1
2
3
4
classname::classname(parameters)
{
    //Implementation.
}


Have fun!

-Albatross
Last edited on
ok this is what I have and I need to get output to show values on three different resistors.




#include <iostream>
using namespace std;

class ResistorClass
{


private:
// properties
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);

}

it should have nominal value resistor tolerance min and max ohms for each one. I dont really know how to do this. any help would be great.
Topic archived. No new replies allowed.