Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following class class Shape { protected: float area; public: Shape(

ID: 666550 • Letter: C

Question

Consider the following class

class Shape

{

protected:

      float area;

public:

      Shape() { area = 0.0; }

};

a) (4) Add a pure virtual function to this class named ComputeArea. This function will not return any value.

b) (2) What type of base class have you just created?

c) (10) From this base class, write a publicly derived class named Triangle according to the following specifications:

i)   Provide state variables to store floating-point values for the base and height of the triangle. Pass these values into the constructor.

ii) Override the pure virtual function to compute and print the area of a triangle according to the following equation

      area = 0.5 * base * height

iii) Overload the addition operator to add two Triangle objects together as in the following application. For this operation, simply add the base from the first Triangle to the base from the second and similarly for the length member.

main()

{

   Triangle t1( 1.0, 2.0 );

   Triangle t2( 2.0, 3.0 );

   Triangle t3 = t1 + t2;

}

Explanation / Answer

#include #include #include using namespace std; class Point { protected: float x, y; public: Point(){} Point(float x1, float y1):x(x1),y(y1){} }; class Shape { protected: Point firstPoint, secondPoint; float area, perimeter; public: Shape(){} Shape(Point a, Point b) { firstPoint = a; secondPoint = b; } virtual float computeArea()=0; virtual float computePerimeter()=0; }; class Rectangle:public Shape { private: float thirdPoint, fourthPoint; public: Rectangle(Point a, Point b, Point c, Point d):Shape(a,b) { thirdPoint = c; fourthPoint = d; } float computeArea(); float computePerimeter(); }; class Triangle:public Shape { private: Point thirdPoint; public: Triangle(){} Triangle(Point a, Point b, Point c):Shape(a,b) { thirdPoint = c; } float computeArea(); float computePerimeter(); }; class Circle:public Shape { private: public: float computeArea(); float computePerimeter(); }; class Robot { private: float totalArea, TotalPerimeter; public: float computeAreaOfRobot(Shape& referenceShape); }; float Robot::computeAreaOfRobot(Shape& referenceShape) { referenceShape.computeArea(); } int main() { Robot robots; int input = rand() % 3; switch(input) { case 0: { coutx>>y; Point one(x,y); Point two(x,y); Point three(x,y); Point four(x,y); Rectangle rec(one, two, three, four); robots.computeAreaOfRobot(rec); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote