Question: Please answer in C++ programming language! The problem : In today's POTD, we are going to explore virtual methods and simple polymorphism in C++. You

Please answer in C++ programming language!

The problem:

In today's POTD, we are going to explore virtual methods and simple polymorphism in C++. You will be writing two classes: Base and Derived, Derived is derived from Base. They will each have two methods, string foo() and string bar(). TODO: For Base, have foo() return "Sam I Am" For Derived, have foo() return "I will not eat them." For Base, have bar() return "Green Eggs" For Derived, have bar() return "And Ham" Note that one of these strings includes a period, but the others do not. Method foo() should be a regular method. Method bar() should be virtual. Create a virtual destructor for both classes. It won't do anything except keep the compiler from complaining. Do not create any namespaces for this problem. Sample Output Sam I Am Sam I Am I will not eat them. Green Eggs And Ham And Ham

Included:

main.cpp:

#include

#include "Base.h"

#include "Derived.h"

int main() {

Base *x1 = new Base();

Base *x2 = new Derived();

Derived *y1 = new Derived();

std::cout << x1->foo() << std::endl;

std::cout << x2->foo() << std::endl;

std::cout << y1->foo() << std::endl;

std::cout << x1->bar() << std::endl;

std::cout << x2->bar() << std::endl;

std::cout << y1->bar() << std::endl;

delete x1;

delete x2;

delete y1;

}

I need to make Base.h, Base.cpp, Derived.h and Derived.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!