Question

In: Computer Science

In C++ write a program with a base class thet has a pure virtual function SALARY,...

  1. 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%

Solutions

Expert Solution

#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;
}


Related Solutions

1 What is a pure virtual function? Why would you define a pure virtual function? Give...
1 What is a pure virtual function? Why would you define a pure virtual function? Give an example of a pure virtual function. 2 When a function has an object parameter that it doesn't modify, what is the best way to declare the parameter (in the function signature), and why? 3 Show an example using a function with a string object parameter. a) When a class has objects as data members, why should its constructors use initialization lists (member and...
What will happen if you forget to implement the pure virtual function in the derived class?...
What will happen if you forget to implement the pure virtual function in the derived class? How the following are achieved in C++? static polymorphism and dynamic polymorphism. What is the advantage of defining the member functions outside a class rather than defining inside a class?
Write a C++ program where class 1 and class 2 (which is a base class) should...
Write a C++ program where class 1 and class 2 (which is a base class) should have a derived class (class 4 and class 5). Each of the derived classes should include at least 1 variable, 2 functions (one will be showing the function overriding case, the second one will be showing the function overloading case), 2 constructors (with default values, with parameters). Then class 3 (composition) (to relate class 1 and class 2) should include 3 variables (first variable...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.
Write a C++ program that creates a base class called Vehicle that includes two pieces of...
Write a C++ program that creates a base class called Vehicle that includes two pieces of information as data members, namely: wheels (type int) weight (type float) Program requirements (Vehicle class): Provide set and a get member functions for each data member. Your class should have a constructor with two parameters (one for each data member) and it must use the set member functions to initialize the two data members. Provide a pure virtual member function by the name displayData()...
How to write a Java program that has a base class with methods and attributes, subclasses...
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions:...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions: getArea() setArea() printArea() Create classes to inherit from the base class Circle Square Rectangle Both implement the functions derived from the abstract base class AND must have private variables and functions unique to them like double Radius double length calculateArea() Use the spreadsheet info.txt read in information about the circle, rectangle, or square text file: circle   3.5   square   3   rectangle   38   36 circle   23  ...
This is in C# on visual Basic Write a base class that has two property members:...
This is in C# on visual Basic Write a base class that has two property members: name and contact and one method member: CalculateFinalGrade(). must be an Abstract class method must be by its child class. (1 point) For example, Student {                 Property: StudentName                 Property: Contact                 Method: CalculateFinalGrade() } Write two child classes and , both of which inherit and implement any abstract member. needs a property for Quiz score and implements CalculateFinalGrade() to calculate final the...
C++ Write a program that has two functions. The 1st function is the main function. The...
C++ Write a program that has two functions. The 1st function is the main function. The main function should prompt the user for three inputs: number 1, number 2, and an operator. The main function should call a 2nd function called calculate. The 2nd function should offer the choices of calculating addition, subtraction, multiplication, and division. Use a switch statement to evaluate the operator, then choose the appropriate calculation and return the result to the main function.
Please write this program in C++ Write a program that           - a user-defined class Cuboid...
Please write this program in C++ Write a program that           - a user-defined class Cuboid which has the following elements:                    - default constructor (has no parameters)                    - constructor that has 3 parameters (height, length, width)                    - data members                              - height, length, width                    - member functions                              - to set the value of each of the data members - 3 functions                              - to get the value of each of the data members - 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT