Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a class employee that includes three pieces of information as data member

ID: 3620023 • Letter: C

Question

create a class employee that includes three pieces of information as data members. a first name ( type string), a last name (type string) and a monthly salary ( type int). Your class should have a constructor that initializes the three data members. provide a set and a get function for each data member. If the monthly salary is not poitive, set it to 0. write a test program that demonstrates class Employee's capablilites. Create two employee objects and display each object's yearly salary. Then give each employee a 10 percent rise and display each employee's yearly salary again.

Explanation / Answer

please rate - thanks salary really should be float or double #include <iostream>
using namespace std;
class employee{
      private:
         string first;
         string last;
         int salary;
       
public:
        employee(string f,string l,int s)
           {first=f;
           last=l;
           salary=s;
           if(salary<0)
               salary=0;
            }
        void setfirst(string f)
           {first=f;
            }
        void setlast(string l)
           {last=l;
            }
         void setsalary(int s)
           {salary=s;
            }
         string getfirst()
           {return first;
           }
          string getlast()
           {return last;
           }
          int getsalary()
           {return salary;
           }
          void giveraise(double percent)
              {salary=salary+(salary*(percent/100));
              }
};

int main()
{employee one("john","paul",100);
employee bad("Miss", "negative", -30);
cout <<"employee 1 "<<one.getfirst()<<" "<<one.getlast()<<" salary: "<<one.getsalary()<<endl;
cout <<"employee 2 "<<bad.getfirst()<<" "<<bad.getlast()<<" salary: "<<bad.getsalary()<<endl;
bad.setfirst("Mrs");
bad.setlast("positive");
bad.setsalary(120);
cout <<"employee 2 "<<bad.getfirst()<<" "<<bad.getlast()<<" salary: "<<bad.getsalary()<<endl;
one.giveraise(10);
bad.giveraise(10);
cout <<"employee 1 "<<one.getfirst()<<" "<<one.getlast()<<" salary: "<<one.getsalary()<<endl;
cout <<"employee 2 "<<bad.getfirst()<<" "<<bad.getlast()<<" salary: "<<bad.getsalary()<<endl;
system("pause");
return 0;
}