Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer this assignment using C++. Thank! The purpose of this assignment is to exercise operator overloading: To do this assignment, you must extend the

Please answer this assignment using C++. Thank!

The purpose of this assignment is to exercise operator overloading:

To do this assignment, you must extend the code you have developed for Shape class and Rectangle class (see below) to implement the following:

Add two new member functions non-member operator overloading and member operator overloading for Rectangle class only

+ : (union of two rectangles) for two specified rectangle objects, take a union of both rectangles and return the area of the union of two rectangles.

If there is an intersection between two rectangles, it returns the sum of the areas of both rectangles subtracted by the intersected area.

If there is no intersection between two rectangles, it simply return the sum of the areas of both rectangles.

* : (intersection of two rectangles) for two specified rectangle objects, take an intersection of both rectangles and return the area of the intersection of two rectangles.

If there is an intersection between two rectangles, it returns the intersection of the areas of two rectangles.

If there is no intersection between two rectangles, it simply return 0.

Implement both non-member operator overloading and member operator overloading for the following operators for all the classes whenever applicable

class. Please note that you should implement both non-member and member operator.

Add a main driver to test:

4 intersection test cases:

Intersected and member operator overloading

Not ntersected and member operator overloading

Intersected and non-member operator overloading

Not ntersected and non-member operator overloading

4 union test cases:

Intersected and member operator overloading

Not ntersected and member operator overloading

Intersected and non-member operator overloading

Not ntersected and non-member operator overloading

Drawing two house pictures from PA2 using "

* The existing code can be found here: https://www.chegg.com/homework-help/questions-and-answers/using-c-please-write-function-move-rectangle-horizontally-right-left-original-point-thanks-q44614613?trackid=Lw_XEa1l

* Attachment

image text in transcribed

HERE IS THE CODE FROM PA2:

Circle.cpp

#include

#include "circle.h"

#include "shapes.h"

#include

using namespace std;

Circle::Circle()

{

radius=0;

}

void Circle:: setRadius(int r) {radius=r;}

void Circle:: draw() {

int circle_radius = 3; //

for (int i = 0; i

for (int j = 0; j

float distance_to_centre = sqrt(

(i - circle_radius) * (i - circle_radius) + (j - circle_radius) * (j - circle_radius));

if (distance_to_centre > circle_radius - 0.5 && distance_to_centre

cout

} else {

cout

}

}

cout

}

}

double Circle:: computeArea(){

double area =(3.14159*(radius*(radius)));

}

Circle.h

#ifndef OOHW2_CIRCLE_H

#define OOHW2_CIRCLE_H

#include

#include "shapes.h"

class Circle: public shapes {

public:

Circle();

void setRadius(int r);

void computeArea();

void draw();

private:

int radius;

};

#endif //OOHW2_CIRCLE_H

point.cpp

#include

#include "Point.h"

using namespace std;

Point::Point()

{

x=0;

y=0;

}

Point.h

#ifndef POINT_H

#define POINT_H

#include

class Point {

public:

Point();// default constructor

int x,y;

};

#endif

rectangle.cpp

#include

#include "rectangle.h"

#include "shapes.h"

using namespace std;

Rectangle::Rectangle() {

width=0;

height=0;

}

void Rectangle:: setHeight(int h) {height=h;}

void Rectangle :: setBase(int b) {width=b;}

