c++ only
Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional functions
1. float getSalary(float rate,int hoursworked) that would return the employee’s monthly salary according to the rate and the weekly hoursworked. The employee’s salary is calculated as follows rate* hoursworked*4. If the type of employee is “CEO” the salary will be multiplied by 2. If the type is “senior” the salary will be multiplied by 1.5 and if it’s a “standard” employee, the salary will remain the same, however the salary shouldn’t be less than 1000 in any case.
2. void printEmployee() which would print all of the employee’s information.Note that if the user tries to set the type of Employee with any value other than “CEO”, “senior” or “standard” the class should set it to “unknown”.
Write a main to test your functions by creating an array of 3 employees. Your program should take the name,ID and type of each employee from the user, calculate their salary and display all of their information.
Code:
#include<iostream>
using namespace std;
class Employee
{
string name;
string id;
float salary;
string type;
public:
Employee()
{
salary=0;
type="unkown";
}
Employee(string name, string id,
string type)
{
this->name=name;this->id=id;this->type=type;
}
string getName()//getters
{
return
name;
}
string getID()
{
return id;
}
string getType()
{
return
type;
}
void setName(string
name)//setters
{
this->name=name;
}
void setID(string id)
{
this->id=id;
}
void setType(string type)
{
if(type!="CEO"
&& type!="senior" && type!="standard")//not a known
type
{
this->type="unkown";
}
else
this->type=type;
}
float getSalary(float rate, int
hoursworked)
{
salary=rate*hoursworked*4;
if(type=="CEO")
salary *= 2;
else
if(type=="senior") salary *= 1.5;
return
salary;
}
void printEmployee()
{
cout<<"Employee name: "<<name<<endl;
cout<<"Employee ID: "<<id<<endl;
cout<<"Employee type: "<<type<<endl;
cout<<"Employee salary: "<<salary<<endl;
}
};
int main()
{
Employee employee[3];//create objects
string name,id,type;float salary,rate,hours;
for(int i=0;i<3;i++)
{
cout<<"Enter name of employee
"<<i+1<<endl;//read from user and call respective
methods
cin>>name;employee[i].setName(name);
cout<<"Enter id of employee
"<<i+1<<endl;
cin>>id;employee[i].setID(id);
cout<<"Enter type of employee
"<<i+1<<endl;
cin>>type;employee[i].setType(type);
while(1)
{
cout<<"Enter rate and hours worked by employee
"<<i+1<<endl;
cin>>rate>>hours;
salary =
employee[i].getSalary(rate,hours);
if(salary <
1000)//invalid details, prompt user to enter again
{
cout<<"salary cannot be less than 1000.
Please enter again"<<endl;
}
else
break;
}
}
cout<<"Employee details:"<<endl;
for(int i=0;i<3;i++)
{
employee[i].printEmployee();
}
return 0;
}
Output:
c++ only Design a class representing an Employee. The employee would have at least these private...
C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary: public: Employee; // default constructor: age=0, id=0, and salary=0 void setAge(int x); // let age = x void setId(int x); // let id = x void setSalary(float x); // salary = x int getAge(); // return age int getId; // return id float...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary; public: Employee( ); // default constructor: age=0, id=0, and salary=0 Employee(Employee &x); // copy constructor Employee& operator = (Employee &x); // equal sign operator void setAge(int x); // let age = x...
Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...
Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...
It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...
C++ #include <iostream> using namespace std; bool checkinventoryid(int id) { return id > 0; } bool checkinventoryprice(float price) { return price > 0; } void endProgram() { system("pause"); exit(0); } void errorID(string str) { cout << "Invalid Id!!! " << str << " should be greater than 0" << endl; } void errorPrice(string str) { cout << "Invalid Price!!!" << str << " should be greater than 0" << endl; } int inputId() {...
Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...