PDA

View Full Version : C++ Question


Nolf-Job
20 Apr 2004, 9:49pm
So I need to create a class and then follow these guidelines------->
Details about the member functions (methods) are as follows:
A. There are no constructors
B. setId() is used to store the id in an Employee object
C. setName() is used to store the name in an Employee object
D. setSalary() is used to store the salary in an Employee object
E. getId() is used to retrieve the id from an Employee object
F. getName() is used to retrieve the name from an Employee object
G. getSalary() is used to retrieve the salary from an Employee object

--Here is my class--
class Employee
{
private:
int id;
string name;
double salary;
public:
void setId(int num)
{id = num;}
void setName(string employeeName)
{name = employeeName;}
void setSalary(double money)
{salary = money;}
void getId()
void getName();
void getSalary();
};

----And here is one of the functions---
void displayEmp(const Employee& emp){
cout << endl << "Name ID Salary: "
<< emp.getName() << " "
<< emp.getId() << " "
<< emp.getSalary(); }

---And my question--
I can't figure out what I need to put for the three "get" functions in my class. Any help?

hooj
20 Apr 2004, 10:00pm
dont really know much about c++ but should be something like the following

int getId(){
return id;
}

Nolf-Job
20 Apr 2004, 10:02pm
I tried that before too, and i get this error h:\CPT 267\wk8\LAB04\LAB04\Lab04p1.cpp(71): error C2662: 'Employee::getName' : cannot convert 'this' pointer from 'const Employee' to 'Employee &'

hooj
20 Apr 2004, 10:16pm
int getId() const{
return id;
}

Nolf-Job
20 Apr 2004, 10:37pm
thanks hooj, that worked