So much "identifier is undefined" in my class

I'm getting a lot of these "identifier is undefined" error messages with my class. With no clue on how to solve it im trying to work around it and that has left me frustrated. Can someone enlighten me on what went wrong?

Header.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
 #include <iostream>
#include <string>
#include <fstream>


using namespace std;

class password{

	int actualListSize = 0;
	char againAgain = 'y';
	const int MAXPASSWORD = 4000;
	string userpassword;
	string *passarray = new string[MAXPASSWORD];

	public:
	void bubblesort();
	void beginprogram();
	bool exactMatch(string key);
	bool searchspace(string key);
	bool searchlength(string key);
	bool searchuppercase(string key);
	bool searchnumber(string key);
	bool searchspecial(string key);
	bool searchWRONGspecial(string key);
	bool strengthBoosterNumOrder(string key);
	bool strengthBoosterPassSize18(string key);
	bool strengthBoosterPassSize12(string key);
	void setpassword(string pass);
	void strength(string key, string list[], int ghostsize);
	string getpassword();
	int getactualListSize();
	password(); 
	~password();
};


Header.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
#include <iostream>
#include <string>
#include <fstream>
#include"Header.h"


using namespace std;

void bubblesort(std::string list[], const int &size)
{
	string temp;
	int  iteration;
	int  index;
	for (iteration = 1; iteration < size; iteration++)
	{
		for (index = 0; index < size - iteration; index++)
		{
			if (list[index] > list[index + 1])
			{
				temp = list[index];
				list[index] = list[index + 1];
				list[index + 1] = temp;
			}
		}
	}
}

void beginprogram()
{
	cout << " Hello user. This is a password program that will help you come up with a"
		<< " strong non-common password."
		<< "\n Some general rules for creating a strong non-common password are: \n"
		<< " 1. No spaces.\n"
		<< " 2. At least one captial letter.\n"
		<< " 3. At least one number. \n"
		<< " 4. No other special charaters other than ! $ % or ? should be used. \n"
		<< " 5. At least 8 or more characters long. \n"
		<< "\n Let us begin. Please enter a password: ";
}

//This is the function that detects spaces in the user's
//entered password.
bool searchspace(string key)

{
	return key.find(' ') != string::npos;
}

//This is the function that checks the user's password
//to make sure it is at least eight characters or more.
bool searchlength(string key)

{
	int ans = key.length();
	if (ans >= 8)
		return true;
	else return false;
}

//This is the function that makes sure that there is at
//least one captial letter in the user's password.
bool searchuppercase(string key)

{
	return key.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") != string::npos;
}

//This is the function that looks for at least one
//numerical character in the user's password.
bool searchnumber(string key)

{
	return key.find_first_of("1234567890") != string::npos;
}

//This is the function that sends back true or false on
//whether the user's password contains one of the four
//special characters stated in the rules.
bool searchspecial(string key)

{
	return key.find_first_of("!$%?") != string::npos;
}

bool searchWRONGspecial(string key)

{
	return key.find_first_of("@#^&*()-_=+[]{}\|;:',.<>/") != string::npos;
}

bool strengthBoosterNumOrder(string key)
{
	return key.find_first_of("012" || "123" || "234" || "345" || "456" || "567" || "678" || "789" || "890") != string::npos;
}

bool strengthBoosterPassSize18(string key)
{
	int ans = key.length();
	if (ans >= 18)
		return true;
	else return false;
}

bool strengthBoosterPassSize12(string key)
{
	int ans = key.length();
	if (ans >= 12)
		return true;
	else return false;
}

//uses the binary search to find if the user password is 
//similar to the list of common passwords.
bool exactMatch(string key, string list[], int size)
{
	/*for (int j = 0; j < size; j++)
	{
		key[j] = tolower(key[j]);
	}*/

	int first = 0;
	int last = size - 1;
	int mid;

	bool found = false;

	while (first <= last&&!found)
	{
		mid = (first + last) / 2;

		if (list[mid] == key)
			found = true;
		else if (list[mid] > key)
			last = mid - 1;
		else
			first = mid + 1;
	}
	return (found);
}

