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

in C++ Define a class type \"Quadrilateral\" that represents general 2-dimension

ID: 3587286 • Letter: I

Question

in C++

Define a class type "Quadrilateral" that represents general 2-dimensional shapes having four sides (for examplectangle, square, trapezoid, etc). You can determine a four-sided shape by the coordinates of its four vertices. Use another class type Point to represent a point on the shape (vertex for example). For the class type Point, add the necessary members as appropriate (coordinates data members, functions to read/write coordinates, constructors, etc). For the class Type Quadrilateral, include four vertices, in addition to the following function members: 1- constructors to initialize the shape 2- Accessor and Manipulator functions to read/write the vertex members. 3- A function to print out the information about the four vertices of the shape After this, define a new class type "Rectangle" that inherits from Quadrilateral. Make sure to add code to check for right angle when initializing or updating information of a Rectangle object. Add two new methods to the new type to determine its area and perimeter, respectively. Also, override the print function of the base type to also print the info about area and perimeter of the rectangle. Write a test program that instantiates a Rectangle object and prints its information to the screen

Explanation / Answer

Solution:

code:

#include<iostream>

using namespace std;

class Point {

private:

float x;

float y;

public:

Point() {

x = 0;

y = 0;

}

Point(int x, int y) {

this->x = x;

this->y = y;

}

int getX() {

return x;

}

int getY() {

return y;

}

void setX(int x) {

this->x = x;

}

void setY(int x) {

this->y = y;

}

};

class Qudrilateral {

private:

Point a,b,c,d;

public:

Qudrilateral() {

}

Qudrilateral(Point a, Point b, Point c, Point d) {

this->a = a;

this->b = b;

this->c = c;

this->d = d;

}

void printVertex() {

cout << "A: (" << a.getX() << ", " << a.getY() <<") ";

cout << "B: (" << b.getX() << ", " << b.getY() <<") ";

cout << "C: (" << c.getX() << ", " << c.getY() <<") ";

cout << "D: (" << d.getX() << ", " << d.getY() <<") ";

}

};

class Rectangle: public Qudrilateral {

private:

double slope(Point a, Point b) {

return (a.getY() - b.getY())/(a.getX() - b.getX());

}

private:

Rectangle(Point a, Point b, Point c, Point d) {

if(slope(a,b) == -1/slope(b,c) && slope(b,c) == -1/slope(c,d) && slope(c,d) == -1/slope(d,a))

Qudrilateral(a,b,c,d);

else

return;

}

};

int main(){

return 0;

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)