In: Computer Science
In C++ write a program with a base class thet has a pure virtual function SALARY, and two derived classes. In the first derived class salary is increased by 20%, in the second derived class salary is increased by 30%
#include <iostream>
using namespace std;
class Base //Abstract base class
{
public:
float salary;
Base()
{
cout<<"Enter the initial salary
"<<endl;
cin>>salary;
}
virtual void SALARY() = 0; //Pure Virtual
Function
};
class Derived:public Base
{
public:
void SALARY()
{
salary = salary+(salary*20/100);
cout<<salary;
}
};
class Derived1:public Base
{
public:
void SALARY()
{ salary = salary+(salary*30/100);
cout<<salary;
}
};
int main()
{
Base *b; //creating objects
Derived d;
b = &d; //assigning the address of derived class object to base
class pointer
cout<<"Salary after incrementation"<<endl;
b->SALARY(); //calls the derived class SALARY function whose
address is assigned to Base class pointer.
return 0;
}