/*//This function compares the user's password with the
//loaded file of common passwords.
bool SubStringSearch(std::string key, std::string list[], int size)
{
	for (int i = 0; i < size; i++)
	{
		if (key.find(list[i]) != string::npos)
			return true;
	}
	return false;
}*/

//set function for class password, sets the private password to whatever password given
void password ::setpassword(string pass)
{
	pass=userpassword;
}

//get function for class password, returns the password inputted
string password::getpassword()
{
	return userpassword;
}

int password::getactualListSize()
{
	return actualListSize;
}


//this determines whether a password is weak, strong, or between
void strength(string key, string list[], int ghostsize)
{

	int strength = 0;
	bool ematch = exactMatch(key, list, ghostsize);
	bool sspace = !searchspace(key);
	bool slength = !searchlength(key);
	bool supcase = !searchuppercase(key);
	bool snum = !searchnumber(key);
	bool sspecial = !searchspecial(key);
	bool swspecial = !searchWRONGspecial(key);
	bool sbnumorder = !strengthBoosterNumOrder(key);
	bool sbps18 = strengthBoosterPassSize18(key);
	bool sbps12 = strengthBoosterPassSize12(key);

	if (ematch) 
	{ 
		strength++; 
		cout << "/n It's best not to use complete words."; 
	}

	if (sspace) 
	{ 
		strength++; 
		cout << "/n No spaces."; 
	}

	if (slength) 
	{ 
		strength++; 
		cout << "/n Password should be at least eight characters long."; 
	}
	if (supcase) 
	{ 
		strength++;
		cout << "/nbPassword should have at least one uppercase letter.";
	}
	if (snum) 
	{ 
		strength++; 
		cout << "/n Password should have at least one number."; 
	}
	if (sspecial) 
	{ 
		strength++; 
		cout << "/n ! $ % or ? should be used."; 
	}
	if (swspecial)
	{ 
		strength++; 
		cout << "/n No other special charaters other than ! $ % or ? should be used."; 
	}
	if (sbnumorder) { strength++; }
	if (sbps18) { strength++; }
	if (sbps12) { strength++; }

	if (strength > 7)
	{
		cout << "/n Exceeds requirements. Strong Password.";
	}
	if (strength == 7)
	{
		cout << "/n Minimum requirements met. Looks good.";
	}
	if (strength < 7)
	{
		cout << "/n Below minimum requirements. Weak password.";
	}
		
}

//constructor for class password, opening file and reading into array also counting how many were read
password::password()
{
	std::ifstream passWordFile;
	passWordFile.open("passwords.txt");

	if (!passWordFile)
	{
		std::cout << "Error!";
		exit(1);
	}

	while (!passWordFile.eof()) 
	{
		passWordFile >> passarray[actualListSize++];
		//ActualListSize++;
	}

	bubblesort();
}

//copy constructor
password::password(const password& passwordcopy)
{
	actualListSize = passwordcopy.actualListSize;
	passarray = new string[MAXPASSWORD];

	for (int k = 0; k < actualListSize; k++)
	{
		passarray[k]= passwordcopy.passarray[k];
	}
}

