I'm getting 3 unresolved external symbol errors. I think it's probably syntax but I can't seem to find it. This is a class I was supposed to write based on the professors specifications. The header and implementation file are mine, while the driver file cannot be edited for this assignment.

I spent an hour looking at syntax, but I can't seem to find it. Can anyone tell me? I'm also not worried about logic errors at the moment becuase I haven't got it to compile yet.
I have to leave for a while but I'll leave this on my computer for when I get back (2-3 hours).

Also, I believe in.open(FileName) won't work. (FileName is a string variable) What should I do for that.

This is the header file Password.h

#include <iostream>
#include <string>
using namespace std;

#ifndef PASSWORD
#define PASSWORD

class Password {
	private:
		string FileName, EncryptionKey, UserID;
		int EncryptedPass[5];
	public:
		void Encrypt(const string& p, int a[], const string& key);
		string Decrypt(int a[], const string& key);
		Password();
		Password(string adminPW);
		void NewPW(string adminPW, string userID, string pw, int & errorCode);
		bool VerifyPW(string adminPW, string userID, string pw, int & errorCode);
};

#endif

this is the implementation file Password.cpp

#include <fstream>
#include <cstdlib>
#include <string>
#include "Password.h"
using namespace std;

/*      Purpose: To encrypt a password.
   Precondition: The first parameter is the password to encrypt.
  Postcondition: The second parameter will be your encrypted password. */
void Password::Encrypt(const string& p, int a[], const string& key)
{	for (int i = 0; i < p.length(); i++)
		a[i] = int(p[i]) + int(key[i]);
}

/*     Purpose: To Decrypt a password.
  Precondition: The 2nd parameter must be an int array of 6.
 Postcondition: The decrypted password is returned */
string Password::Decrypt(int a[], const string& key)
{	string s;
	for (int i = 0; i < 6; i++)
		s += char(a[i] - key[i]);
	return s;
}

//Default Constructor
Password::Password()
{	FileName = "pw.txt";
	EncryptionKey = "#!2>eB";
	UserID = "petn";
	Encrypt("ADMINP", EncryptedPass, EncryptionKey);
}

//Explicit Value Constructor
Password::Password(string pw)
{	FileName = "pw.txt";
	EncryptionKey = "#!2>eB";
	UserID = "petn";
	Encrypt(pw, EncryptedPass, EncryptionKey);
}

/*      Purpose:
   Precondition:
 Postcondtition: */
void Password::NewPW(string adminPW, string userID, string pw, int & errorCode)
{	ifstream in;
	ofstream out;
	string check;
	int EuserPW[6];

	if (pw.length() == 6)
	{	errorCode = 3;
		return;
	}
	if (adminPW == Decrypt(EncryptedPass, EncryptionKey))
	{		in.open(FileName);
			if (in.fail())
			{	cerr << "ERROR!!! Input file failed to open\n.";
				exit(1);
			}
			getline(in, check);
			while(!in.eof())
			{	if (check == userID)
				{	errorCode = 2;
					return;
				}
			}
			in.close();
			out.open(FileName, ios::app);
			Encrypt(pw, EuserPW, EncryptionKey);
			out << userID << " " << EuserPW << endl;
			errorCode = 0;
			out.close();
	}
	else
		errorCode = 1;
}

/*


					*/
bool Password::VerifyPW(string adminPW, string userID, string pw, int & errorCode)
{	ifstream in;
	string NameCheck;

	if (pw.length() != 6)
	{	errorCode = 3;
		return false;
	}
	if (adminPw == Decrypt(EncryptedPass, EncryptionKey))
	{	in.open(FileName, ios::app);
		if (in.fail())
		{	cout << "Error input file failed to open.\n";
			exit(1);
		}
		getline(in, NameCheck, ' ');
		while (!in.eof())
		{	if (NameCheck == userID)
			{	getline(in, NameCheck, " ");
				if (NameCheck == pw)
				{	errorCode = 0;
					return true;
				}
			}
		}
		errorCode = 2;
		return false;
	}
	else
	{	errorCode = 1;
		return false;
	}
}

Next is the professor's driver that I'm not allowed to change

#include <iostream>
#include <fstream>
#include <cassert>
#include "Password.h"

