2 Replies - 3257 Views - Last Post: 28 February 2009 - 06:47 AM Rate Topic: -----

#1 htrinh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-October 08

C++: Compilation Errors/Static Methods

Posted 27 February 2009 - 09:10 PM

#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;
				 
}	
 


Is This A Good Question/Topic? 0
  • +

Replies To: C++: Compilation Errors/Static Methods

#2 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

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
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,657
  • Joined: 23-August 08

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1