//deconstructor for class password
password::~password()
{
	delete[] passarray;
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
#include<string>
#include"Header.h"

using namespace std;
int main()
{
	password usersFirstPassword;
	string pass;
	beginprogram();
	getline(cin, pass);
	cout << endl << endl;
	strength();

	return 0;
}
Last edited on
header.h lines 10,11,14: You can't initialize non-const variables in a class declaration. That's what the constructor is for.

header.cpp line 88: Special characters such as \ must be escaped with a \.

header.cpp line 265: You're defining a copy constructor, but you have no declaration for a copy constructor.

main.cpp line 13: strength is declared to take 3 arguments.
Last edited on
Edited, but errors continue. In the header.cpp and main.cpp is were the error occurs an example of what I tried to do but received an error that passarray and actualListSize are undefined:

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
bool exactMatch(string key)
{
	/*for (int j = 0; j < actualListSize; j++)
	{
		key[j] = tolower(key[j]);
	}*/

	int first = 0;
	int last = actualListSize - 1;
	int mid;

	bool found = false;

	while (first <= last&&!found)
	{
		mid = (first + last) / 2;

		if (passarray[mid] == key)
			found = true;
		else if (passarray[mid] > key)
			last = mid - 1;
		else
			first = mid + 1;
	}
	return (found);
}
The definition of exactMatch isn't a member of password (you forgot to put "password::")
The same with all your other member functions (besides the constructors and destructor)
Wow I forgot about that. Unfortunately the errors aren't all gone. Not sure what else I am forgetting. The error shows up in what I bolded in the header.cpp code below.

Header.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
#include <iostream>
#include <string>
#include <fstream>
#include"Header.h"


using namespace std;

void password::bubblesort()
{
	string temp;
	int  iteration;
	int  index;
	for (iteration = 1; iteration < actualListSize; iteration++)
	{
		for (index = 0; index < actualListSize - iteration; index++)
		{
			if (passarray[index] > passarray[index + 1])
			{
				temp = passarray[index];
				passarray[index] = passarray[index + 1];
				passarray[index + 1] = temp;
			}
		}
	}
}

void password::beginprogram()
{
	cout << " Hello user. This is a password program that will help you come up with a"
		<< " strong non-common password."
		<< "\n Some general rules for creating a strong non-common password are: \n"
		<< " 1. No spaces.\n"
		<< " 2. At least one captial letter.\n"
		<< " 3. At least one number. \n"
		<< " 4. No other special charaters other than ! $ % or ? should be used. \n"
		<< " 5. At least 8 or more characters long. \n"
		<< "\n Let us begin. Please enter a password: ";
}

//This is the function that detects spaces in the user's
//entered password.
bool password::searchspace(string key)

{
	return key.find(' ') != string::npos;
}

//This is the function that checks the user's password
//to make sure it is at least eight characters or more.
bool password::searchlength(string key)

{
	int ans = key.length();
	if (ans >= 8)
		return true;
	else return false;
}

//This is the function that makes sure that there is at
//least one captial letter in the user's password.
bool password::searchuppercase(string key)

{
	return key.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") != string::npos;
}

//This is the function that looks for at least one
//numerical character in the user's password.
bool password::searchnumber(string key)

{
	return key.find_first_of("1234567890") != string::npos;
}

//This is the function that sends back true or false on
//whether the user's password contains one of the four
//special characters stated in the rules.
bool password::searchspecial(string key)

{
	return key.find_first_of("!$%?") != string::npos;
}

bool password::searchWRONGspecial(string key)

{
	return key.find_first_of("@#^&*()-_=+[]{}\.|;:',.<>/") != string::npos;
}

bool password::strengthBoosterNumOrder(string key)
{
	return key.find_first_of("012" || "123" || "234" || "345" || "456" || "567" || "678" || "789" || "890") != string::npos;
}

bool password::strengthBoosterPassSize18(string key)
{
	int ans = key.length();
	if (ans >= 18)
		return true;
	else return false;
}

bool password::strengthBoosterPassSize12(string key)
{
	int ans = key.length();
	if (ans >= 12)
		return true;
	else return false;
}

//uses the binary search to find if the user password is 
//similar to the list of common passwords.
bool password::exactMatch(string key)
{
	/*for (int j = 0; j < size; j++)
	{
		key[j] = tolower(key[j]);
	}*/

	int first = 0;
	int last = actualListSize - 1;
	int mid;

	bool found = false;

	while (first <= last&&!found)
	{
		mid = (first + last) / 2;

		if (passarray[mid] == key)
			found = true;
		else if (passarray[mid] > key)
			last = mid - 1;
		else
			first = mid + 1;
	}
	return (found);
}

/*//This function compares the user's password with the
//loaded file of common passwords.
bool SubStringSearch(std::string key, std::string list[], int size)
{
	for (int i = 0; i < size; i++)
	{
		if (key.find(list[i]) != string::npos)
			return true;
	}
	return false;
}*/

//set function for class password, sets the private password to whatever password given
void password ::setpassword(string pass)
{
	pass=userpassword;
}

//get function for class password, returns the password inputted
string password::getpassword()
{
	return userpassword;
}

int password::getactualListSize()
{
	return actualListSize;
}


//this determines whether a password is weak, strong, or between
void strength(string key)
{

	int strength = 0;
	bool ematch = exactMatch(key);
	bool sspace = searchspace(key);
	bool slength = !searchlength(key);
	bool supcase = !searchuppercase(key);
	bool snum = !searchnumber(key);
	bool sspecial = !searchspecial(key);
	bool swspecial = !searchWRONGspecial(key);
	bool sbnumorder = !strengthBoosterNumOrder(key);
	bool sbps18 = strengthBoosterPassSize18(key);
	bool sbps12 = strengthBoosterPassSize12(key);

	if (ematch) 
	{ 
		strength++; 
		cout << "/n It's best not to use complete words."; 
	}

	if (sspace) 
	{ 
		strength++; 
		cout << "/n No spaces."; 
	}

	if (slength) 
	{ 
		strength++; 
		cout << "/n Password should be at least eight characters long."; 
	}
	if (supcase) 
	{ 
		strength++;
		cout << "/nbPassword should have at least one uppercase letter.";
	}
	if (snum) 
	{ 
		strength++; 
		cout << "/n Password should have at least one number."; 
	}
	if (sspecial) 
	{ 
		strength++; 
		cout << "/n ! $ % or ? should be used."; 
	}
	if (swspecial)
	{ 
		strength++; 
		cout << "/n No other special charaters other than ! $ % or ? should be used."; 
	}
	if (sbnumorder) { strength++; }
	if (sbps18) { strength++; }
	if (sbps12) { strength++; }

	if (strength > 7)
	{
		cout << "/n Exceeds requirements. Strong Password.";
	}
	if (strength == 7)
	{
		cout << "/n Minimum requirements met. Looks good.";
	}
	if (strength < 7)
	{
		cout << "/n Below minimum requirements. Weak password.";
	}
		
}

//constructor for class password, opening file and reading into array also counting how many were read
password::password()
{
	std::ifstream passWordFile;
	passWordFile.open("passwords.txt");

	if (!passWordFile)
	{
		std::cout << "Error!";
		exit(1);
	}

	while (!passWordFile.eof()) 
	{
		passWordFile >> passarray[actualListSize++];
		//ActualListSize++;
	}

	bubblesort();

	actualListSize = 0;
	againAgain = 'y';
	passarray = new string[MAXPASSWORD];
}

//copy constructor
password::password(const password& passwordcopy)
{
	actualListSize = passwordcopy.actualListSize;
	passarray = new string[MAXPASSWORD];

	for (int k = 0; k < actualListSize; k++)
	{
		passarray[k]= passwordcopy.passarray[k];
	}
}

//deconstructor for class password
password::~password()
{
	delete[] passarray;
}


Header.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
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

class password{

	int actualListSize;
	char againAgain;
	const int MAXPASSWORD = 4000;
	string userpassword;
	string *passarray;

	public:
	void bubblesort();
	void beginprogram();
	bool exactMatch(string);
	bool searchspace(string);
	bool searchlength(string);
	bool searchuppercase(string);
	bool searchnumber(string);
	bool searchspecial(string);
	bool searchWRONGspecial(string);
	bool strengthBoosterNumOrder(string);
	bool strengthBoosterPassSize18(string);
	bool strengthBoosterPassSize12(string);
	void setpassword(string);
	void strength(string);
	string getpassword();
	int getactualListSize();
	password(); 
	password(const password& passwordcopy);
	~password();
};
anyone?
header.h line 11: should be declared static

header.cpp line 88: You didn't escape the \ as previously pointed out.
 
return key.find_first_of("@#^&*()-_=+[]{}\\.|;:',.<>/") != string::npos;

Note the double \.

header.cpp line 93: That's not going to work the you think it will. You're passing a boolean expression (the result of multiple or conditions) to find_find_of. find_first_of requires a string, not a bool expression.

header.cpp lines 176-186: You're attempting to call members of your class, but you're not naming an instance. strength is declared to be a member of your class, but you haven't included the password:: scope on your function definition.

header.cpp line 258: You reading passwords into an unallocated array. You don't allocate the array until line 266.

main.cpp line 10: beginprogram is a member of your class. you must invoke it though a specific instance.
 
  usersFirstPassword.beginprogram();







Last edited on
Sorry about line 88, not sure why it showed double \ when i copied and paste straight from my complier with only one \.

Can you explain why line 11 should be declared as static? I just want to understand which would help me not make this mistake in future projects.

Would a binary search work better, since im looking for an order group of numbers? or Do you have something else in mind for line 93?

Can't believe it was as simple as not including the password:: scope again for lines 176-185.

Whoa, you saved me there (line 258, 266).

Ahh yes, (main.cpp line 10) I'm not sure why I keep forgetting these rules when it comes to classes.
Line 11: static says there is only one instance of the variable across all instances of the class. static is not required in C++11.

Line 93: I didn't have anything specific in mind. Probably just a simple table of non-allowed sequences and use find_first_of against each entry of the non-allowed table.

ah okay.

Line 93; table? I don't think we learn anything about tables. Can you explain this?
Last edited on
Table is just another name for an array.

1
2
3
4
5
6
7
8
const int num_not_allowed = 9;
const string not_allowed[num_not_allowed] = { "012" , "123" , "234" , "345" , "456" , "567" , "678" , "789" , "890" };

  for (int i=0; i<num_not_allowed; i++)
    if (key.find_first_of (not_allowed[i]) != string::npos)
      return true;  // not allowed 
  return false;  // no match found
}



