Created
August 17, 2017 16:15
-
-
Save axayjha/e270013dc9d57973477b41f7482d87ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
using namespace std; | |
#define CITY_ALLOWANCE 5000 | |
#define HILL_ALLOWANCE 3000 | |
#define H_D_ALLOWANCE 2000 | |
class employee | |
{ | |
string name, address, designation, office_location, ID; | |
long int phone_no; | |
int basic_salary; // I won't get a salary of order of long int, so... | |
public: | |
employee(){} //default constructor | |
employee(string name, string address, string designation, string office_location, string ID, long int phone_no, int salary) | |
{ | |
/* No one will use this bulky constructor, so just use the above | |
* default constructor and then use the methods below to set attributes. | |
*/ | |
this->name = name; | |
this->address = address; | |
this-> designation = designation; | |
this->office_location = office_location; | |
this->ID = ID; | |
this->phone_no = phone_no; | |
this->basic_salary = salary; | |
} | |
// Methods to set and get attributes | |
//----------------------------------------------------------------------------------- | |
void setName(string name) { this->name = name;} | |
string getName() { return this->name;} | |
void setAddress(string address) { this->address = address;} | |
string getAddress() { return this->address;} | |
void setDesignation(string designation) { this->designation = designation;} | |
string getDesignation() { return this->designation;} | |
void setLocation(string location) { this->office_location = location;} | |
string getLocation() { return this->office_location;} | |
void setID(string ID) { this->ID = ID;} | |
string getID() { return this->ID;} | |
void setPhoneNo(long int number) { this->phone_no = number;} | |
long int getPhoneNo() { return this->phone_no;} | |
void setBasicSalary(int b_salary) { this->basic_salary = b_salary;} | |
int getBasicSalary() { return this->basic_salary;} | |
//----------------------------------------------------------------------------------- | |
float getTotalSalary(); | |
void displayInfo(); | |
}; | |
float employee::getTotalSalary() | |
{ | |
if(this->basic_salary <= 0) | |
{ | |
cout << "No valid entry in basic salary attribute." << endl; | |
cout << "First set the basic salary (a natural number)> " << endl; | |
int amount; | |
cin >> amount; | |
this->setBasicSalary(amount); | |
return getTotalSalary(); | |
} | |
if(this->office_location=="" || (!(this->office_location =="Kolkata" \ | |
|| this->office_location=="Darjeeling" || this->office_location=="Gosaba"))) | |
{ | |
cout << "No valid entry in office location." << endl; | |
cout << "First set office location to be any of: Kolkata, Darjeeling or Gosaba" << endl; | |
cout << "Enter location > " << endl; | |
string location; | |
cin >> location; | |
this->setLocation(location); | |
return getTotalSalary(); | |
} | |
float salary=this->basic_salary; | |
salary += (0.5*salary); | |
if (this->office_location == "Kolkata") | |
salary += ((0.3 * this->basic_salary) + CITY_ALLOWANCE) ; | |
else if (this->office_location =="Darjeeling") | |
salary += ((0.25 * this->basic_salary)+ HILL_ALLOWANCE); | |
else | |
salary += ((0.2 * this->basic_salary) + H_D_ALLOWANCE); | |
return salary; | |
} | |
void employee::displayInfo() | |
{ | |
cout << "Name : \t" << this->getName() << endl; | |
cout << "ID : \t" << this->getID() << endl; | |
cout << "Branch: \t" << this->getLocation() << endl; | |
cout << "Designation:\t" << this->getDesignation() << endl; | |
cout << "Contact:\t" << this->getPhoneNo() << endl; | |
cout << "Net Salary:\t" << this->getTotalSalary() << endl; | |
cout << "Address:" << endl; | |
stringstream ss(this->getAddress()); | |
while( ss.good() ) | |
{ | |
string substr; | |
getline( ss, substr, ',' ); | |
cout << "\t" << substr << endl; | |
} | |
} | |
int main() | |
{ | |
employee e1; | |
e1.setName("Akshay"); | |
e1.setAddress("Hemchandra Street, Khidirpur, Kolkata"); | |
e1.setDesignation("Software Engineer"); | |
e1.setID("AD250996"); | |
e1.setLocation("Kolkata"); | |
e1.setPhoneNo(9430421262); | |
e1.setBasicSalary(22000); | |
e1.displayInfo(); | |
} | |
/* OUTPUT | |
---------------------------------------- | |
Name : Akshay | |
ID : AD250996 | |
Branch: Kolkata | |
Designation: Software Engineer | |
Contact: 9430421262 | |
Net Salary: 44600 | |
Address: | |
Hemchandra Street | |
Khidirpur | |
Kolkata | |
----------------------------------------*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment