In: Computer Science
This assignment will test your knowledge and skills in C++.
/* CAN BE IMPLEMENTED IN MULTIPLE WAYS ONE OF THE WAY IS BELOW */
/* NOTE SORTING IS BASED ON ASCENDING OF SALARY FOR DESCENDING CHANGE IT TO > TO < */
#include<iostream>
using namespace std;
class employee{
private:
string Name;
int ID;
double Salary;
public:
// methods to update data member of
employee class
void setName(string name){
this->Name =
name;
}
void setID(int ID){
this->ID =
ID;
}
void setSalary(double
Salary){
this->Salary
= Salary;
}
string getName(){
return
Name;
}
int getID(){
return ID;
}
double getSalary(){
return
Salary;
}
};
class manager: public employee{
private:
employee Managed_Employees[3]; //
CREATE ARRAY
string Department; // CREATE
VARIABLE
public:
void getEmployeesInfo();
void printInfo();
};
void manager::getEmployeesInfo(){ // GET EMPLOYEES INFO
cout<<"Enter 3 employees info\n";
// DECLARE VARIABLE
string name;
int id;
double salary;
for(int i = 0; i < 3; i++){
cout<<"\nEnter data for
"<<i+1<<" Employee\n";
cout<<"Enter Name: ";
cin >> name;
// SET ARRAY VALUE
Managed_Employees[i].setName(name);
cout<<"Enter ID: ";
cin >> id;
Managed_Employees[i].setID(id);
cout<<"Enter Salary: ";
cin >> salary;
Managed_Employees[i].setSalary(salary);
}
}
void manager::printInfo(){
// bubble sort
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3-i-1;
j++){
if(Managed_Employees[j].getSalary() >
Managed_Employees[j+1].getSalary()){
employee obj = Managed_Employees[j];
Managed_Employees[j] =
Managed_Employees[j+1];
Managed_Employees[j+1] = obj;
}
}
}
// display Info
cout<<"Name\tID\t\tSalary\n";
for(int i = 0 ; i < 3; i++){
cout<<Managed_Employees[i].getName()<<"\t"<<Managed_Employees[i].getID()
<<"\t\t"<<Managed_Employees[i].getSalary()<<"\n";
}
}
int main(){
manager obj; // CREATE OBJECT
obj.getEmployeesInfo(); // GET INFO
obj.printInfo(); // PRINT INFO
}
/* PLEASE UPVOTE */