Question: Shape.h #pragma once class Shape { public: virtual double area() const = 0; }; ShapeApp.cpp #include #include Shape.h #include Rectangle.h #include Triangle.h #include Square.h using

 Shape.h #pragma once class Shape { public: virtual double area() const

Shape.h

#pragma once class Shape { public: virtual double area() const = 0; }; 

ShapeApp.cpp

#include  #include "Shape.h" #include "Rectangle.h" #include "Triangle.h" #include "Square.h" using namespace std; int main() { const int shapeSize = 10; Shape *shapeArr[shapeSize]; int shapeCnt = 0; shapeArr[shapeCnt++] = new Rectangle(Point(1, 2), Point(3, 4)); shapeArr[shapeCnt++] = new Square(Point(2, 2), Point(3, 3)); shapeArr[shapeCnt++] = new Triangle(Point(1, 1), Point(2, 2), Point(3, 1)); for (int i = 0; i area(): " area()  

Please use getDistance while finding height and width, thanks for the effort! I got 2 hours left so any answers would be so helpful...

Exercise 1. (20 points) Write a C++ program that implements the classes whose UML diagrams are given below: Shape +areal): virtual double Point Triangle int Rectangle pintTopleft: Point ptotright: Point -width: int -height:int +Rectangle(Point, Point) tareal): virtual double +Point(int,int) +getX(): int +getY(): int +get Distance(Point, Point): static double pinti: Point pnt 2: Point pnt: Point -edge double -edge: double -edge double + Triangle(Point, Point, Point) +areal): virtual double Rectangle and Triangle classes should inherit from Shape, which only has the area() method that is defined as virtual to implement polymorphism. Rectangle class has two Point type members, corresponding to the upper left and lower right points of the rectangle constructed, that is, these points are expected to be supplied to the constructor of the class. Upon construction, you are advised to compute width and height of the rectangle using the get Distance(Point, Point) static method of the Point class. Triangle class has three Point members, given during the construction of the object. Similar to Rectangle, you should calculate the length of the edges of the triangle during construction. Point class is used by Rectangle and Triangle classes. Point represents a point in the Cartesian coordinate system using x and y integer distances from the origin. The class has two accessor methods, getX() and getY(), in order to allow read access to private x and y fields. Point also defines a static method get Distance(Point, Point), to calculate the distance between two given points. Remark: Add Square class into the design, wherever you think it's appropriate. The application that uses the classes above is coded in ShapeApp.cpp file. You normally do not need to modify this code, as well as the header files given. What you should code is a separate header (h) and source (.cpp) file for each class so that the whole application compiles and runs, giving the following output: ./output shapeArr[0]->area(): 4 shapeArr[1]->area(): 1 shapeArr(2)->area: 1

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!