based on their ranking among their peers and OUTPUT informat
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 << \"\\t\";
cout << \"Last Name : \" << lastName << \"\\t\"<<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;
}