Resistor

The program is giving me undeclared identifiers everywhere. It is like the programs are not linking.
Resistor.H
#include <iostream>
#include <iomanip>
#include <string.h>
#include <Windows.h>
using namespace std;
class CResistor
{
public:
double getNominal(bool);
double getTolerance(bool);
string getResName(bool);
void setTolerance(double,bool);
void setNominal(double,bool);
CResistor(double,double,string,bool);
CResistor();

private:
double nominalRes;
double nominalTol;
string resistorName;
};
ResistorMain.cpp
#include "Resistor.h"
#include "source.cpp"
#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <math.h>
#include <string>

using namespace std;

//EIA Standard array element sizes per tolerance class
const int E12 = 12;
const int E24 = 24;
const int E48 = 48;
const int E96 = 96;

//EIA Standard Resistor Values
//E12 10% tolerance
//E24 5% tolerance
//E48 2% tolerance
//E96 1% tolerance

//10% standard values
const int nominalE12Values[E12] =
{ 100, 120, 150, 180, 220, 270,
330, 390, 470, 560, 680, 820};

//5% standard values
const int nominalE24Values[E24] =
{ 100, 110, 120, 130, 150, 160, 180, 200, 220, 240,
270, 300, 330, 360, 390, 430, 470, 510, 560, 620,
680, 750, 820, 910};

//2% standard values
const int nominalE48Values[E48] =
{ 100, 105, 110, 115, 121, 127, 133, 140, 147, 154,
162, 169, 178, 187, 196, 205, 215, 226, 237, 249,
261, 274, 287, 301, 316, 332, 348, 365, 383, 402,
422, 442, 464, 487, 511, 536, 562, 590, 619, 649,
681, 715, 750, 787, 825, 866, 909, 953};

//1% standard values
const int nominalE96Values[E96] =
{ 100, 102, 105, 107, 110, 113, 115, 118, 121, 124,
127, 130, 133, 137, 140, 143, 147, 150, 154, 158,
162, 165, 169, 174, 178, 182, 187, 191, 196, 200,
205, 210, 215, 221, 226, 232, 237, 243, 249, 255,
261, 267, 274, 280, 287, 294, 301, 309, 316, 324,
332, 340, 348, 357, 365, 374, 383, 392, 402, 412,
422, 432, 442, 453, 464, 475, 487, 499, 511, 523,
536, 549, 562, 576, 590, 604, 619, 634, 649, 665,
681, 698, 715, 732, 750, 768, 787, 806, 825, 845,
866, 887, 909, 931, 953, 976};

void DisplayResistance(CResistor&, bool );
void EnterResistance(CResistor&, bool);

void main(void)
{

//Print programmer's name and assignment number name.

cout << setfill('*') << setw(25) << "" << endl;
cout << setfill('*') << setw(2) << "" << " Terry Bright" << setw(2) << "" << endl;
cout << setfill('*') << setw(2) << "" << " iLab assignment wk2 " << setw(2) << "" << endl;
cout << setfill('*') << setw(25) << "" << endl;

//Control variable to display function names when called
bool fnDisp = false;
string Resistor1 = "Res1";
string Resistor2 = "Res2";
string Resistor3 = "Res3";

CResistor Res1(4700.0, 0.10, Resistor1, fnDisp);
CResistor Res2(330.0, 0.10, Resistor2, fnDisp);
CResistor Res3(10000.0,0.10, Resistor3, fnDisp);

DisplayResistance(Res1, fnDisp);
DisplayResistance(Res2, fnDisp);
DisplayResistance(Res3, fnDisp);

EnterResistance(Res1, fnDisp);
DisplayResistance(Res1, fnDisp);

system("pause");
}

