Pointers help

Hi fellow programmers. Here is my program thus far...
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
#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(Resistor &, bool );
void EnterResistance(Resistor &, bool);


void main(void)
{
string name;
Resistor * resPtr[3];

for(int i = 0; i < 3; i++)
{
resPtr[i] = new Resistor();
EnterResistance(resPtr[i]);
}
   for(int j=0; j<3; j++)
	{
    DisplayResistance(resPtr[j]);
	}
		for(int i=0; i<3, i++;)
		{
		delete resPtr[i];
		}
system("pause");
}

// Function displays all data member values of a Resistor object
void DisplayResistance(Resistor*)
{
	//Local variables to hold Resistor data copies
	double nom, tol, min, max;
	nom = resObj.getNom();
	tol = resObj.getTol();
	min = nom * (1.0 - tol);
	max = nom * (1.0 + tol);
	cout << endl << "Resistor object name is " << resObj.getName() << 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 Resistor data members
void EnterResistance(Resistor*)
{
	//Local variables to hold Resistor 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.getNom();
	tol = resObj.getTol();
	name = resObj.getName();
	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.setTol((double)tolEdit*0.01);

	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.setNom((double)nomEdit * pow(10.0,(double)powerOfTen));
}


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
//Resistor.h
#ifndef resistor_H
#define resistor_H
#include <string>
using namespace std;

class Resistor //Names the class "Resistor".
{ 
private:
double nomVal; 
double tolVal;
string ResistorName;

 
public: //Getter and setter functions.
Resistor(); //Constructor 1
Resistor(double nom, double tol, string name); //Constructor 2
~Resistor(); //Destructor
void setNom(double n); 
double getNom(); 
void setTol(double t); 
double getTol();
void setName(string nm);
string getName ();

};
#endif  


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
//Resistor.cpp
#include "Resistor.h"
#include <iostream>
#include <string>
using namespace std;

//Constructor
Resistor::Resistor()
{
	nomVal = 0;
	tolVal = 0;
}
Resistor::Resistor(double nom, double tol, string name)
{
	nomVal = nom;
	tolVal = tol;
	ResistorName = name;
}

 //Functions
void Resistor::setNom(double nom)
 {
 nomVal=nom;
 }
 double Resistor::getNom(void)
 {
     return nomVal;
 }
 void Resistor::setTol(double tol)
 {
     tolVal=tol;
 }
 double Resistor::getTol(void)
 {
     return tolVal;
 } 
 void Resistor::setName(string nm)
 {
     ResistorName=nm;
 }
 string Resistor::getName(void)
 {
     return ResistorName;
 }
Resistor::~Resistor() //Implementation of destructor from class.
{}
Last edited on
Here are the output errors that I'm getting.
1>------ Build started: Project: wk 5, Configuration: Debug Win32 ------
1>Build started 2/21/2013 12:06:27 AM.
1>InitializeBuildStatus:
1>  Touching "Debug\wk 5.unsuccessfulbuild".
1>ClCompile:
1>  ResistorMain.cpp
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(67): error C2660: 'EnterResistance' : function does not take 1 arguments
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(71): error C2660: 'DisplayResistance' : function does not take 1 arguments
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(85): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(85): error C2228: left of '.getNom' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(86): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(86): error C2228: left of '.getTol' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(89): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(89): error C2228: left of '.getName' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(117): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(117): error C2228: left of '.getNom' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(118): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(118): error C2228: left of '.getTol' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(119): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(119): error C2228: left of '.getName' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(134): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(134): error C2228: left of '.setTol' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(245): error C2065: 'resObj' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(245): error C2228: left of '.setNom' must have class/struct/union
1>          type is ''unknown-type''
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.65
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


What the heck is a class/struct/union!?
use resPtr instead of resObj..
Last edited on
Ok I changed all the 'resObj' to 'resPtr' however I am still getting the same output errors...

1>------ Build started: Project: wk 5, Configuration: Debug Win32 ------
1>Build started 2/21/2013 1:11:29 AM.
1>InitializeBuildStatus:
1>  Touching "Debug\wk 5.unsuccessfulbuild".
1>ClCompile:
1>  ResistorMain.cpp
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(66): error C2660: 'EnterResistance' : function does not take 1 arguments
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(70): error C2660: 'DisplayResistance' : function does not take 1 arguments
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(84): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(84): error C2228: left of '.getNom' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(85): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(85): error C2228: left of '.getTol' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(88): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(88): error C2228: left of '.getName' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(116): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(116): error C2228: left of '.getNom' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(117): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(117): error C2228: left of '.getTol' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(118): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(118): error C2228: left of '.getName' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(133): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(133): error C2228: left of '.setTol' must have class/struct/union
1>          type is ''unknown-type''
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(244): error C2065: 'resPtr' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(244): error C2228: left of '.setNom' must have class/struct/union
1>          type is ''unknown-type''
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.35
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Resistor * resPtr[3]

should be declared globally..

closed account (z05DSL3A)
the first error:
1>f:\ ... \resistormain.cpp(66): error C2660: 'EnterResistance' : function does not take 1 arguments


declared as: void EnterResistance(Resistor &, bool);
defined as: void EnterResistance(Resistor*)

fix that then move on to the next error.
Ok so here is a snippet of code that I modified...

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
void DisplayResistance(Resistor*);//Changed from (Resistor &, bool) to (Resistor*)
void EnterResistance(Resistor*);//Same here


void main(void)
{

Resistor * resPtr[3];

for(int i = 0; i < 3; i++)
{
resPtr[i] = new Resistor();
EnterResistance(resPtr[i]);
}
   for(int j=0; j<3; j++)
	{
    DisplayResistance(resPtr[j]);
	}
		for(int i=0; i<3, i++;)
		{
		delete resPtr[i];
		}
system("pause");
}

// Function displays all data member values of a Resistor object
void DisplayResistance(Resistor*)
{
	//Local variables to hold Resistor data copies
	double nom, tol, min, max;
	nom = resPtr[3]*.getNom();//Modified this from resPtr[3]* but the '.' is wrong.
	tol = resPtr.getTol();
	min = nom * (1.0 - tol);
	max = nom * (1.0 + tol);
	cout << endl << "Resistor object name is " << resPtr.getName()...


Here is the output...

1>------ Build started: Project: wk 5, Configuration: Debug Win32 ------
1>Build started 2/21/2013 10:01:17 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\wk 5.unsuccessfulbuild".
1>ClCompile:
1>  ResistorMain.cpp
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(84): error C2059: syntax error : '.'
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(85): error C2228: left of '.getTol' must have class/struct/union
1>          type is 'Resistor *[3]'
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(88): error C2228: left of '.getName' must have class/struct/union
1>          type is 'Resistor *[3]'
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(116): error C2228: left of '.getNom' must have class/struct/union
1>          type is 'Resistor *[3]'
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(117): error C2228: left of '.getTol' must have class/struct/union
1>          type is 'Resistor *[3]'
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(118): error C2228: left of '.getName' must have class/struct/union
1>          type is 'Resistor *[3]'
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(133): error C2228: left of '.setTol' must have class/struct/union
1>          type is 'Resistor *[3]'
1>f:\my documents\visual studio 2010\projects\wk 5\wk 5\resistormain.cpp(244): error C2228: left of '.setNom' must have class/struct/union
1>          type is 'Resistor *[3]'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.69
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


So I know its something to do with the resPtr.ect... lines but not sure how to fix that. Can anyone help?
Last edited on
cout << "Bump" << endl; //;)
The dot operator doesn't work with pointers, so you need to use the -> operator to call the objects functions. Resobj doesn't exist anywhere not even in main, certainly not as a local variable in your function, as the compiler says.

However I think your code needs a bit of reorganising.

In the resitormain.cpp file you have all these functions to do with resistors - they should all be class functions which are called through the resistor object.

Also main always returns an int - not void.

Lines 141 to 244 would be much better written with switch statements.

Each case clause (Your else if) could call a function. Your else if blocks are all very similar, call a function that has the array & the length of it as parameters. This will avoid quite a bit of repetition in your code.


Lines 10 to 52 should be private member variables in the resistor class. Your member functions can get at them because they are in the same class.

When deleting dynamically created arrays - use the delete[] operator

HTH & good luck. :-D


Thank you guys for the help thus far... After all your help here is my complete Resistormain...

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
#include "Resistor.h"
#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <math.h>

using namespace std;
Resistor * resPtr[3];
//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(Resistor*);
void EnterResistance(Resistor*);


void main(void)
{

Resistor * resPtr[3];

for(int i = 0; i < 3; i++)
{
resPtr[i] = new Resistor();
EnterResistance(resPtr[i]);
}
   for(int j=0; j<3; j++)
	{
    DisplayResistance(resPtr[j]);
	}
		for(int i=0; i<3, i++;)
		{
		delete resPtr[i];
		}
system("pause");
}

// Function displays all data member values of a Resistor object
void DisplayResistance(Resistor*resPtr)
{
	//Local variables to hold Resistor data copies
	double nom, tol, min, max;
	nom = resPtr->getNom();//Modified this from resPtr[3]* but the '.' is wrong.
	tol = resPtr->getTol();
	min = nom * (1.0 - tol);
	max = nom * (1.0 + tol);
	cout << endl << "Resistor object name is " << resPtr->getName() << 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 Resistor data members
void EnterResistance(Resistor*resPtr)
{
	//Local variables to hold Resistor 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 = resPtr->getNom();
	tol = resPtr->getTol();
	name = resPtr->getName();
	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;
	resPtr->setTol((double)tolEdit*0.01);

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

	resPtr->setNom((double)nomEdit * pow(10.0,(double)powerOfTen));
}


I'll probably go in there and clean up some of the code in there later but for now its compiling. Now I just need to figure out how to assign my own resistor.
Topic archived. No new replies allowed.