Answer to Question #179048 in C++ for Hari bashkar

Question #179048

Develop a code for the multiple inheritance diagram given below

·         The experience details class consisting of data members such as name and total experience.

·         The salary details class consisting of data members such as salary.

·         The education details class consisting of data members such as degree.

·       The promotion class consisting of member function promote() to find the employee promotion for higher grade on satisfying the condition total experience to be greater than 10 and salary to be greater than Rs. 20,000 and the degree qualification to be “PG”, print "PROMOTED FOR HIGHER GRADE". otherwise the employee is not eligible for promotion, print "PROMOTION IS NOT ELIGIBLE".



1
Expert's answer
2021-04-07T02:35:06-0400
#include<iostream>
#include <string>
using namespace std;
// Base class
class Experience{
   int total;
   string name;
public:
   Experience() {};                     // default constructor
   Experience(string Name, int Total){  // parameterized constructor  
       name = Name;
       total = Total;
       }
   int getTotal(){ return  total;}
   string getName(){return name; }
};
// Derived class
class Salary : public Experience {
   double salary;
public:
    Salary() {};                   // default constructor
    Salary(string Name, int Total, double s);  // parameterized constructor
    double getSalary(){ return salary;    };
};
Salary::Salary(string Name, int Total, double s):Experience(Name, Total) {
    salary = s;
    getName();
}
// Derived class
class Education : public Experience {
 string degree;
public:
    Education() {};                   // default constructor
    Education(string Name, int Total, string d);  // parameterized constructor
    string getDegree(){return degree;     }
};
Education::Education(string Name, int Total, string d):Experience(Name, Total) {
    degree = d;
}
// Derived class
class Promotion : public Salary, public Education{
public:
   Promotion();
   Promotion(string Name, int Total, double s, string d);
   void advance () {
        if(Salary::getTotal() >  10 && Salary::getSalary() >= 20000 && getDegree()=="PG" )
              cout<<"PROMOTED FOR HIGHER GRADE "<<endl;
      else
            cout<<"PROMOTION IS NOT ELIGIBLE "<<endl;;
    }
    void display(){
        cout<<endl;
        cout<< Salary::getName()<<"  "
        <<Salary::getTotal()<<" "
        << Salary::getSalary()<<"  "
        << getDegree()<<endl;
    }
};
 Promotion::Promotion(string Name, int Total, double s, string d): Salary(Name, Total, s), Education( Name, Total, d)
 {  }
 
int main() {
  Promotion obj1("Ann", 10, 30000,"PG");
  obj1.display();
  obj1.advance();
 
  Promotion obj2("Alex", 11, 30000,"PG");
  obj2.display();
  obj2.advance();
 
  Promotion obj3("Alan", 11, 30000,"St");
  obj3.display();
  obj3.advance();
 
  Promotion obj4("Leo", 11, 10000,"PG");
  obj4.display();
  obj4.advance();

   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS