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: 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.
Write a c++ program to convert any decimal number to either binary base  or Hex base...
Write a c++ program to convert any decimal number to either binary base  or Hex base number system. Test your program with the followings: Convert 15 from decimal to binary.  Convert 255 from decimal to binary. Convert BAC4 from hexadecimal to binary Convert DEED from hexadecimal to binary.  Convert 311 from decimal to hexadecimal. Convert your age to hexadecimal.
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT