Question: 12 - Virtual and Pure Virtual Function C++ Advance Please only answer this question if your code is 100%. Include your answer in text so
12 - Virtual and Pure Virtual Function
C++ Advance
Please only answer this question if your code is 100%. Include your answer in text so I may copy and paste the code into visual studio. The same applies for the individual questions. Please only answer if you have the correct answer. Thank you.
1.Create class Person as following
class Person
{
private:
string name;
public:
Person();
virtual void getData();
virtual void print()=0;
void printName();
NOTE: that the print() function is pure virtual function. That means you have to implement print() function in derived class
2.Derive class Employee from Person class. And the following private member variables:
A.Salary
B.Title
3.Derive class Student from Person class, Add GPA as private member.
4.Override getData() and print() function in Employee and Student class
5.Write a test program, add 2 functions in the test program:
A.Call_getData() pass Person object by reference or pointer
B.Call_print() pass Person object by reference or pointer
C.Show the use of the virtual functions.
6.Write another test program to show in what case the slicing problem happens and how to fix slicing problem by using pointers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