using namespace std; //introduces namespace std

void TestNewPW(Password p);
// Tests the Password class public function NewPW

void TestVerifyPW(Password p);
// Tests the Password class public function VerifyPW


int main ( void )
{
	cout << "This is a test of Lab 3\n";
	Password thePassword ("OLab3a"); // Tests explicit value constructor.
	TestNewPW(thePassword);
	TestVerifyPW(thePassword);

	return 0;
}

void TestNewPW(Password p)
{
	cout << "\nTesting NewPW.\n";
	ifstream in ("newpw.txt");
	assert (in.is_open());
	string ID, pw;
	int code;
	for (;;)
	{
		in >> ID;
		if (in.fail()) break;
		in >> pw;
		p.NewPW ("OLab3a", ID, pw, code);
		cout << "\nID: " << ID
		     << "  PW: " << pw;
		switch (code)
		{
			case 0: cout << " successfully added.\n"; break;
			case 1: cout << " error:  invalid administrator password.\n"; break;
			case 2: cout << " error:  ID already exists.\n";  break;
			case 3: cout << " error:  invalid user password.\n";  break;
			default:  cout << " *** Programmer Error, invalid code returned.\n";
		}

	}

	in.close();


	ID = "BB02";
	pw = "ZZZZZZ";
	p.NewPW ("OLab3p", ID, pw, code);
	cout << "\nID: " << ID
	     << "  PW: " << pw;
	switch (code)
	{
		case 0: cout << " successfully added.\n"; break;
		case 1: cout << " error:  invalid administrator password.\n"; break;
		case 2: cout << " error:  ID already exists.\n";  break;
		case 3: cout << " error:  invalid user password.\n";  break;
		default:  cout << " *** Programmer Error, invalid code returned.\n";
	}
} // end TestNewPW




void TestVerifyPW(Password p)
{
	cout << "\nTesting VerifyPW.\n";
	ifstream in ("verifypw.txt");
	assert (in.is_open());
	string ID, pw;
	int code;
	for (;;)
	{
		in >> ID;
		if (in.fail()) break;
		in >> pw;

		cout << "\nID: " << ID
		     << "  PW: " << pw;

		if (p.VerifyPW ("OLab3a", ID, pw, code))
			cout << " password is correct;\n";
		else
			switch (code)
			{
				case 0: cout << " successful verification.\n"; break;
				case 1: cout << " error:  invalid administrator password.\n"; break;
				case 2: cout << " error:  ID not found.\n";  break;
				case 3: cout << " error:  invalid user password.\n";  break;
				default:  cout << " *** Programmer Error, invalid code returned.\n";
			}

	}
	in.close();

	ID = "BB02";
	pw = "ZZZZZZ";
	cout << "\nID: " << ID
	     << "  PW: " << pw;
	if (p.VerifyPW ("OLab3a", ID, pw, code))
			cout << " password is correct;\n";
		else
			switch (code)
			{
				case 0: cout << " successful verification.\n"; break;
				case 1: cout << " error:  invalid administrator password.\n"; break;
				case 2: cout << " error:  ID not found.\n";  break;
				case 3: cout << " error:  invalid user password.\n";  break;
				default:  cout << " *** Programmer Error, invalid code returned.\n";
			}

} // end TestVerifyPW

First, this belongs in the C++ forum.

I'm not getting unresolved external symbol errors, but they might be mistaken for some mismatched templated function arguments ("no matching function for call to xxx").

Password.cpp: Lines 55, 68, 91
The fstream.open() function takes a (const char *), not a (std::string). Fix it thus: in.open(FileName[B].c_str()[/B]); Password.cpp: Line 90
Watch the character case of your identifiers. if ([B]adminPW[/B] == Decrypt(EncryptedPass, EncryptionKey)) Password.cpp: Line 99
Again, you've supplied arguments that don't match the function. getline() takes a character for a delimiter, not a string. Alas. getline(in, NameCheck, [B]' '[/B]); This compiles and runs for me. I can't test further because I don't have your test input file, and my brain is too tired right now to read through your code to figure out what it should look like.

Hope this helps.

Thanks Duodas, it compiles and now I only need to fix some logic things.

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.