well i can do that but i need it to check to make sure that the user isn't entering a name that already exists... |
Think carefully about what
Thomas1965 said here :+)
Why don't you use your find function to see if it returns -1, in this case the employee doesn't exist. |
Some other things:
Pass strings by const reference:
int Staff::find(const std::string& n)
Try using a range based for loop:
1 2 3 4 5 6 7 8
|
void Staff::print()
{
for (const auto& item : members)
{ // always use braces even if there is 1 statement
// it will save you one day when adding new code
cout << item.get_name() << " " << item.get_salary() << endl;
}
}
|
There are other places where you could do something similar.
When using double literal values in code, I like to put digits before and after the decimal point. It saves the compiler doing an implicit cast to double, and can help with hard to see errors:
1 2
|
salary += salary * percent/100;
salary *= 1.0 + percent/100.0;
|
Use const where ever you can:
1 2
|
void Staff::raise_salary(const std::string& n, const int percent)
{
|
Note that I mark the parameters
const
in the implementation, not the class definition.
Functions that don't change the value of the class members, should be marked const:
1 2 3 4 5 6 7 8 9 10 11 12
|
class Employee
{
private:
string name;
double salary;
public:
Employee();
Employee(string n, double s);
string get_name() const ;
double get_salary() const ;
void set_salary(double s);
};
|
Good Luck !!