C++ HELP!

I am a beginner in C++ coding and need some help. This first part is given and I will post what I wrote after. I have the complete program listed below and keep getting the following fatal error: 1>------ Build started: Project: Lab 2, Configuration: Debug Win32 ------
1> Lab 2.cpp
1>c:\users\documents\visual studio 2010\projects\lab 2\lab 2\lab 2.cpp(19): fatal error C1083: Cannot open include file: 'Resistor.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is my code and any help would be greatly appreciated!
#include "Resistor.h"
#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)
{
//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++)
{
if(nomEdit == nominalE24Values[i])
{
validEIA = true;
cout << "Valid EIA value entered" << endl;
}
}
}
else if(tolEdit == 2)
{
for( i = 0; i < E48; i++)
{
if(nomEdit == nominalE48Values[i])
{
validEIA = true;
cout << "Valid EIA value entered" << endl;
}
}
}
else
{
for( i = 0; i < E96; i++)
{
if(nomEdit == nominalE96Values[i])
{
validEIA = true;
cout << "Valid EIA value entered" << endl;
}
}
}
if (validEIA == false)
{
cout << "Invalid EIA value entered, try again" << endl;
}
}
while(validEIA == false);
do
{
cout << endl << "Enter a power of ten multiplier between -2 (0.01) and 3 (1000): ";
cin >> powerOfTen;
cout << "You entered " << powerOfTen << endl;
}
while(powerOfTen < -2 || powerOfTen > 3);
resObj.setNominal((double)nomEdit * pow(10.0,(double)powerOfTen), fnDisplay);
}
This is what I wrote:

// In this file, all the class member functions that are
// declared in the "Resistor.h" file are defined.
#include "Resistor.h"
#include <iostream>
#include <iomanip>
#include <string.h>
#include <Windows.h>
using namespace std;
//This functions retrieves the nominal resistance value from the user.
double CResistor::getNominal(bool fnDisplay)
{
fnDisplay = true;
if (fnDisplay != false)
{
cout << " The 'getNominal' function has been called" << endl;
}
return nominalRes;
}

//This function retrieves the nominal tolerance from the user and display's
//a test message that states the function has been called if the correct boolean
//value has been set.
double CResistor::getTolerance(bool fnDisplay)
{
fnDisplay = true;
if (fnDisplay != false)
{
cout << " The 'getTolerance()' function has been called" << endl;
}
return nominalTol;
}

//This function retrieves the resistor name from the user.
string CResistor::getResName(bool fnDisplay)
{
fnDisplay = true;
if (fnDisplay != false)
{
cout << " The 'getResName()' function has been called" << endl;
}
return (resistorName);
}

//This function defines the Constructor. The Constructor has 4 defualt parameters that will
//initialize the class member attributes nominalRes, nominalTol and resistorName to a default
//value.
CResistor::CResistor(double R,double T,string rN,bool fnDisplay)
{
fnDisplay = true;
if(fnDisplay != false)
{
cout << "The Constructor is called" << endl;
cout << endl;
if(0.0 < R)
{
nominalRes = R;
}
else
{
nominalRes = 0.0;
}
if(.00 < T)
{
nominalTol = T;
}
else
{
nominalTol = .00;
}
resistorName = rN;
}
}

//This function will reset the class member attribute "nominalTol"
//to the user defined tolerance value.
void CResistor::setTolerance(double Tol,bool fnDisplay)
{
fnDisplay = true;
if(fnDisplay != false)
{
cout <<"The setTolerance function was called" << endl;
}
nominalTol = Tol;
}

void CResistor::setNominal(double nom,bool fnDisplay)
{
fnDisplay = true;
if(fnDisplay != false)
{
cout <<"The setNominal function was called" << endl;
}
nominalRes = nom;
}

#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;
};
Is there a file named Resistor.h in the same location as the file that you posted?
It looks to me like you might be using visual studio, is that correct?
Last edited on
Yes I am using visual basic 2010 and that is my whole file split into 2 sections, because it would not let me post it all at once. I wrote the 2 files on the bottom and I was given the big file on the top.
Last edited on
Is there a file named Resistor.h in the same location as the file that you posted?
No. That is what I got lost on....That is what I was told the resistor class would be or pull up. Like I said before I am new and don't completely understand.
Last edited on
Did your teacher provide Resistor.h?
See the next post, because I figured out most of the problems with the resistor.h file.
Last edited on
I am have done a lot of work on this and would appreciate a small amount of help. I am now down to just one error - 1>Lab 2.cpp(39): error C2059: syntax error : ';'. I will list all the code I have now to see if anyone can see what I am missing. These are my .h and .cpp files for the class I had to write:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184


// file Resistor.h

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class Resistor
	{
		private:
			string name;
			double value;
			double tolerance;
			double minValue;
			double maxValue;
		public:
			void DisplayResistor();
			void GetResistance();
	};

// file Resistor.cpp

#include "stdafx.h"
#include "Resistor.h"
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

void Resistor::DisplayResistor()
	{
	};

void Resistor::GetResistance()
	{
	};

//And this is my main program given by the professor and I underlined and 
//bolded the line causing the issue:

// Lab 2.6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

#include "Resistor.h"
#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;
	}
Last edited on
Please post the error you are getting.
You have extra semicolons in you Resistor.cpp file.

Can you highlight your files with the code button on the right?
See this link for information: http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
Your professor purposefully give you a program with two main functions????
That is unusual.
I made a post above about the same time that you posted your main.cpp
There I fixed the code and no the resistor.cpp is generated when you make a resistor.h file. Or are you taking about the int_tmain line? If so, that is created by Visual Basic 2010 when I open a new console cpp project.
Last edited on
The syntax error reads:
Lab 2.cpp(39): error C2059: syntax error : ';'

This means that on line 39 of Lab 2.cpp there is a syntax error. Like I said earlier there are extra semicolons.
How to show line numbers in VS 2010:
http://msdn.microsoft.com/en-us/library/ms165340(v=vs.100).aspx
Topic archived. No new replies allowed.