I am new and have been working my way through the tutorials and am now officially annoyed. I have started experimenting with classes and seeing how I can work them into a linked list style of operation. My code is here:
Code:
class Database
{
public:
// public variables
char employee_name [50]; // employee name
int id_number; // identification number
int group_number; // group number
Database (); // constructor definition
~Database (); // destructor definition
Database *next; // pointer to the next entry
// function to add a new employee
void add_new_user();
protected:
char supervisor [50]; // name of supervisor
int ranking; // ranking within group
float salary; // employee's salary
void getsupervisor (char *super, int group);
// determine the employee rank
int getrank (int id, int group);
// determine the salary
float getsalary (int rank, int group);
};
void Database::add_new_user( )
{
char name [50];
int group;
int id;
cout << "Enter the employee's name ";
cin.getline (name, 50, '\n');
cout << "Enter the employee's group ";
cin >> group;
cin.ignore(); // ignore enter
cout << "Enter the employee's ID number ";
cin >> id;
cin.ignore();
strncpy(employee_name, name, 50);
group_number = group;
id_number = id;
ranking = getrank(id, group);
salary = getsalary(ranking, group);
getsupervisor(supervisor, group);
}
int main ()
{
Database *root; // delcare a pointer to a root database
Database *employee; // declare a pointer to the employee database
employee = root; // set the employee
char entry; // entry selection
while (entry != 'e')
{
cout << "(a)dd new employee \n";
cout << "(p)rint all employees \n";
cout << "(e)xit \n";
cin >> entry;
// switch statement for entry
switch (entry)
{
case 'a' :
employee -> next = new Database; // create a new database
employee = employee -> next; // set pointer to new employee
employee.add_new_user();
break;
case 'p' :
employee = root;
while (employee != NULL)
{
cout << "Name: " << employee -> employee_name << "\n";
cout << "Group: " << employee -> group_number << "\n";
cout << "ID number " << employee -> id_number << "\n";
employee = employee -> next;
}
cout << "Name: " << employee -> employee_name << endl;
cout << "Group: " << employee -> group_number << endl;
cout << "ID number " << employee -> id_number << endl;
break;
case 'e' :
cout << "Ending" << endl;
break;
}
}
cin.get();
}
When I get to employee.add_new_user, I get this error:
"141 C:\Documents and Settings\Owner\My Documents\dbase_exp.cpp `add_new_user' has not been declared" and I can't understand why. Could somebody enlighten me?
Thanks
Chris