First/last name: Quan Ortiz ID: 20974521 Home Address: 123 Amber st New York NY
ID: 3590726 • Letter: F
Question
First/last name: Quan Ortiz
ID: 20974521
Home Address: 123 Amber st New York NY 12343
contact num: 6465678909
Work Location: 90 White plain Rd Elmsford ny 56366
Base salary: $1500
Sales: $4200
First/last name: Fares Mac
ID: 22145864
Home Address: 34 Union Ave Staten Island NY 10314
contact num: 2134589045
Work Location: 23 Cedar st Flushing Ny 12567
Base Salary: $1250
Sales: $2200
First/last name: Cathy Chan
ID: 23433551
Home Address: 765 Oak st Brooklyn Ny, 10220
contact num: 3474553468
Work Location: 345 Anderson Rd New York ny 11234
Base salary: $1275
Sales: $1300
First/last name: Daren Anxon
ID: 23400347
Home Address: 2212 66th Brooklyn ny 11908
contact num: 2133338887
Work Location: 123 ForestHill Ln Staten island ny 15153
Base salary: 2000
Sales: $700
First/last name: Sara Lopez
ID: 23567890
Home Address: 223 Colon Ave ossining NY 13567
contact num: 9179087123
Work Location: 11-09 River Loop Jackson NJ 34567
Base salary: $1000
Sales: $5000
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
Solution:
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
class Employee
{
public :
int employeeID;
private:
string firstName;
string lastName;
//int employeeID;
string street;
string city;
string state;
string zip;
float contactNumber;
string workLocation;
float baseSalary;
float sales[12];
bool operator<(const Employee & other) //(1)
{
return employeeID < other.employeeID;
}
public:
Employee();
~Employee(){}
void setFirstName(string firstNameLocal){
firstName = firstNameLocal;
}
void setLastName(string lastNameLocal){
lastName = lastNameLocal;
}
void setEmployeeID(int employeeIDLocal){
employeeID = employeeIDLocal;
}
void setStreet(string streetLocal){
street = streetLocal;
}
void setCity(string cityLocal) {
city = cityLocal;
}
void setState(string stateLocal) {
state = stateLocal;
}
void setZip(string zip) {
zip = zip;
}
void setContactNumber(float contactNumberLocal){
contactNumber = contactNumberLocal;
}
void setWorkLocation(float workLocationLocal){
workLocation = workLocationLocal;
}
void setBaseSalary(float baseSalaryLocal){
baseSalary = baseSalaryLocal;
}
void setSales(float salesL[]){
int i = 0;
for(; i < 12 ; i++){
sales[i] = salesL[i];
}
}
void printStockInfo();
};
//implementations
Employee::Employee()
{
baseSalary = 0.0;
}
//printing
void Employee:: printStockInfo()
{
cout << "firstName : " << firstName << " ";
cout << "Last Name : " << lastName << " "<<endl;
cout << " Salary " << endl;
int idx = 0 ;
for(; idx < 12 ; idx++){
cout<< sales[idx] << endl;
}
}
bool compare(const Employee & l, const Employee & r) //(2)
{
return l.employeeID < r.employeeID;
}
std::vector<Employee> tokens;
int main()
{
std::ifstream file("Newfile.txt");
std::string line = "deepak rajdev 1 stree1 city1 state1 201301 12345678 newjersy 10000 100,200,100,300,202.5,300,400,200,100,300,400,500";
// while(std::getline(file, line)) { // ' ' is the default delimiter
std::istringstream iss(line);
std::string token;
Employee *f1 = new Employee;
string firstName;
string lastName;
string employeeID;
string street;
string city;
string state;
string zip;
string contactNumber;
string workLocation;
string baseSalary;
string sales;
std::string::size_type sz;
getline (iss, firstName, ' '); //read from in, store iso and table
getline (iss, lastName, ' '); //getline will only use string
getline (iss, employeeID, ' ');
getline (iss, street, ' ');
getline (iss, city, ' ');
getline (iss, state, ' ');
getline (iss, zip, ' ');
getline (iss, contactNumber, ' ');
getline (iss, workLocation, ' ');
getline (iss, baseSalary, ' ');
getline (iss, sales, ' ');
// cout << firstName << lastName << sales << endl ;
f1->setFirstName(firstName);
f1->setLastName(lastName);
int tEmpID = std::atoi(employeeID.c_str());
f1->setEmployeeID(tEmpID);
float tBaseSalary = std::atof(baseSalary.c_str());
f1->setBaseSalary(tBaseSalary);
std::istringstream iss1(sales);
string token1;
int i = 0 ;
float salesLocal[12];
while (getline(iss1,token1, ','))
{
float salesTemp = std::atof(token1.c_str());
if( i < 12){
salesLocal[i] = salesTemp;
i++;
}
f1->setSales(salesLocal);
}
tokens.push_back(*f1);
// std::sort(tokens.begin(), tokens.end(), compare);//
// }
vector<Employee>::iterator it1;
for ( it1 = tokens.begin(); it1 != tokens.end(); ++it1 ) {
it1->printStockInfo();
}
return 0;
}
Please use C++11 to execute.
Please, please upvote and ask your doubts in the comments.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.