Question: Could you please help me with this lab? The main.cpp is attached at the bottom. Thank you In this lab youll be provided with a

Could you please help me with this lab? The main.cpp is attached at the bottom. Thank you

In this lab youll be provided with a Visual Studio project containing definitions for a parent class called Shape and two childen: Rectangle and Triangle. You will adapt the classes to use polymorphism.

Lab 6a: Getting Started

Download the code from Canvas (Files\Labs\Lab6.zip (or Lab6.7z) and re-write main() to create pointers and dynamically allocate variables of each type, e.g. to create a Shape pointer to a dynamically allocated Triangle object, you would use the following command:

Shape* sPtr = new Triangle(10,12,5);

Try calling draw( ) on each pointer-object combination. Remember that you can call a function through a pointer to an object using the syntax:

sPtr->draw();

Play around with the code until you can fill out the following table for regular (non-virtual) functions.

Object Type

Shape

Rectangle

Triangle

Pointer Type

Shape

Rectangle

Triangle

Lab 6b: Virtual Functions

Modify the draw( ) function to make it a virtual function. Then play around with the pointers in main( ) to fill out a fresh copy of the table.

Object Type

Shape

Rectangle

Triangle

Pointer Type

Shape

Rectangle

Triangle

Lab 6c: Pointer Arrays

Modify Shapes copy of the draw( ) function to make it a pure virtual function.

Re-write main( ) to create a statically-allocated 4 x 4 array of Shape pointers.

Dynamically allocate variables for each of the pointers in your array to point at; you can choose what types of objects to store at each location, but make sure to include both Rectangles and Triangles.

Adapt main( ) so that it will prompt the user 3 times for a set of co-ordinates and will then display the object stored at that location in your array. (For the purposes of the lab, you can assume the user doesnt give you bad co-ordinates).

#include

#include "rectangle.h"

#include "triangle.h"

using namespace std;

int main()

{

cout << "I need to be written by you! ";

system("PAUSE");

return 0;

}

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!