Well your code doesnt have a constructor or deconstructor (though the compiler will give you a basic one in the background), but if you want one you define it like so:
Code:
class database
{
public:
database(); //constructor
~database(); // deconstructor
}
The constructor is called whenever you make an OBJECT of the class, and you make an object of the class if you plan on using that class for something. You can give the constructor arguements (but not the deconstructor), so when you create an object of the class you can give it arguments that basicly define initial values that you want for every database object. You can also do things inside of the constructor or deconstructor, for example delete pointers (allocated memory) ro avoid memory leaks.
Theres 2 problems I see with your code. The first is your argument in the function 'position', when you called it you put 'position(rank)' .. well what is rank? its nothing, the 'int rank' in the function cant go out of that scope, so you would need to make a new variable whereever you are calling that function and define it to the case you want, or put the case in directly.
The second is a class problem for defining your functions. If you want functions for your class you give the prototype inside the class, and then define the action function outside of it. ie. void database:osition (int rank) { }, however you could define them inside the class if they were inline, but I dont think that would work with the code you want to have here, or would it be efficient.
Code:
#include <iostream>
using namespace std; //you had 2 s's in 'namespace'
class database
{
private: // you might as well define these as private variables
int employee; //you can combine these variables, ie. int employee, position, x, rank;
//removed int position, and x, it was not necessary
int id_number; //added here because you have defined down there as if in class scope
int rank; //added this because you are using this as if its scope is everywhere in the class.
float salery;
public:
int position (); //prototype, changed from void to int to return the positon #
void quarry (); //prototype
void respond (); //prototype
};
int database::position ()
{
switch (rank)
{
case 1:
cout<<"cashier";
break;
case 2:
cout<<"Bag boy";
break;
case 3:
cout<<"delly";
break;
case 4:
cout<<"janeter";
break;
case 5:
cout<<"banker";
break;
case 6:
cout<<"produce";
break;
case 7:
cout<<"vice-maneger";
break;
case 8:
cout<<"maneger";
break;
case 10:
cout<<"1) cashier \n2) bag boy \n3) delly \n4) janeter \n5) banker \n";
cout<<"6) produce \n7) vice-maneger \n8) maneger \n";
cin>> rank;
break;
//position (rank); commenting this out, put a while(1) loop on the menu instead of a goto type
default:
cout<<"not in database";
break;
}
return rank;
}
void database::quarry ()
{
cout<<"Employee id number? "<<endl;
cin>> id_number;
cout<<"The salery of employee: "<< id_number<<endl;
cin>> salery;
cout<<"The current status of employee? 10 for listings "<<endl;
cin>> rank;
position (); //added this so it has something to do after taking input
}
void database::respond ()
{
cout<<"employee id number is: "<<id_number<<endl; //you mispelled id_number
cout<<"employee salery: "<<salery<<" per hour"<<endl;
cout<<"your employee's position is: " <<position ()<<endl; // changed this part, you can put it all together
}
int main ()
{
database editDatabase; //declare an object of 'database' class
editDatabase.quarry(); //call the function
editDatabase.respond();
cin.ignore(); //pause the system to view output
cin.get();
}
Alright that will compile, and I tried not to many many changes so I could relate to your method of coding. That means there are some "problems" with your, and that coding, because its not really efficient, or does it make sense in some areas (the return position #, salary amount, etc.). In my own version I would change a lot, but I didnt want to go an add a bunch of strings, while statements, remove and add functions or else it wouldnt be the image you had in mind.. this is just a compiling version.
btw you have some spelling mistakes of course, salery, maneger, janeter, etc.