Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[c++] modify this code to where department and role can be set individually add an additional data member named count that keeps track of the

[c++] modify this code to where

  • department and role can be set individually
  • add an additional data member named count that keeps track of the number of Employee object
  • salary can be increased by 5 - 10 %
  • department, role and salary can be changed simultaneously.
  • All data members can be displayed at once
  • In main:
  • Display information of all employees on the console
  • Display the average salary of all employees on the console
  • Display information of programmers only on the console
  • Increase the salaries of all managers by random percentage and display the results
  • Reassign an employee to a different department and role with increased salary and display the result.
  • Also, display the number of employees.

//Employee.h

#pragma once #include #include #include #include #include

using namespace std;

#define SIZE 5

enum Role { programmer = 0, manager = 1, director = 2 };

class Employee { string firstName; string lastName; int SSN; string department; Role role; double salary; public: Employee(); void setSalary(double sala); void setRoles(Role r); Role getRole(); //Added by CHEGGEA //add mutator function to set private variables void setFirstName(string str); void setLastName(string str); void setSSN(int ss); void setDepartment(string dept); //add accessor functions to access private variable string getFirstName(); string getLastName(); int getSSN(); string getDepartment(); double getSalary();

};

=======================================

//Employee.cpp

#include"Employee.h" //Added constructor without which you cannot create an object,CHEGGEA Employee::Employee() { firstName = ""; lastName = ""; SSN = 0; department = ""; role = Role(programmer); salary = 0; }

//Added new function by CHEGGEA //add mutator function to set private variables void Employee::setFirstName(string str) { firstName = str; } void Employee::setLastName(string str) { lastName = str; } void Employee::setSSN(int ss) { SSN = ss; } void Employee::setDepartment(string dept) { department = dept; } //add accessor functions to access private variable string Employee::getFirstName() { return firstName; } string Employee::getLastName() { return lastName; } int Employee::getSSN() { return SSN; } string Employee::getDepartment() { return department; }

void Employee::setSalary(double sala) { salary = sala; } void Employee::setRoles(Role r) { role = r; } Role Employee::getRole() { return role; }

double Employee::getSalary() { return salary; }

==========================

//main.cpp and output

#include #include #include"Employee.h" using namespace std;

void hardCoding(Employee *em) { em[0].setFirstName("Bob"); em[0].setLastName("Marley"); em[0].setDepartment("Acc."); em[0].setSSN(3);

em[1].setFirstName("Shas"); em[1].setLastName("Ivy"); em[1].setDepartment("Audit"); em[1].setSSN(4);

em[2].setFirstName("Margo"); em[2].setLastName("Kim"); em[2].setDepartment("Mgmnt."); em[2].setSSN(5); em[3].setFirstName("Milly"); em[3].setLastName("Pink"); em[3].setDepartment("IT"); em[3].setSSN(6); em[4].setFirstName("Sia"); em[4].setLastName("Miskel"); em[4].setDepartment("IT"); em[4].setSSN(7); }

//Modified functions by CHEGGEA void setSalaries(Employee *em, int size) { for (int i = 0; i < size; i++) { em[i].setSalary(rand()); } }

void setRoles(Employee *em, int size) { for (int i = 0; i < size; i++) { em[i].setRoles(Role(rand() % 3)); } }

string getRole(Role role) { string ret;

switch (role) { case 0: ret = "Programmer"; break; case 1: ret = "Manager"; break; case 2: ret = "Director"; break; } return ret; }

int main() { Employee *emp = new Employee[SIZE];

srand((unsigned)time(NULL));

double avgSal = 0.0;

hardCoding(emp);

setSalaries(emp, SIZE);

setRoles(emp, SIZE);

cout << "Employee Database ";

cout << "Name\t\tSSN\tDapartment\tRole\t\tSalary ";

for (int i = 0; i < SIZE; i++) { cout << emp[i].getFirstName() << " " << emp[i].getLastName() << "\t"; cout << emp[i].getSSN() << "\t"; cout << emp[i].getDepartment() << "\t\t"; cout << getRole(emp[i].getRole()) << "\t"; cout << emp[i].getSalary() << " ";

avgSal += emp[i].getSalary(); }

cout << " Average Salary: " << avgSal / SIZE;

return 0; }

================================================

/*Output Employee Database

Name SSN Dapartment Role Salary Bob Marley 3 Acc. Programmer 26163 Shas Ivy 4 Audit Programmer 228 Margo Kim 5 Mgmnt. Programmer 23061 Milly Pink 6 IT Director 7207 Sia Miskel 7 IT Programmer 20657

Average Salary: 15463.2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

The amount of work I am asked to do is reasonable.

Answered: 1 week ago

Question

The company encourages a balance between work and personal life.

Answered: 1 week ago