Huzaifa ..OOP ASSIGNMENT 6
Huzaifa ..OOP ASSIGNMENT 6
Huzaifa ..OOP ASSIGNMENT 6
class Employee {
private:
string name;
const int id;
int service_length;
int allowance;
double salary;
public:
void calculateSalary() {
salary = 50000 + service_length * 5000 + allowance;
}
void updateServiceLength(int s) {
service_length = s;
calculateSalary();
}
void updateAllowance(int a) {
allowance = a;
calculateSalary();
}
};
int main() {
Employee emp("Huzaifa Ali Khan",1,2, 15000);
emp.displayDetails();
emp.updateServiceLength(6);
emp.updateAllowance(15000);
cout<<"------updated allowance and service length-----"<<endl;
emp.displayDetails();
return 0;
}
2. Change your program in (1) to generate unique employee id for
each employee along with total number of employees.
#include <iostream>
#include <string>
class Employee {
private:
string name;
const int id; // Unique ID for each employee
int service_length;
int allowance;
double salary;
// Static member to keep track of the total number of employees
static int employeeCount;
public:
// Constructor to initialize employee data
Employee(string n, int s, int a) : name(n), id(++employeeCount),
service_length(s), allowance(a) {
calculateSalary();
}
int main() {
Employee emp1("Huzaifa ",2, 5000);
emp1.displayDetails();
emp1.updateServiceLength(5);
emp1.updateAllowance(18000);
cout << "|------ Updated allowance and service length for Huzaifa Ali Khan
-----|" << endl;
emp1.displayDetails();
return 0;
}
class Employee {
private:
string name;
const int id; // Unique ID for each employee
int service_length;
int allowance;
double salary;
// Static member:
static int employeeCount;
public:
// Constructor to initialize employee data
Employee(string n, int s, int a) : name(n), id(++employeeCount),
service_length(s), allowance(a) {
calculateSalary();
}
int main() {
// Create (5 employees)
Employee emp1("Arraik", 3, 10000);
Employee emp2("ALI", 5, 15000);
Employee emp3("umar", 2, 8000);
Employee emp4("huzaifa", 4, 12000);
Employee emp5("ahmad", 6, 18000);
return 0;
}