#ifndef SECURITY_H
#define SECURITY_H
#include <iostream>
using namespace std;
class Security
{
public:
static int validate(string username, string password);
bool Administrator_login( string username, string password);
bool User_login(string username, string password);
};
#endif //SECURITY_H
//This is Security.cpp This subroutine hard-code valid users.
//It returns 0 if the credentials are invalid.
// 1 if valid user, and
// 2 if valid administrator
int Security::validate(string username, string password)
{
if ((username=="abbott") && (password=="monday"))
return 1;
if ((username=="costello") && (password=="tuesday"))
return 2;
else
return 0;
}
bool Security::Administrator_login(string username,string password)
{
int valid=Security::validate(username, password);
if (valid == 2)
{
return true;
}
else
return false;
}
bool Security::User_login(string username, string password)
{
int valid=Security::validate(username, password);
if(valid == 1 || valid == 2)
return true;
else
return false;
}
int main()
{
string username = "abbott";
string userpassword = "monday";
string AdminisName = "costello";
string AdminisPass = "tuesday";
int valid=Security::Administrator_login(AdminisName, AdminisPass)
if(valid = 2)
cout << "Enter your supervisor' s name" << AdminisName << endl;
else
cout << "You get mistake";
if(Administrator::Login(UserName, UserPass))
cout << "Enter your name" << Username << endl;
else
cout<< "This is not your name" << endl;
if(User::Login(AdminisName, AdminisPass)
cout << "That is correct" << AdminisName<< endl;
else
cout << "That is not correct";
if(User::Login(UserName, UserPass)
cout << "That is correct" << UserName << endl;
else
cout << "That is not correct" << endl;
}
C++: Compilation Errors/Static Methodsint main () is in trouble
Page 1 of 1
2 Replies - 2737 Views - Last Post: 28 February 2009 - 06:47 AM
#1
C++: Compilation Errors/Static Methods
Posted 27 February 2009 - 09:10 PM
Replies To: C++: Compilation Errors/Static Methods
#2
Re: C++: Compilation Errors/Static Methods
Posted 27 February 2009 - 09:33 PM
C:\Borland\BCC55\bin\bcc32.exe help1.cpp
Process started >>>
Borland C++ 5.5.1 for Win32 Copyright © 1993, 2000 Borland
help1.cpp:
Error E2283 help1.cpp 57: Use . or -> to call 'Security::Administrator_login(string,string)' in function main()
Error E2141 help1.cpp 58: Declaration syntax error in function main()
Error E2054 help1.cpp 60: Misplaced else in function main()
Error E2090 help1.cpp 63: Qualifier 'Administrator' is not a class or namespace name in function main()
Error E2377 help1.cpp 63: If statement missing ) in function main()
Error E2054 help1.cpp 65: Misplaced else in function main()
Error E2090 help1.cpp 68: Qualifier 'User' is not a class or namespace name in function main()
Error E2377 help1.cpp 68: If statement missing ) in function main()
Error E2054 help1.cpp 70: Misplaced else in function main()
Error E2090 help1.cpp 73: Qualifier 'User' is not a class or namespace name in function main()
Error E2377 help1.cpp 73: If statement missing ) in function main()
Error E2054 help1.cpp 75: Misplaced else in function main()
Warning W8004 help1.cpp 78: 'valid' is assigned a value that is never used in function main()
*** 12 errors in Compile ***
<<< Process finished.
From these errors, I think you should be able to fix a lot of it. See how many of these you can filter through, and then let us know what u couldnt get and I or someone else will be happy to help
~Bodom
Process started >>>
Borland C++ 5.5.1 for Win32 Copyright © 1993, 2000 Borland
help1.cpp:
Error E2283 help1.cpp 57: Use . or -> to call 'Security::Administrator_login(string,string)' in function main()
Error E2141 help1.cpp 58: Declaration syntax error in function main()
Error E2054 help1.cpp 60: Misplaced else in function main()
Error E2090 help1.cpp 63: Qualifier 'Administrator' is not a class or namespace name in function main()
Error E2377 help1.cpp 63: If statement missing ) in function main()
Error E2054 help1.cpp 65: Misplaced else in function main()
Error E2090 help1.cpp 68: Qualifier 'User' is not a class or namespace name in function main()
Error E2377 help1.cpp 68: If statement missing ) in function main()
Error E2054 help1.cpp 70: Misplaced else in function main()
Error E2090 help1.cpp 73: Qualifier 'User' is not a class or namespace name in function main()
Error E2377 help1.cpp 73: If statement missing ) in function main()
Error E2054 help1.cpp 75: Misplaced else in function main()
Warning W8004 help1.cpp 78: 'valid' is assigned a value that is never used in function main()
*** 12 errors in Compile ***
<<< Process finished.
From these errors, I think you should be able to fix a lot of it. See how many of these you can filter through, and then let us know what u couldnt get and I or someone else will be happy to help
~Bodom
#3
Re: C++: Compilation Errors/Static Methods
Posted 28 February 2009 - 06:47 AM
As shown, you should be able to make all of your Security class methods static because it has no member variables. That will make all of the calls you've made to it in the form of Security::whatever_method not cause an error.
Can't say anything about the User and Administrator classes, as they're nowhere to be found.
Also, changing your title to something more relevant.
Can't say anything about the User and Administrator classes, as they're nowhere to be found.
Also, changing your title to something more relevant.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|