Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions