,can anyone help me to find what's the problem with this programming code! it's work so well !but there two methoods didn't work ((the max salary method and sum salary )) at (main)... Especially the output results .
there's no errors \ i have no idea how to solve it but i am gonna to drop my code with my assignment and i hopfully to help me.
thank you!
#include<iostream.h>
#include<string.h>
using namespace std;
class Employee {
string eNAME;
int eNO;
double eSALARY;
double eSSN;
public:
Employee(){
}
Employee(string eNAME,int eNO,double eSALARY,double eSSN){
//this->ATTRIBUTE: refers to class attribute
this->eNAME=eNAME;
this->eNO=eNO;
this->eSALARY=eSALARY;
this->eSSN=eSSN;
//cout <<"[*] Inside Employee\n";
}
void setNAME(string eNAME){
this->eNAME=eNAME;
}
string getNAME(){
return eNAME;
}
void setNO(int eNO){
this->eNO=eNO;
}
int getNO(){
return eNO;
}
void setSALARY(double eSALARY){
this->eSALARY=eSALARY;
}
double getSALARY(){
return eSALARY;
}
void setSSN(double eSSN){
this->eSSN=eSSN;
}
void increaseSALARY(double value){
double first = this->getSALARY();
double last = first+value;
this->setSALARY(last);
cout<<" [+] Salary has been Successfully increased by "<<value<<" , Salary now Equal = "<<last<<endl;
}
bool isequal(Employee Emp){
double sal,sal2;
sal = this->getSALARY();
sal2 = Emp.getSALARY();
if(sal == sal2){
cout<<" [+] True: Both salaries are equal\n";
return true;
}
else{
cout<<" [-] False: Both salaries are not equal\n";
return false;
}
}
~Employee(){
//cout<<"[-] Inside Employee Destructor but obviously there is no pointer to DESTRUCT.\n";
}
};
class Department{
string dNAME;
int dNO;
Employee *employees; // number of Employees working in the Department
int size;
public:
Department(string dNAME,int dNO,int z){
int size=z;
employees=new Employee[size];
}
void setDname(string dNAME){
this->dNAME=dNAME;
}
string getDname(){
return dNAME;
}
void setDNO(int dNO)
{
this->dNO=dNO;
}
int getDNO(){
return dNO;
}
void setEmployee(Employee *emp){
int id=emp->getNO();
for(int i=0;i<size;i++ )
if(this->employees[i].getNO() == id){
cout<<" [-] Sorry, this employee already exist.\n";
}
else{
cout<<" [+] Employee has been set successfully.\n";
}
} //End of setEmployee methood
Employee *getEmployee(){
return employees;
}
Employee *getEmpByEno(int eNO){
Employee *current=NULL;
for(int i=0;i<size;i++)
if(employees[i].getNO()==eNO)
current=&employees[i];
return current;
}
Employee *getEmpByName(string nam){
Employee *eobj=new Employee[size];
int j=0;
for(int i=0;i<size;i++)
if(employees[i].getNAME()==nam)
{
eobj[j]=employees[i];
j++;
}
if(j==0)return 0;
return eobj;
}
float maxSalary(){
float max=0;
for(int i=0;i<size;i++){
if(employees[i].getSALARY()>max){
max = employees[i].getSALARY();
}
}
return max;
}
double sumSalary(){
double total = 0;
for(int i=0;i<size;i++){
total += employees[i].getSALARY();
}
return total;
}
~Department(){
//cout<<"[-] Inside Department Destructor but obviously there is no pointer to DESTRUCT.\n";
}
}; // initializer
bool equal(Department dep1, Department dep2){
if(dep1.sumSalary()==dep2.sumSalary()){
cout<<" [+] Both departments sum of salary are equal.\n";
return 1;
}
else{
cout<<" [+] Both departments sum of salary are not equal.\n";
return 0;
}
}
main()
{
const int size=5;
Employee emp1("narjis",12,300,4000);
Employee emp2("Ali",10,233,5000);
Department dep1("CSE",2,size);
Department dep2("AFS",3,size);
emp1.isequal(emp2);
emp1.increaseSALARY(500);
emp2.increaseSALARY(300);
dep1.maxSalary();
cout<<dep1.maxSalary()<<endl;
cout<<equal(dep1,dep2);
}