[Solved] 1 Introduction Week S Lesson Focused Polymorphism Create Classes Using Inheritance Virtual Q37188319

1. Introduction This week’s lesson is focused on Polymorphism, for which you will create classes using inheritance and virtual functions. To start with, what is polymorphism? Polymorphism allows the name of a function to invoke a response on a base-class-type object and a different one in objects of a derived class, for which virtual functions are used. 1.1 Exercise 1 This exercise deals with using virtual functions, seeing how they act according to the object on which it is applied, which you will see in main). Create a file lab12pl.cpp and enter the following code class Employee protected: double sal; //salary base public: Employee (double s) sal-s;) double Payment() return sal; ) void prt() cout << “Salary-“<< Payment <<endl; > ; class Manager: public Employee ( double inc; public: Manager (double s, double i) : Employee(s) { inc – i; } double Payment () return sal*inc; ) void main() f Employee el (1500); Manager ml (1500, 1.5); cout << “Exercise about inheritance and polymorphism”<<endl; el.prt(); ml.prt() Compile the project and run it, observing what is printed on the console. Next, add the word virtual before the function Payment0 in the base class and run again the program. What happens this time? Why? Turn in your cpp file and a txt file called lab12pl.txt with your discussion from above to the Lab 12 folder in Canvas Show transcribed image text 1. Introduction This week’s lesson is focused on Polymorphism, for which you will create classes using inheritance and virtual functions. To start with, what is polymorphism? Polymorphism allows the name of a function to invoke a response on a base-class-type object and a different one in objects of a derived class, for which virtual functions are used. 1.1 Exercise 1 This exercise deals with using virtual functions, seeing how they act according to the object on which it is applied, which you will see in main). Create a file lab12pl.cpp and enter the following code class Employee protected: double sal; //salary base public: Employee (double s) sal-s;) double Payment() return sal; ) void prt() cout
Expert Answer
Answer to 1. Introduction This week’s lesson is focused on Polymorphism, for which you will create classes using inheritance and v… . . .
OR

