based on their ranking among their peers, and OUTPUT information as defined belo
ID: 3594923 • Letter: B
Question
based on their ranking among their peers, and OUTPUT information as defined below. The program should eontain separate functions wherever redundancy appears; you M 3 User-Defined Functions in your program. Create a Program that will INPUT Employee Information from a ,calculate the BONUS UST have at least The INPUT information must include Employee Name (both First and Las), an Employee ID, their Home Address (Street, City State and Zip), their Home Phone/Personal Contact Number, their Work Location (you should have at least 3 different/possible locations), their Base Salary, and their Sales for the last 12 months. ALL information INPUT about each employee, except their Bonus and Total Salary, of course, will be obtained from a file which you will need to create. INPUT will be read into a STRUC which you will design. The program will calculate a 20% bonus based on their Total Sales for the year if they are the top selling employee, a 15% bonus if they are the #2 person and 10 % if they are the number 3 person. All other employees will receive a 5% bonus if their sales are greater than a specified "minimum" amount or NO bonus if they did not produce that "minimum" amount. The employees TOTAL SALARY is their Base Salary plus their BONUS. The OUTPUT will be PRINTED in increasing order by TOTAL SALARY for the vear Employees First and Last Name, Location, BONUS for the year should be printed. AIl OUTPUT MUST have appropriate headings. (Specifically, all information should be printed using the functionality contained in the preprocessor directive 1OMANIP, that is, output should be in tabular form with appropriate headings.) Lastly, you will print all Employee Contact Information separately. Again, First Name, Last Name, Employee ID, their Location and their Home Address and Home Phone and Ranking by Total Salary. EXTRA CREDIT: The program will calculate a 20% bonus based on their total sales for the year if they are the top selling employee FOR EACH LOCATION SEPARATELY and give, by LOCATION, a 15% bonus if they are the #2 person at their location and 10 % if they are the number 3 person. All other employees will receive a 5% bonus if their sales are greater than a specified “minimum" amount For the Extra Credit, you will print all Employee Contact Information separately BY LOCATION. OUTPUT MUST INCLUDE: First Name, Last Name, Employee ID, their Location, Home Address and Home Phone, AND THEIR Ranking in order by BONUS for EACH LOCATIONExplanation / Answer
#include <fstream>
#include<iostream>
#include<iomanip>
#include<string>
#include<stdlib.h>
//Defines minimum sales amount
#define MIN 1500
using namespace std;
//class Employee defined
class Employee
{
//Data member to store data
string firstName;
string lastName;
string employee_ID;
string street;
string city;
string state;
string zip;
string contactNumber;
string workLocation;
double baseSalary;
double salesAmount;
double bonus;
double totalSalary;
int numberOfRecords;
public:
//Prototype of member function
Employee();
void readFile(Employee[]);
void process(Employee[]);
void printOutput(Employee[]);
void sortEmployee(Employee e[]);
};//End of class
//Default constructor to initialize data members
Employee::Employee()
{
firstName = lastName = employee_ID = street = city = state = zip = contactNumber = workLocation = "";
baseSalary = salesAmount = bonus = totalSalary = 0;
numberOfRecords = 0;
}//End of constructor
//Function to read data from specified file
void Employee::readFile(Employee e[])
{
int c = 0;
//Creates an object of ifstream
ifstream f;
//Opens the file for reading
f.open("EmployeeData.txt");
//Displays error if file not found
if(!f)
{
cout<<"Error in opening file..!!";
exit(0);
}//End of if
//Loops till end of file
while(!f.eof())
{
//Read data from file and stores it in data members
f>>e[c].firstName;
f>>e[c].lastName;
f>>e[c].employee_ID;
f>>e[c].street;
f>>e[c].city;
f>>e[c].state;
f>>e[c].zip;
f>>e[c].contactNumber;
f>>e[c].workLocation;
f>>e[c].baseSalary;
f>>e[c].salesAmount;
//Increase the record counter
c++;
}//End of while
//Stores the record counter in data member
numberOfRecords = c;
//Close the file
f.close();
}//End of function
//Function to print the result
void Employee::printOutput(Employee e[])
{
cout<<endl;
//Displays the heading
cout<<std::left<<setw(15)<<"First Name"<<setw(10)<<"Last Name"<<setw(5)<<"ID"<<setw(15)<<"Street"<<setw(15)<<"City"<<setw(10)<<"State"<<setw(13)<<"Zip"
<<setw(17)<<"Contact Number"<<setw(17)<<"Work Location"<<setw(13)<<"Basic Salary"<<setw(13)<<"Sales Amount"<<setw(8)<<"Bonus"<<setw(13)<<"Total Salary";
//Loops till number of records
for(int c = 0; c < numberOfRecords; c++)
{
//Displays each record
cout<<endl;
cout<<std::left<<setw(15)<<e[c].firstName<<setw(10)<<e[c].lastName<<setw(5)<<e[c].employee_ID;
cout<<setw(15)<<e[c].street<<setw(15)<<e[c].city<<setw(10)<<e[c].state;
cout<<setw(13)<<e[c].zip<<setw(17)<<e[c].contactNumber<<setw(17)<<e[c].workLocation;
cout<<setw(13)<<e[c].baseSalary<<setw(13)<<e[c].salesAmount<<setw(8)<<e[c].bonus<<setw(13)<<e[c].totalSalary;
}//End of for
}//End of function
//Function to calculate bonus and total salary
void Employee::process(Employee e[])
{
//Loops till number of records
for(int c = 0; c < numberOfRecords; c++)
{
//Checks sales amount and calculates the bonus
if(e[c].salesAmount > 5000)
e[c].bonus = e[c].salesAmount * .20;
else if(e[c].salesAmount > 4000)
e[c].bonus = e[c].salesAmount * .15;
else if(e[c].salesAmount > 3000)
e[c].bonus = e[c].salesAmount * .10;
else if(e[c].salesAmount > MIN)
e[c].bonus = e[c].salesAmount * .05;
else
e[c].bonus = 0;
//Calculates the total salary
e[c].totalSalary = e[c].baseSalary + e[c].bonus;
}//End of for loop
}//End of function
//Function to sort employee ascending order based on total salary
void Employee::sortEmployee(Employee e[])
{
int x, y;
int t = numberOfRecords;
//Creates a temporary object for swapping
Employee temp;
//Loops till number of records
for(x = 0; x < t; x++)
{
//Loops till number of records minus x minus one
for(y = 0; y < t - x - 1; y++)
{
//Checks if the current employee total salary is greater than the next employee total salary then swap
if(e[y].totalSalary > e[y + 1].totalSalary)
{
//Swapping process
temp = e[y];
e[y] = e[y + 1];
e[y + 1] = temp;
}//End of if
}//End of inner for loop
}//End of outer for loop
numberOfRecords = t;
}//End of function
//main function definition
int main()
{
//Creates an array of object of Employee class
Employee e[100];
//Calls the function to read data from file and store it in data member
e[0].readFile(e);
//Calls function to calculate bonus and total salary
e[0].process(e);
//Sorts employee record
e[0].sortEmployee(e);
//Displays employee information
e[0].printOutput(e);
}//End of main function
Sample Run:
First Name Last Name ID Street City State Zip Contact Number Work Location Basic Salary Sales Amount Bonus Total Salary
Rohit Sharma 150 koilinagar rourkela orissa 711008 9040008814 BBSR 25000 1000 0 25000
Suresh Panda 130 garebazar berhampur orissa 761108 9000555814 RKL 33000 3000 150 33150
Ram Padhi 120 ankuli bhubaneswar orissa 760013 9040555514 BBSR 45000 3000 150 45150
Roja Dash 140 jyotinagar rourkela orissa 760114 9990568855 RKL 48000 2000 100 48100
Pyari Sahu 110 comapoly berhampur orissa 760008 9040568814 BAM 55000 5000 750 55750
Input File: EmployeeData.txt contents
Pyari
Sahu
110
comapoly
berhampur
orissa
760008
9040568814
BAM
55000
5000
Ram
Padhi
120
ankuli
bhubaneswar
orissa
760013
9040555514
BBSR
45000
3000
Suresh
Panda
130
garebazar
berhampur
orissa
761108
9000555814
RKL
33000
3000
Roja
Dash
140
jyotinagar
rourkela
orissa
760114
9990568855
RKL
48000
2000
Rohit
Sharma
150
koilinagar
rourkela
orissa
711008
9040008814
BBSR
25000
1000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.