Question

Write the class definition for a class named Employee. The class should include data members for...

Write the class definition for a class named Employee. The class should
include data members for an employee object's name and salary (the salary will
be an integer). The class should contain two member functions: the constructor
and a function that allows a program to assign values to the data members. Add
two member functions to the employee class. One member function should allow any
program using an employee object to view the contents of the salary data member.
The other member function should allow the program to view the contents of the
employee name data member. (Hint: have the member functions simply return the
contents of the appropriate data member).

Add another member function to the class. This function should calculate an
employee object's new salary, based on a raise percentage, provided by the
program (main function). Before calculating the raise, the member function
should verify that the raise percentage is greater or equal to zero. If the
raise percentage is less then zero, the member function should display an error
message.

Write main function that will create an array of employee objects, assign
values to the objects, display the names and current salaries for all objects,
ask user for the raise percentage and then calculate and display new salaries
for all objects.

Do this in C++

Homework Answers

Answer #1

Note

######

In case of any issue please comment

//####################### PGM START #########################################

#include<iostream>
#include<string>
using namespace std;
//employee class
class Employee{
   private:
       string name;
       int salary;
   public:
       //constructor
       Employee(){
       }
       //adding name and salary for employee
       void addEmp(string name,int s){
           this->salary=s;
           this->name=name;
       }
       //funtion to get name of employee
       string getName(){
           return this->name;
       }
       //funciton to get salary of employee
       int getSalary(){
           return this->salary;
       }
       //funtion to find new salary beased on rate increased
       int newSalary(double r){
           if(r<0){
               cout<<"Error... rate less than 0\n";
               return -1;
           }
           this->salary+=(0.01*r*this->salary);
           return 1;
       }
};
//main class
int main(){
   string name;
   double rate;
   int flag;
  
   //creating an array of 5 employee
   Employee e1[5];
   //adding values to 5 employee object using addEmp() method
   e1[0].addEmp("Emp1",1500);
   e1[1].addEmp("Emp2",2300);
   e1[2].addEmp("Emp3",4500);
   e1[3].addEmp("Emp4",3400);
   e1[4].addEmp("Emp5",4000);
  
   //prinitng initial employee data
   cout<<"Current employee data:\n";
   for(int i=0;i<5;i++){
       cout<<e1[i].getName()<<"          "<<e1[i].getSalary()<<"\n";
   }
   cout<<"Enter the rate by which salary is to be increased: ";
   cin>>rate;
  
   //revising employee salary based on rate user entered
   for(int i=0;i<5;i++){
       flag=e1[i].newSalary(rate);      
       if(flag==-1)
           break;
   }
   if(flag==1){
       //prinitng revised employee data
       cout<<"Revised employee data:\n";
       for(int i=0;i<5;i++){
           cout<<e1[i].getName()<<"          "<<e1[i].getSalary()<<"\n";
       }
   }
  
  
   return 0;
}

//############################### PGM END ##################################

OUTPUT
#########

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Write program in C#. WAP on Encapsulation to hide the type members with private access and...
Write program in C#. WAP on Encapsulation to hide the type members with private access and display employee details. • Create a new project, select console application from the template and name the project as “EmployeeDetails.cs”. • Here type members are nothing but properties. • Create another class as Employee and write the properties for EmpId, EmpName and Salary. • Now, create an instance of the Employee class in the “EmployeeDetails” class and assign the values for EmpId,EmpName and Salary...
Create a class hierarchy to be used in a university setting. The classes are as follows:...
Create a class hierarchy to be used in a university setting. The classes are as follows:  The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last...
Write a program to prepare the ‘payroll’ of an employee by using single inheritance. The base...
Write a program to prepare the ‘payroll’ of an employee by using single inheritance. The base class contains employee Name and Id while the derived class ‘allowance’ has float members for basic_pay, medical_allowance and transport_allowance. It then calculates gross pay of the employee through a member function (for both classes there should be getinput() and getoutput() functions with same name) use c++
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for...
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked. Write a program with an array of seven PayRoll objects. The program should read the number of hours each employee worked and their hourly pay rate from a file and call class functions to store this information in the appropriate objects. It should then call a class function, once for each object, to return...
Create a class called time that has three data members hours, minutes, and seconds. The class...
Create a class called time that has three data members hours, minutes, and seconds. The class has the following member functions: - Overloaded Constructors - Display function to display it, in 11:59:59 format. - SetTime() - IsValid(): Check if the time is valid or not - AddTime(Time t1, Time t2): Add two time values passed as a parameter leaving the result in third time variable. - Increment(): Tells what will be time after a second - Decrement(): Tells what was...
Has to be written in C#! Write a program that includes an Employee class that can...
Has to be written in C#! Write a program that includes an Employee class that can be used to calculate and print the take-home pay for a commissioned sales employee. Items to include as data members are employee number, first name, last name, and total sales. All employees receive 9% of the total sales of the month. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Use appropriate constants, design an object-oriented solution, and...
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
Define a class named Employee that has four data fields: name: String hoursWorked: double hourlyPayrate: double...
Define a class named Employee that has four data fields: name: String hoursWorked: double hourlyPayrate: double bonusRate: double The class has two constructors: 1. constructor without arguments: initialize name to empty string, and all other data fields to 0.0 2. constructor with a String type arguments and three double type arguments. Use them to initialize the data fields properly The class also has: 1. Getter method for each data field to return the value of the data field 2. Setter...
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT