Multifile Project Help - Compile Errors

Hi everyone, I'm working on an assignment involving a multifile project, and I'm getting a number of compile errors I'm not sure how to fix. Basically, the assignment requires that we create a class in a header file, and write the functions for the class in another .cpp file. I'll start with my header file, then my .cpp file, and finally, the source. I appreciate the help, as this online class is making it very difficult for me to get any. Compile errors to follow.

Resistor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class CResistor
{
public:
	double getNominal(bool fnStatus);
	void setNominal(double edit, bool fnStatus);
	string getResName(bool fnStatus);
	double getTolerance(bool fnStatus);
	void setTolerance(double edit, bool fnStatus);

	CResistor(double resNom, double resTol, string resName, bool fnStatus);

private:
	double resNom;
	double resTol;
	string resName;
	bool fnStatus;
};


Resistor.cpp
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
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

#include "Resistor.h"

double CResistor::getNominal(bool fnStatus)
{
	if (fnStatus == true)
	{
		cout << "Function: getNominal\n";
	};
	return resNom;
}

void CResistor::setNominal(double edit, bool fnStatus)
{
	if (fnStatus == true)
	{
		cout << "Function: setNominal\n";
	};

	resNom = edit;
}

string CResistor::getResName(bool fnStatus)
{
	if (fnStatus == true)
	{
		cout << "Function: getResName\n";
	}
	
	return resName;
	
}

double CResistor::getTolerance(bool fnStatus)
{
	if (fnStatus == true)
	{
		cout << "Function: getTolerance\n";
	};
	return resTol;
}

void CResistor::setTolerance(double edit, bool fnStatus)
{
	if (fnStatus == true)
	{
		cout << "Function: setTolerance\n";
	};

	resTol = edit;
};


Source.cpp
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
  //Filename:  ResistorSource.cpp

//Description: Contains CResistor class test function

//Class:  COMP 220

//Student Name:  Julio Adame

#include "Resistor.h"

#include <iostream>

#include <iomanip>

#include <Windows.h>

#include <math.h>

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;

	CResistor Res1(4700.0, 0.10, "Res1", fnDisp);

	CResistor Res2(330.0, 0.10, "Res2", fnDisp);

	CResistor Res3(10000.0, 0.10, "Res3", 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);

}
Last edited on
Compile errors:

Error 1 error C2146: syntax error : missing ';' before identifier 'getResName' c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistor.h 6 1 ResistorProgram
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistor.h 6 1 ResistorProgram
Warning 3 warning C4183: 'getResName': missing return type; assumed to be a member function returning 'int' c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistor.h 6 1 ResistorProgram
Error 4 error C2061: syntax error : identifier 'string' c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistor.h 10 1 ResistorProgram
Error 5 error C2146: syntax error : missing ';' before identifier 'resName' c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistor.h 15 1 ResistorProgram
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistor.h 15 1 ResistorProgram
Error 7 error C2661: 'CResistor::CResistor' : no overloaded function takes 4 arguments c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistorsource.cpp 110 1 ResistorProgram
Error 8 error C2661: 'CResistor::CResistor' : no overloaded function takes 4 arguments c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistorsource.cpp 112 1 ResistorProgram
Error 9 error C2661: 'CResistor::CResistor' : no overloaded function takes 4 arguments c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistorsource.cpp 114 1 ResistorProgram
Error 10 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\users\yo\documents\visual studio 2013\projects\resistorprogram\resistorprogram\resistorsource.cpp 206 1 ResistorProgram
11 IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char>> << std::string c:\Users\Yo\Documents\Visual Studio 2013\Projects\ResistorProgram\ResistorProgram\ResistorSource.cpp 150 45 ResistorProgram
12 IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char>> << std::string c:\Users\Yo\Documents\Visual Studio 2013\Projects\ResistorProgram\ResistorProgram\ResistorSource.cpp 206 37 ResistorProgram
Last edited on
Does the source.cpp have to include Resistor.cpp file instead of .h ?
Last edited on
To my understanding, no. If the .h file is included in both .cpp files, the program should be fine. I just updated the code, as I changed some things to reduce errors.

I'm very new to programming, and I'm really not understanding what I'm doing wrong here...
Last edited on
Resistor.h
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
// see: http://en.wikipedia.org/wiki/Include_guard
#ifndef CRESISTOR_H_INCLUDED_
#define CRESISTOR_H_INCLUDED_

#include <string> // required for std::string

class CResistor
{
public:
	double getNominal(bool fnStatus);
	void setNominal(double edit, bool fnStatus);

	// string getResName(bool fnStatus);
	std::string getResName(bool fnStatus);

	// void setResName(string resName);
        void setResName( std::string resName );

	double getTolerance(bool fnStatus);
	void setTolerance(double edit, bool fnStatus);
	void setBool(bool fnStatus);

	// CResistor(double resNom, double resTol, string resName, bool fnStatus);
        CResistor( double resNom, double resTol, std::string resName, bool fnStatus );

private:
	double resNom;
	double resTol;
	
        // string resName;
        std::string resName ;

	bool fnStatus;
	
};

#endif // CRESISTOR_H_INCLUDED_ 


And Source.cpp: see http://www.stroustrup.com/bs_faq2.html#void-main
JLBorges, thank you so much for your help. Did the last bit of your comment cut off?

So, my problem here was the inclusion of std:: before the string variables? So I can understand, what did the inclusion of:

#ifndef CRESISTOR_H_INCLUDED_
#define CRESISTOR_H_INCLUDED_
#endif // CRESISTOR_H_INCLUDED_

do to solve this problem?

I'm now getting only two compile errors:

Error 1 error LNK2019: unresolved external symbol "public: __thiscall CResistor::CResistor(double,double,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" (??0CResistor@@QAE@NNV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z) referenced in function _main C:\Users\Yo\Documents\Visual Studio 2013\Projects\ResistorProgram\ResistorProgram\ResistorSource.obj ResistorProgram
Error 2 error LNK1120: 1 unresolved externals C:\Users\Yo\Documents\Visual Studio 2013\Projects\ResistorProgram\Debug\ResistorProgram.exe ResistorProgram
Last edited on
> So, my problem here was the inclusion of std:: before the string variables?

Also, you didn't have #include <string> in the header


> So I can understand, what did the inclusion of:
> #ifndef CRESISTOR_H_INCLUDED_
> ... do ...

Repeat: see: http://en.wikipedia.org/wiki/Include_guard


> I'm now getting only two compile errors:

You are getting a linker error.
You need to define the constructor for CResistor. ie. define
CResistor::CResistor(double resNom, double resTol, string resName, bool fnStatus) in Resistor.cpp
That fixed it! I now have a fully-functional program. Thanks for all your help, JLBorges! Much appreciated!
Topic archived. No new replies allowed.