Created
August 21, 2017 08:40
-
-
Save axayjha/3284e08f03db2eec19dfe8eed4532c79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 city | |
{ | |
string name; | |
int special_allowance; | |
float hra; | |
public: | |
city(){} | |
city(string n, int s, float h) {name = n; special_allowance=s; hra=h;} | |
int specialAllowance(){return this->special_allowance;} | |
float HRA(){return this->hra;} | |
string Name(){return name;} | |
} Kolkata("Kolkata", CITY_ALLOWANCE,0.3), Darjeeling("Darjeeling", HILL_ALLOWANCE, 0.25), Gosaba("Gosaba", H_D_ALLOWANCE, 0.2); | |
class employee | |
{ | |
string name, address, designation, ID; | |
city office_location; | |
long int phone_no; | |
int basic_salary; // I won't get a salary of order of long int, so... | |
public: | |
employee(){city office_location();} //default constructor | |
employee(string name, string address, string designation, city 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(city location) { this->office_location = location;} | |
city 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(); | |
}; | |
class Kolkata_Branch | |
{ | |
protected: | |
employee e1[100]; | |
int count; | |
public: | |
Kolkata_Branch(){ | |
count=0; | |
for(int i=0; i<100; i++) | |
e1[i].setLocation(Kolkata); | |
} | |
int getCount(){return count;} | |
void setCount(int count){this->count=count;} | |
employee getEmployee(int i){return e1[i];} | |
float regional_allowance() | |
{ | |
return Kolkata.specialAllowance(); | |
} | |
void Add_employee() | |
{ | |
string name, address, designation, id; long int phone_no; int salary; | |
cout << "Enter name: "; | |
cin >> name; | |
e1[count].setName(name); | |
cout << "Enter address: "; | |
cin >> address; | |
e1[count].setAddress(address); | |
cout << "Enter designation: "; | |
cin >> designation; | |
e1[count].setDesignation(designation); | |
cout << "Enter ID: "; | |
cin >> id; | |
e1[count].setID(id); | |
cout << "Enter phone number: "; | |
cin >> phone_no; | |
e1[count].setPhoneNo(phone_no); | |
cout << "Enter salary: "; | |
cin >> salary; | |
e1[count].setBasicSalary(salary); | |
count++; | |
} | |
void display_list() | |
{ | |
for(int i=0; i<count; i++) | |
{ | |
cout << i+1 << ". "<< e1[i].getName() << endl; | |
} | |
} | |
}; | |
class Darjeeling_Branch : public Kolkata_Branch | |
{ | |
public: | |
Darjeeling_Branch() | |
{ | |
setCount(0); | |
for(int i=0; i<100; i++) | |
{ | |
getEmployee(i).setLocation(Darjeeling); | |
} | |
} | |
}; | |
class Gosaba_Branch : public Kolkata_Branch | |
{ | |
public: | |
Gosaba_Branch() | |
{ | |
setCount(0); | |
for(int i=0; i<100; i++) | |
{ | |
getEmployee(i).setLocation(Gosaba); | |
} | |
} | |
}; | |
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.Name() == "Kolkata" || this->office_location.Name()=="Darjeeling" || this->office_location.Name()=="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 City; static city location; | |
cin >> City; | |
location = (City=="Kolkata") ? Kolkata : (City=="Darjeeling") ? Darjeeling : Gosaba; | |
this->setLocation(location); | |
return getTotalSalary(); | |
} | |
float salary=this->basic_salary; | |
salary += (0.5*salary); | |
salary += ((this->office_location.HRA() * this->basic_salary) + this->office_location.specialAllowance()) ; | |
return salary; | |
} | |
void employee::displayInfo() | |
{ | |
cout << "Name : \t" << this->getName() << endl; | |
cout << "ID : \t" << this->getID() << endl; | |
cout << "Branch: \t" << this->getLocation().Name() << 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() | |
{ | |
int count; | |
cout << "Enter the number of employees to add to Kolkata branch: "; | |
cin >> count; | |
Kolkata_Branch k_branch; | |
for(int i=0; i<count; i++) | |
{ | |
cout << "\nAdd details for employee #" << k_branch.getCount()+1 << ": " << endl; | |
k_branch.Add_employee(); | |
} | |
cout<< "\nList of employees added to Kolkata branch:" << endl; | |
k_branch.display_list(); | |
cout << "\nEnter the number of employees to add to Gosaba branch: "; | |
cin >> count; | |
Gosaba_Branch g_branch; | |
for(int i=0; i<count; i++) | |
{ | |
cout << "\nAdd details for employee #" << g_branch.getCount()+1 << ": " << endl; | |
g_branch.Add_employee(); | |
} | |
cout<< "\nList of employees added to Gosaba branch:" << endl; | |
g_branch.display_list(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment