Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

=+Describe an important trade-off you recently faced

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago