hey everyone
ok so i have reached another road block any pointers are much appreciated the program will not compile due to eclipse not liking the
int Password::passwordNumber(int i);
int Password::passwordCapLetter(int i);
in the .h
any ideas

demp.cpp

/* File Name: Demo.cpp
 Chapter No. 12 - Exercise No. 12
 Programmer:         Carl Sue
 Date Last Modified: Mar 9, 2010
 
 Problem Statement: (what you want the code to do)
 Imagine you are developing a software package that requires users to
 enter their own passwords. Your software requires that user’s
 passwords meet the following criteria:
	The password should be at least six characters long.
	The password should contain at least one upper-case and at least
		 one lower-case letter.
	The password should have at least one digit.
 Write a program that asks for a password and then verifies that
 it meets the stated criteria. If it doesn’t, the program should
 display a message telling the user why.

 
 
 Classes needed and Purpose (Input, Processing, Output):
 
 
 */

#include <iostream>
#include "Password.h"
using namespace std;

int main(int argc, char * const argv[]){
	string pass;
	cout << "enter a password: ";
	cin >> pass;
	if (pass.length() < 6) {
		cout << "password must be longer than 6 characters. ";
	} else {
		Password passwd(pass);
		passwd.passwordCapLetter(pass.length());
		passwd.passwordNumber(pass.length());
	}

	return 0;
}

password.cpp

/*
 * Password.cpp
 *
 *  Created on: Mar 9, 2010
 *      Author: Carl
 */

#include "Password.h"

Password::Password() {
	// TODO Auto-generated constructor stub

}

Password::Password(string s){
	password = s;
	flag1 = false;
	flag2 = false;
}

Password::~Password() {
	// TODO Auto-generated destructor stub
}

int Password::passwordNumber(int i){
	if (i > 0) {
			if (password[i] >= 48 && password[i] <= 57) {
				flag3 = true;
			}
			return passwordNumber(i-1);
		} else {
			if (flag3 == true) {
				cout << "your password needs a capital letter";
			}
		}
}


int Password::passwordCapLetter(int i){
	if (i > 0) {
		if (password[i] >= 65 && password[i] <= 90) {
			flag1 = true;
		}
		if (password[i] >= 97 && password[i] <= 122) {
					flag2 = true;
				}
		return passwordCapLetter(i-1);
	} else {
		if (flag1 == true) {
			cout << "your password needs a capital letter";
		}
	}
}

password.h

/*
 * Password.h
 *
 *  Created on: Mar 9, 2010
 *      Author: Carl
 */

#ifndef PASSWORD_H_
#define PASSWORD_H_
#include <iostream>
using namespace std;
class Password {
public:
	Password();
	Password(string);
	virtual ~Password();
	int Password::passwordNumber(int i);
	int Password::passwordCapLetter(int i);
private:
	static string password;
	static bool flag1, flag2, flag3;
};

#endif /* PASSWORD_H_ */

again thanks for any help

Recommended Answers

All 8 Replies

Lines 17 and 18 of password.h do not need the Password:: qualifier. Since they are being declared within the class it is assumed just like it is for the constructor/destructor.

Lines 17 and 18 of password.h do not need the Password:: qualifier. Since they are being declared within the class it is assumed just like it is for the constructor/destructor.

in that case when would i need the ClassName::Function syntax

also when i take out the Password:: the compiler throws an error when trying to access class variables.

in that case when would i need the ClassName::Function syntax

In the implementation file when you write the method definitions like you have it in Password.cpp.

also when i take out the Password:: the compiler throws an error when trying to access class variables.

I get at least a warning for having them in there in Password.h You don't need them there.

A couple of problems: Some of the paths of passwordCapLetter and passwordNumber do not return anything. Even if there's an error your function should still return something (say -999) which you can check for in the calling function.

Also, you have static variables declared in the Password.h file but never defined anywhere. You should define them in Password.cpp as string Password::password=""; etc.

thanks so much for the help ill be back in the morning after I've fixed it getting a little late to go on when wife wants me in bed again thanks see you all in the morning. also I am banging by head on the desk for not remembering to add a return for recursive base case.

Made the changes to the .h and added the return however for some reason the compiler is throwing a cannot find symbol(s) error on no pages, anyone using eclipse CDT have any ideas, i think thats whats causing the errors

It's still probably your static variables. They need to be initialized in your .cpp file and not just declared in the .h. Otherwise repost your code.

should be initialized in constructor

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.