// Function displays all data member values of a CResistor object
void DisplayResistance(CResistor& resObj, bool fnDisplay)
{
//Local variables to hold CResistor data copies
double nom, tol, min, max;
nom = resObj.getNominal(fnDisplay);
tol = resObj.getTolerance(fnDisplay);
min = nom * (1.0 - tol);
max = nom * (1.0 + tol);
cout << endl << "Resistor object name is " << resObj.getResName(fnDisplay) << endl;
cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint)
<< setprecision(3);
cout << endl << "Nominal resistance value = " << setw(15) << nom << " ohms ";
cout << endl << "Tolerance = " << setw(15) << tol * 100 << " %";
cout << endl << "Minimum Resistance = " << setw(15) << min << " ohms";
cout << endl << "Maximum Resistance = " << setw(15) << max << " ohms";
cout << endl << endl;
}

// Function allows user to enter new values for CResistor data members
void EnterResistance(CResistor& resObj, bool fnDisplay)
{
//Local variables to hold CResistor data copies
double nom, tol;
string name;

//Local variable for user data entry
int nomEdit = 0;
int tolEdit = 0;
int powerOfTen = 0;

//Valid EIA entry value check boolean
bool validEIA = false;

//Local loop counter
int i = 0;

nom = resObj.getNominal(fnDisplay);
tol = resObj.getTolerance(fnDisplay);
name = resObj.getResName(fnDisplay);
cout << endl << endl;
cout << "Resistor being edited: " << name << endl << endl;

do
{
cout << "Current resistance tolerance = " << tol * 100 << " %" << endl;
cout << "Valid tolerances are 1%, 2%, 5% or 10%" << endl << endl;
cout << "Enter 1, 2, 5 or 10: ";
cin >> tolEdit;
cout << endl;
}
while(tolEdit != 1 && tolEdit != 2 && tolEdit != 5 && tolEdit != 10);

cout << "Tolerance set to " << tolEdit << " %" << endl << endl;
resObj.setTolerance((double)tolEdit*0.01, fnDisplay);

do
{
cout << "Current nomimal resistance = " << nom << " ohms" << endl;
cout << "Standard 10% Resistance Values, First Three Digits" << endl << endl;

if(tolEdit == 10)
{
for( i = 0; i < E12; i++)
{
if(!(i % 10))
cout << endl;
cout << nominalE12Values[i] << " ";
}
}
else if(tolEdit == 5)
{
for( i = 0; i < E24; i++)
{
if(!(i % 10))
cout << endl;
cout << nominalE24Values[i] << " ";
}
}
else if(tolEdit == 2)
{
for( i = 0; i < E48; i++)
{
if(!(i % 10))
cout << endl;
cout << nominalE48Values[i] << " ";
}
}
else
{
for( i = 0; i < E96; i++)
{
if(!(i % 10))
cout << endl;
cout << nominalE96Values[i] << " ";
}
}

cout << endl << endl << "Enter first three digits: ";
cin >> nomEdit;
cout << "You entered " << nomEdit << endl;
validEIA = false;

if(tolEdit == 10)
{
for( i = 0; i < E12; i++)
{
if(nomEdit == nominalE12Values[i])
{
validEIA = true;
cout << "Valid EIA value entered" << endl;
}
}
}
else if(tolEdit == 5)
{
for( i = 0; i < E24; i++)
{

First step put [ Code ] [ /Code ] tags each of your code segments so we can read it easily.
http://www.cplusplus.com/articles/jEywvCM9/

Also, please copy and paste the exact errors you are getting. Do not expect us to magically know what you are seeing on your screen.

Additonally, you should use <cstring> rather than <string.h>, unless you meant to use <string> for std::string rather than C-style strings.
Last edited on
It's a good idea to include all the necessary libraries in your header files. That way you don't have to guess about what you need to include in your source files and you aren't repeating. There are exceptions but in your case, it's the best way to go.

We can already see that you are wasting space by including the same libraries in both your header and source files.

You are also including a source file which is generally a big no-no. Source files should include headers and occasionally libraries while headers should include libraries and other headers.
Last edited on
IceThatJaw wrote:
We can already see that you are wasting space by including the same libraries in both your header and source files.
That's not how include guards work.
He wasted several bytes of space typing that redundant line though. haha
I'm no C++ expert so I'll just leave now.
Last edited on
It's actually a good practice - if the source file continues to have the dependency but the dependency is removed from the header, you won't have to remember to adjust the source file.
Last edited on
Error 1 error C2011: 'CResistor' : 'class' type redefinition c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.h 8 1 ResistorWeek2
Error 2 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 13 1 ResistorWeek2
Error 4 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 28 1 ResistorWeek2
Error 6 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 40 1 ResistorWeek2
Error 8 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 54 1 ResistorWeek2
Error 12 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 84 1 ResistorWeek2
Error 14 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 94 1 ResistorWeek2
Error 27 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 93 1 ResistorWeek2
Error 29 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 94 1 ResistorWeek2
Error 31 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 97 1 ResistorWeek2
Error 33 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 125 1 ResistorWeek2
Error 35 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 126 1 ResistorWeek2
Error 37 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 127 1 ResistorWeek2
Error 40 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 142 1 ResistorWeek2
Error 42 error C2027: use of undefined type 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 251 1 ResistorWeek2
Error 9 error C2062: type 'double' unexpected c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 54 1 ResistorWeek2
Error 3 error C2065: 'nominalRes' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 20 1 ResistorWeek2
Error 15 error C2065: 'nominalRes' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 101 1 ResistorWeek2
Error 5 error C2065: 'nominalTol' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 35 1 ResistorWeek2
Error 13 error C2065: 'nominalTol' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 91 1 ResistorWeek2
Error 7 error C2065: 'resistorName' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 47 1 ResistorWeek2
Error 17 error C2078: too many initializers c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 74 1 ResistorWeek2
Error 19 error C2078: too many initializers c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 75 1 ResistorWeek2
Error 21 error C2078: too many initializers c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 76 1 ResistorWeek2
Error 16 error C2079: 'Res1' uses undefined class 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 74 1 ResistorWeek2
Error 18 error C2079: 'Res2' uses undefined class 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 75 1 ResistorWeek2
Error 20 error C2079: 'Res3' uses undefined class 'CResistor' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 76 1 ResistorWeek2
Error 10 error C2143: syntax error : missing ';' before '{' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 55 1 ResistorWeek2
Error 28 error C2228: left of '.getNominal' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 93 1 ResistorWeek2
Error 34 error C2228: left of '.getNominal' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 125 1 ResistorWeek2
Error 32 error C2228: left of '.getResName' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 97 1 ResistorWeek2
Error 38 error C2228: left of '.getResName' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 127 1 ResistorWeek2
Error 30 error C2228: left of '.getTolerance' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 94 1 ResistorWeek2
Error 36 error C2228: left of '.getTolerance' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 126 1 ResistorWeek2
Error 43 error C2228: left of '.setNominal' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 251 1 ResistorWeek2
Error 41 error C2228: left of '.setTolerance' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 142 1 ResistorWeek2
Error 11 error C2447: '{' : missing function header (old-style formal list?) c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistance.h 55 1 ResistorWeek2
Error 22 error C2664: 'DisplayResistance' : cannot convert parameter 1 from 'int' to 'CResistor &' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 78 1 ResistorWeek2
Error 23 error C2664: 'DisplayResistance' : cannot convert parameter 1 from 'int' to 'CResistor &' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 79 1 ResistorWeek2
Error 24 error C2664: 'DisplayResistance' : cannot convert parameter 1 from 'int' to 'CResistor &' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 80 1 ResistorWeek2
Error 26 error C2664: 'DisplayResistance' : cannot convert parameter 1 from 'int' to 'CResistor &' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 83 1 ResistorWeek2
Error 25 error C2664: 'EnterResistance' : cannot convert parameter 1 from 'int' to 'CResistor &' c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 82 1 ResistorWeek2
Error 39 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\users\terry\documents\visual studio 2010\projects\resistorweek2\resistorweek2\resistor.cpp 129 1 ResistorWeek2
(These are the errors)
I tried to separate the code but it is taking too many characters and will not let me separate. The dotted lines are the best I can do for now.
Could not wait on you slow people.
Topic archived. No new replies allowed.