/Sigh
Program crashes now.

Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<string>
#include<windows.h>
#include"Header.h"

using namespace std;
int main()
{
	/*cout << " Program is loading, please wait...";
	Sleep(5000);
	cout << "\n This may take some time...";
	Sleep(3000);
	cout << "\n 50%";*/
	password usersFirstPassword;
	/*cout << "\n 100%";
	Sleep(3000);
	cout << "\n Starting...";
	Sleep(4000);*/
	usersFirstPassword.beginprogram();
	return 0;
}


Header.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<string>
#include<fstream>

using namespace std;

class password{
	//everything here is private until stated public...

	//declaring variables to be used in class member functions, go figure
	int actualListSize;
	char againAgain;
	const static int MAXPASSWORD = 4000;
	string userpassword;
	string *passarray;
	int pstrength;

	//these variables are used to check user's response and whatnot
	const static int max4txt = 100;
	int txt1size;
	int txt2size;
	string *acceptance;
	string *nogo;
	string userchoice;

	public://stated public :P
	void bubblesort();
	void bubblesort2();
	void bubblesort3();
	void beginprogram();
	void password::beginprogramagain();
	bool exactMatch();
	bool exactMatch2();
	bool exactMatch3();
	bool searchspace();
	bool searchlength();
	bool searchuppercase();
	bool searchnumber();
	bool searchspecial();
	bool searchWRONGspecial();
	bool strengthBoosterNumOrder();
	bool strengthBoosterPassSize18();
	bool strengthBoosterPassSize12();
	void setpassword(string);
	void strength();
	string getpassword();
	//int getactualListSize();
	void tryagain();
	bool password::tryagaincheck();
	password(); 
	password(const password& passwordcopy);
	~password();
};


Header.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
#include<iostream>
#include<string>
#include<fstream>
#include<windows.h>
#include"Header.h"
#include"Clear.h"

using namespace std;

//sorts the array to enable it to be searched with the binary search
void password::bubblesort()
{
	string temp;
	int  iteration;
	int  index;
	for (iteration = 1; iteration < actualListSize; iteration++)
	{
		for (index = 0; index < actualListSize - iteration; index++)
		{
			if (passarray[index] > passarray[index + 1])
			{
				temp = passarray[index];
				passarray[index] = passarray[index + 1];
				passarray[index + 1] = temp;
			}
		}
	}
}

void password::bubblesort2()
{
	string temp;
	int  iteration;
	int  index;
	for (iteration = 1; iteration < txt1size; iteration++)
	{
		for (index = 0; index < txt1size - iteration; index++)
		{
			if (acceptance[index] > acceptance[index + 1])
			{
				temp = acceptance[index];
				acceptance[index] = acceptance[index + 1];
				acceptance[index + 1] = temp;
			}
		}
	}
}

void password::bubblesort3()
{
	string temp;
	int  iteration;
	int  index;
	for (iteration = 1; iteration < txt2size; iteration++)
	{
		for (index = 0; index < txt2size - iteration; index++)
		{
			if (nogo[index] > nogo[index + 1])
			{
				temp = nogo[index];
				nogo[index] = nogo[index + 1];
				nogo[index + 1] = temp;
			}
		}
	}
}

