In this work you only need to implement “the Rectangle” and “Triangle” classes as derived classes of the base class Figure.
Each of these three classes (i.e., Figure, Rectangle, and Triangle) has two member functions, namely, erase() and draw(), which if properly implemented erase or draw a figure, respectively. You don’t need to implement the actual drawing or erasing. It will suffice to just print out a message to indicate which version of the erase() or draw() function being called at run time. For example, you can print a message like “Calling Figure::erase()”.
The base class Figure has three member functions:
(1) draw(), which doesn’t do anything other than print a message to identify itself when it is being called;
(2) erase(), which again doesn’t do anything other than print a message to identify itself when being called; and
(3) center(), which simply calls the erase() and draw() functions and prints a message indicating that it is being called.
There are 3 parts in this question.
PART I Implement the above three classes using separate compilation without including any virtual functions. Compile and then test your classes using the following test drive:
#include
#include “figure.h”
#include “rectangle.h”
#include “triangle.h”
using std::cout;
int main()
{
Triangle tri;
tri.draw();
cout << “nDerived class Triangle object calling” << ” center().n”;
tri.center();
Rectangle rect;
rect.draw();
cout << “nDerived class Rectangle object calling” << ” center().n”;
rect.center();
return 0;
}
Part II Make the draw() and erase() functions in the base class Figure virtual. Compile the project and test using the above test drive again.
Part III Observe and describe the differences in the outputs generated by Part I and Part II. Next explain why virtual functions can lead to such differences.
Question 2. Modify the Student class to add another dynamic array
string * list_classes;
This array manages the list of classes a student is currently taking. You’ll need to add the corresponding mutators and accessors and modify the existing constuctors, destructor, assignment operator, insertion operator, and the output() function to reflect this change.
Question3 Write a code and Use at least 10000 simulations to answer the following questions.
1. Suppose Xi for i=1, 2, 3… has Uniform(0,1) distribution.
A. Let M = min (n: X1 + X2 + … + Xn> 1). Find E (M) by simulation.
B. Let N = min (n+1: Xn > Xn+1). Find E (N) by simulation.
2. Toss a pair of fair dice. If you get any double stop and lose. Otherwise keep tossing. If any sum gets repeated before getting any doubles stop and win.
A. Find the probability of winning
B. Find the expected number of tosses per game.