PART ONE -Writing a program that keeps track of employees and their pay. - Emplo
ID: 3569915 • Letter: P
Question
PART ONE
-Writing a program that keeps track of employees and their pay.
- Employee.h is provided
- giveRaise - takes an int(which is percenatge of a pay raise.) This should calculate new pay rate
- pay - Should pay the employee once. Their balance should increase by the amount they are paid.
- fire - Should remove the employee from payroll
- isEmployeed - Boolean that should return if they are employed or not.
- Employyes hsould start off with base pay of $10.00
- Create a main.pp and add the main()
- create some Employee objects
PART TWO
- You will use a map to store employee info
- it should associate their ID num with rest of their data
- Create your employee map, and test adding employees to it, changing pay rates and paying them.
PART THREE
- Write rest of main function from a file called input.txt and write out to file called output.txt
- input file contains:
- NEW: This will add a new employee to the company. The number after the command is their employee ID num, and the next 2 are first/last name
- RAISE: This will give employe a raise. Num afterthe command is their ID. Next is the percenatge their pay goes up
- PAY: Pays all employees
- FIRE: This will fire employee. Next num is ID num of employee to fire
EMPLOYEE.H
#include
<string>
using
namespace std;
#ifndef
EMPLOYEE_H
#define
EMPLOYEE_H
?
classEmployee
{
private:
string name;
double balance;
double payRate;
public:
// Constructor
Employee(string myName = "")
{
}
// Getter to return the current pay rate
double getPayRate()
{
}
// Getter to return the current amount of pay earned
double getBalance()
{
}
// Getter to get Employee's name
string getName()
{
}
// Function to give the raise. It takes in a percent in whole numbers
// (ex: 5 for 5%)
void giveRaise(int rate)
{
}
// Pays the employee
void pay()
{
}
// Fires the Employee
void fire()
{
}
// Returns if the Employee is currently employed
bool isEmployed()
{
}
};
#endif
=======
INPUT.TXT
NEW 101 Jane Jameson
NEW 156 Sam Samuelson
NEW 104 Bob Boberson
NEW 136 Tim Thomason
RAISE 104 5
PAY
NEW 188 Mike Michaelson
NEW 190 Jason Jasonson
RAISE 101 5
RAISE 190 5
PAY
PAY
RAISE 101 5
PAY
PAY
FIRE 188
PAY
PAY
===========
OUTPUT:
Jane Jameson, ID Number 101:
Current pay rate: $11.025
Pay earned to date: $75.1
Bob Boberson, ID Number 104:
Current pay rate: $10.5
Pay earned to date: $73.5
Tim Thomason, ID Number 136:
Current pay rate: $10
Pay earned to date: $70
Sam Samuelson, ID Number 156:
Current pay rate: $10
Pay earned to date: $70
Mike Michaelson, ID Number 188:
Not employed with the company.
Pay earned to date: $40
Jason Jasonson, ID Number 190:
Current pay rate: $10.5
Pay earned to date: $63
Explanation / Answer
//employee.h
#include<string>
#include<iostream>
using namespace std;
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee {
private:
string name;
double balance;
double payRate;
bool isEmployee;
public:
// Constructor
Employee()
{
}
Employee(string myName) {
name = myName;
payRate = 10;
isEmployee = true;
}
// Getter to return the current pay rate
double getPayRate() {
return payRate;
}
// Getter to return the current amount of pay earned
double getBalance() {
return balance;
}
// Getter to get Employee's name
string getName() {
return name;
}
// Function to give the raise. It takes in a percent in whole numbers
// (ex: 5 for 5%)
void giveRaise(int rate) {
payRate += ((rate/100.0)*payRate);
}
// Pays the employee
void pay() {
if(isEmployed())
balance += payRate;
}
// Fires the Employee
void fire() {
isEmployee = false;
}
// Returns if the Employee is currently employed
bool isEmployed() {
return isEmployee;
}
};
#endif
------------------------------------------------------------------------------------
//main.cpp
#include <iostream>
#include <fstream>
#include <string>
#include<map>
#include "employee.h"
using namespace std;
int main() {
ifstream in;
in.open("input.txt");
map<int, Employee> employees;
while (!in.eof()) {
string action;
in>>action;
if (strcmp(action.c_str(), "NEW") == 0) {
int id;
char name[100];
in>>id;
in.getline(name, 100);
employees[id] = Employee(string(name));
} else if (strcmp(action.c_str(), "RAISE") == 0) {
int id, raise;
in >> id>>raise;
employees[id].giveRaise(raise);
} else if (strcmp(action.c_str(), "PAY") == 0) {
for (map<int, Employee>::iterator ii = employees.begin(); ii != employees.end(); ++ii)
ii->second.pay();
} else {
int id;
in>>id;
employees[id].fire();
}
}
for (map<int, Employee>::iterator ii = employees.begin(); ii != employees.end(); ++ii) {
cout<<ii->second.getName()<<","<<" ID Number: "<<(ii->first)<<": ";
if(ii->second.isEmployed())
cout<<"Current pay rate: $"<<ii->second.getPayRate()<<" ";
else
cout<<"Not employed with the company. ";
cout<<"Pay earned to date: $"<<ii->second.getBalance()<<" ";
}
return 0;
}
--------------------------------------------------------------------------------
OUTPUT
Jane Jameson, ID Number: 101:
Current pay rate: $11.025
Pay earned to date: $75.1
Bob Boberson, ID Number: 104:
Current pay rate: $10.5
Pay earned to date: $73.5
Tim Thomason, ID Number: 136:
Current pay rate: $10
Pay earned to date: $70
Sam Samuelson, ID Number: 156:
Current pay rate: $10
Pay earned to date: $70
Mike Michaelson, ID Number: 188:
Not employed with the company.
Pay earned to date: $40
Jason Jasonson, ID Number: 190:
Current pay rate: $10.5
Pay earned to date: $63
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.