//the member function that starts all this madness
void password::beginprogram()
{
	ClearScreen();
	cout<< " Hello user. This is a password program that will help you come up with a"
		<< " strong non-common password."
		<< "\n Some general rules for creating a strong non-common password are: \n"
		<< " 1. No spaces.\n"
		<< " 2. At least one captial letter.\n"
		<< " 3. At least one number. \n"
		<< " 4. No other special charaters other than ! $ % or ? should be used. \n"
		<< " 5. At least 8 or more characters long. \n"
		<< "\n Let us begin. Please enter a password: ";
	getline(cin, userpassword);
	cout<< endl
		<< "--------------------------------------------------------------------------------";
	strength();
	return;
}

//the member function that continues all this madness
void password::beginprogramagain()
{
	ClearScreen();
	cout<< endl
		<< "--------------------------------------------------------------------------------"
		<< "\n To reiterate..."
		<< "\n Some general rules for creating a strong non-common password are: \n"
		<< " 1. No spaces.\n"
		<< " 2. At least one captial letter.\n"
		<< " 3. At least one number. \n"
		<< " 4. No other special charaters other than ! $ % or ? should be used. \n"
		<< " 5. At least 8 or more characters long. \n"
		<< "\n Let us begin, again. Please enter a password: ";
	getline(cin, userpassword);
	strength();
	return;
}

//This is the function that detects spaces in the user's
//entered password.
bool password::searchspace()

{
	return userpassword.find(' ') != string::npos;
}

//This is the function that checks the user's password
//to make sure it is at least eight characters or more.
bool password::searchlength()

{
	int ans = userpassword.length();
	if (ans >= 8)
		return true;
	else return false;
}

//This is the function that makes sure that there is at
//least one captial letter in the user's password.
bool password::searchuppercase()

{
	return userpassword.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") != string::npos;
}

//This is the function that looks for at least one
//numerical character in the user's password.
bool password::searchnumber()

{
	return userpassword.find_first_of("1234567890") != string::npos;
}

//This is the function that sends back true or false on
//whether the user's password contains one of the four
//special characters stated in the rules.
bool password::searchspecial()

{
	return userpassword.find_first_of("!$%?") != string::npos;
}

bool password::searchWRONGspecial()

{
	return userpassword.find_first_of("@#^&*()-_=+[]{}|;:',<>/\\.") != string::npos;
}

bool password::strengthBoosterNumOrder()
{
	const int num_not_allowed = 9;
	const string not_allowed[num_not_allowed] = { "012", "123", "234", "345", "456", "567", "678", "789", "890" };

	for (int i = 0; i<num_not_allowed; i++)
	if (userpassword.find_first_of(not_allowed[i]) != string::npos)
		return true;  // not allowed 
	return false;  // no match found
}

bool password::strengthBoosterPassSize18()
{
	int ans = userpassword.length();
	if (ans >= 18)
		return true;
	else return false;
}

bool password::strengthBoosterPassSize12()
{
	int ans = userpassword.length();
	if (ans >= 12)
		return true;
	else return false;
}

//uses the binary search to find if the user password is 
//similar to the list of common passwords.
bool password::exactMatch()
{
	/*for (int j = 0; j < size; j++)
	{
		key[j] = tolower(key[j]);
	}*/

	int first = 0;
	int last = actualListSize - 1;
	int mid;

	bool found = false;

	while (first <= last&&!found)
	{
		mid = (first + last) / 2;

		if (passarray[mid] == userpassword)
			found = true;
		else if (passarray[mid] > userpassword)
			last = mid - 1;
		else
			first = mid + 1;
	}
	return (found);
}

