Question
I need help writing 3 functions for the rest of my c++ code. The code is centered around making functions for creating a rectangle using
I need help writing 3 functions for the rest of my c++ code. The code is centered around making functions for creating a rectangle using a premade header file called Point.h. I have done a majority of the code and will include the header files and code. The 3 functions NEED to be in this certain form with these certain parameters. They are Point Rectangle::getCenter(); (Finds center of rectangle" , void Rectangle shift(double x, double y); "Move the rectangle by the given amount in x and y dimensions. Do so by moving the Point your rectangle is based on.", bool Rectangle::contains(Point& p);" Return true if indicated Point is within the rectangle (on edge counts as within)".
Point.h header file:
#ifndef POINT_H
#define POINT_H
class Point
{
public:
Point();
Point(double startX, double startY);
double getX() const;
double getY() const;
void setX(double newX);
void setY(double newY);
void translate(double xShift, double yShift);
bool isSameAs(const Point& other) const;
double distanceTo(const Point& other) const;
void print() const;
private:
double x;
double y;
};
#endif // POINT_H
Rectangle.h:
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include "point.h"
class Rectangle
{
private:
Point upperLeftVertex;
double height;
double width;
public:
Rectangle(Point& p1, double heightValue, double widthValue);
Rectangle(Point& p1, Point& p2);
Point getUpperLeftVertex() const;
double getWidth() const;
double getHeight() const;
double getArea();
double getPerimeter();
Point getCenter();
void shift(double x, double y);
bool contains(Point p);
};
#endif // RECTANGLE_H
Rectangle.cpp:
#include "Rectangle.h"
#include
#include
using namespace std;
Rectangle::Rectangle(Point& p1, double heightValue, double widthValue)
{
upperLeftVertex = p1;
height = heightValue;
width = widthValue;
}
Rectangle::Rectangle(Point &p1, Point &p2){
upperLeftVertex = p1;
height = abs(p1.getY() - p2.getY());
width = abs(p1.getX() - p2.getX());
}
Point Rectangle::getUpperLeftVertex() const{
return upperLeftVertex;
}
double Rectangle::getWidth() const{
return width;
}
double Rectangle::getHeight() const{
return height;
}
double Rectangle::getArea(){
return width * height;
}
double Rectangle::getPerimeter(){
return (width + height) * 2;
}
Point Rectangle::getCenter(){
//YOUR CODE HERE//
}
void Rectangle::shift(double x, double y){
//YOUR CODE HERE//
}
bool Rectangle::contains(Point& p){
//YOUR CODE HERE//
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started