void Rectangle :: draw() {

for (int i = 0; i

cout

}

cout

for (int j = 0; j

{

cout

for(int k=0;k

{

cout

}

cout

cout

}

for(int i=0;i

{

cout

}

cout

}

void Rectangle:: computeArea()

{

double area = height * width;

}

Rectangle.h

#ifndef RECTANGLE_H

#define RECTANGLE_H

#include

#include "shapes.h"

class Rectangle: public shapes {

public:

Rectangle(); //default constructor

void setHeight(int height);

void setBase(int base);

double computeArea();

void draw();

private:

int width;

int height;

};

#endif

shapes.cpp

#include "shapes.h"

#include

using namespace std;

shapes::shapes()

{

area=0.0;

circumference=0.0;

}

//coordinates

int shapes::getX() {return Point::x;}

int shapes::getY() {return Point::y;}

void shapes::setX(int newx) {Point::x=newx;}

void shapes::setY(int newy) {Point::y=newy;}

void shapes::draw(){}

//area

double shapes::getArea() {return area;}

void shapes:: setArea(double a) {area=a;}

//circumference

double shapes:: getCircumference() {return circumference;}

void shapes:: setCircumference(double c) {circumference=c;}

//methods

void shapes:: computeArea() {}

void shapes:: computeCircumference() {}

void shapes:: setLineType(char lineType) {lineTY=lineType;}

void shapes::moveBy(int space) {}

void shapes:: draw(int length) {}

void shapes:: draw(int width, int height) {}

shapes.h

#ifndef SHAPES_H

#define SHAPES_H

#include

#include "Point.h"

class shapes : public Point{

public:

//default constructor

shapes();

//Methods

virtual double computeArea();

virtual double computeCircumference();

virtual void moveBy(int space);

virtual void draw();

virtual void draw (int length);

virtual void draw(int width, int height);

//setter and getters

void setX(int newx);

void setY(int newy);

void setArea(double a);

void setCircumference(double c);

void setLineType(char lineType);

double getArea();

double getCircumference();

int getX();

int getY();

private:

char lineTY;

double area;

double circumference;

};

#endif

square.cpp

#include "square.h"

#include "rectangle.h"

#include

using namespace std;

Square::Square()

{

}

void Square::setSide(int side) {

setBase(side);

setHeight(side);

}

square.h

#ifndef SQUARE_H

#define SQUARE_H

#include

#include "rectangle.h"

class Square: public Rectangle{

public:

Square();

void setSide(int side);

};

#endif

triangle.cpp

#include "triangle.h"

#include "shapes.h"

#include

using namespace std;

Triangle::Triangle() {

base = 0;

height = 0;

}

void Triangle :: setHeight(int h) {height=h;}

void Triangle :: setBase(int b) {base=b;}

void Triangle:: draw()

{

int spaces=base/2;

cout

for(int i=0;i

{

cout

}

cout

cout

for(int i=0;i

{

cout

}

cout

for(int i=0;i

{

cout

}

cout

cout

for(int i=0;i

{

cout

}

cout

for(int i=0;i

{

cout

}

cout

cout

cout

for(int i=0;i

{

cout

}

}

double Triangle :: computeArea()

{

double area= (base*height)/2.0;

}

triangle.h

#ifndef OOHW2_TRIANGLE_H

#define OOHW2_TRIANGLE_H

#include "shapes.h"

#include

class Triangle: public shapes {

public:

Triangle();//default constructor

void setHeight(int h);

void setBase(int b);

void draw();

void computeArea();

private:

int base;

int height;

};

#endif //OOHW2_TRIANGLE_H

ABOVE IS MY CODE FROM THE LAST PA2!!! PLEASE MAKE SURE ITS IN C++, YOU READ THE PROBLEM, AND KNOW WHAT TO DELIVER!! PLEASE I DON'T KNOW WHERE TO START WITH THIS PROBLEM!!! PLEASE ANSWER IT ASAP!! AND YOU CAN CHANGE MY CODE FROM MY PA2 IN ORDER TO MAKE THE PROGRAM FUNCTION!! WHOEVER ANSWERS THIS THANK YOU SOOO MUCH!!!

Point: reference point Shape Double: area, circumference Getters and setters of attributes computeArea() computeCircumference()| Base class moveBy (anlnt) draw (length) draw (wd, ht) setLine Type(aChar) Abstract class Char: line type (*, _, +, 5, ...) Integers: width, Rectangle height char: line Type Implements the methods from Shape Inherits from Add setHeight(anlnt), Shape setBase(anlnt) Point: reference point Shape Double: area, circumference Getters and setters of attributes computeArea() computeCircumference()| Base class moveBy (anlnt) draw (length) draw (wd, ht) setLine Type(aChar) Abstract class Char: line type (*, _, +, 5, ...) Integers: width, Rectangle height char: line Type Implements the methods from Shape Inherits from Add setHeight(anlnt), Shape setBase(anlnt)

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_2

Step: 3

blur-text-image_3

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

How flying airoplane?

Answered: 1 week ago

Question

Is it clear what happens if an employee violates the policy?

Answered: 1 week ago