bool password::exactMatch2()
{
	/*for (int j = 0; j < size; j++)
	{
	key[j] = tolower(key[j]);
	}*/

	int first = 0;
	int last = txt1size - 1;
	int mid;

	bool found = false;

	while (first <= last&&!found)
	{
		mid = (first + last) / 2;

		if (acceptance[mid] == userchoice)
			found = true;
		else if (acceptance[mid] > userchoice)
			last = mid - 1;
		else
			first = mid + 1;
	}
	return (found);
}

bool password::exactMatch3()
{
	/*for (int j = 0; j < size; j++)
	{
	key[j] = tolower(key[j]);
	}*/

	int first = 0;
	int last = txt2size - 1;
	int mid;

	bool found = false;

	while (first <= last&&!found)
	{
		mid = (first + last) / 2;

		if (nogo[mid] == userchoice)
			found = true;
		else if (nogo[mid] > userchoice)
			last = mid - 1;
		else
			first = mid + 1;
	}
	return (found);
}

void password ::setpassword(string key)
{
	key=userpassword;
}

//get function for class password, returns the password inputted
string password::getpassword()
{
	return userpassword;
}
Last edited on
other half of Header.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
//this determines whether a password is weak, strong, or between
void password::strength()
{

	pstrength = 7;
	bool ematch = exactMatch();
	bool sspace = searchspace();
	bool slength = searchlength();
	bool supcase = searchuppercase();
	bool snum = searchnumber();
	bool sspecial = searchspecial();
	bool swspecial = searchWRONGspecial();
	bool sbnumorder = strengthBoosterNumOrder();
	bool sbps18 = strengthBoosterPassSize18();
	bool sbps12 = strengthBoosterPassSize12();

	cout << "\n FOR THE PASSWORD: " << userpassword << "- \n";

	if (ematch) 
	{ 
		pstrength--; 
		cout << "\n It's best not to use complete words."; 
	}

	if (sspace) 
	{ 
		pstrength--; 
		cout << "\n No spaces."; 
	}

	if (slength==false) 
	{ 
		pstrength--; 
		cout << "\n Password should be at least eight characters long."; 
	}
	if (supcase==false) 
	{ 
		pstrength--;
		cout << "\n Password should have at least one uppercase letter.";
	}
	if (snum==false) 
	{ 
		pstrength--; 
		cout << "\n Password should have at least one number."; 
	}
	if (sspecial==false) 
	{ 
		pstrength--; 
		cout << "\n ! $ % or ? should be used."; 
	}
	if (swspecial)
	{ 
		pstrength--; 
		cout << "\n No other special charaters other than ! $ % or ? should be used."; 
	}
	if (sbnumorder == false) { pstrength++; }
	if (sbps18) { pstrength++; }
	if (sbps12) { pstrength++; }

	tryagain();
	return;
}

//somewhat of the last step
//ask user if they would like to make another password
//forces user to make another password if the minimum requirements were not met
//when given a choice, the user can input any form of the way "yes" or "no"
//if their form of the way "yes" or "no" is not recognizable they will have to 
//input again. 
//when the user says "no" the member function will return the program to main
//where return 0 is waiting to end the program
void password::tryagain()
{
	bool goagain;
	if (pstrength > 8)
	{
		cout<< "\n\n Your password exceeds requirements. It's a strong Password."
			<< "\n Would you like to make another? \n\n ";
		getline(cin,userchoice);
		goagain = tryagaincheck();
		if (goagain) { beginprogramagain(); }
	}
	if (pstrength >= 7)
	{
		cout<< "\n\n Your password meets the minimum requirements. Looks good."
			<< "\n Would you like to try and make a stronger password? \n\n ";
		getline(cin, userchoice);
		goagain = tryagaincheck();
		if (goagain) { beginprogramagain(); }
	}
	if (pstrength < 7)
	{
		cout<< "\n\n Your password fails to meet the minimum requirements." 
			<<"\n It's a pretty weak password. Try again. \n ";
		//Sleep(5000);
		beginprogramagain();
	}

	return;
}

//when called compares and checks user choice to answers in text
//when yes is found goagain will be true so "yes go again"
//when no is found go again will be false so "go again? no!"
//if yes and no are not found, it will invoke tryagaincheck2
//to repeat a similar function until users input is recognizable
bool password::tryagaincheck()
{
	bool run1 = exactMatch2();
	bool run2 = exactMatch3();

	while (run1&&run2==false)
		{
			cout << "\n\n Did not recognize your answer, try again.";
			getline(cin, userchoice);
			run1 = exactMatch2();
			run2 = exactMatch3();
		}

	bool run3;
	if (run1) { run3=true; };
	if (run2) { run3=false; };
	return run3;
}

//constructor for class password, opening file and reading into array also counting how many were read
password::password()
{
	//initializing varibles
	actualListSize = 0;
	againAgain = 'y';
	passarray = new string[MAXPASSWORD];

	//opening and reading in txt file
	std::ifstream passWordFile;
	passWordFile.open("passwords.txt");

	if (!passWordFile)
	{
		std::cout << "Error!";
		exit(1);
	}

	while (!passWordFile.eof()) 
	{
		passWordFile >> passarray[actualListSize++];
		//ActualListSize++;
	}

	passWordFile.close(); //closing txt file to open more
	bubblesort(); //sorting read in file to be able to use binary search on it

	//initializing varibles for the tryagain function
	txt1size = 0;
	txt2size = 0;
	acceptance = new string[max4txt];
	nogo = new string[max4txt];

	//reading in "yes" options into an array
	std::ifstream acceptanceFile;
	acceptanceFile.open("acceptance.txt");

	if (!acceptanceFile)
	{
		std::cout << "Error!";
		exit(1);
	}

	while (!acceptanceFile.eof())
	{
		acceptanceFile >> acceptance[txt1size++];
		//txt1size++;
	}

	acceptanceFile.close();
	bubblesort2();

	//reading in "no" options into an array
	std::ifstream nogoFile;
	nogoFile.open("nogo.txt");

	if (!nogoFile)
	{
		std::cout << "Error!";
		exit(1);
	}

	while (!nogoFile.eof())
	{
		nogoFile >> passarray[txt2size++];
		//txt2size++;
	}

	nogoFile.close();
	bubblesort3();
}

//copy constructor
password::password(const password& passwordcopy)
{
	actualListSize = passwordcopy.actualListSize;
	passarray = new string[MAXPASSWORD];

	for (int k = 0; k < actualListSize; k++)
	{
		passarray[k]= passwordcopy.passarray[k];
	}
}

//deconstructor for class password
password::~password()
{
	delete[] passarray;
}
Your program compiles cleanly. I can't offer any more help since I don't have the data files that your program opens. I suggest you step through your program with a debugger.


hello I need help
I'm trying to do simple calc but I'm faling with all my tryings:

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
float firstnum, secondnum, result;
char sign;
while(true)
{
cout << "first number:\n";
cin >> firstnum;
cout << "What do yo want to do: * / + - ^\n";
cin >> sign;
cout << "second number:\n";
cin >> secondnum;
if(sign == '*')
{
cout << "the result is:" << firstnum * secondnum << "\n\n";
}
if(sign == '+')
{
cout << "the result is:" << firstnum + secondnum << "\n\n";
}
if(sign == '-')
{
cout << "the result is:" << firstnum - secondnum << "\n\n";
}
if(sign == '/')
{
if(secondnum == 0)
{
cout << "invalid denominator" << "\n\n";
}
else
{
cout << "the result is:" << firstnum / secondnum << "\n\n";
}
}
if(sign == '^')
{
result == pow((float) firstnum, secondnum);
cout << result << "\n\n";
}
}
return 0;
}

this is my code (C++code blocks compiler)
and this is the error:
undefined reference to `pow(double, double)'

HELP!!! Thank you!
@nanyo - Please don't post multiple times and do not post in other people's threads.
Topic archived. No new replies allowed.