subject

In this exercise, you will be working with 3 classes to test your knowledge of inheritance and composition. The classes are Shape, Point and Rectangle. Shape includes a Point attribute to store the center coordinates. Rectangle inherits from Shape, therefore rectangle is a Shape and owns a Point center. You are asked to complete the following tasks:
Add the correct headers to main. cpp so the program will compile
Fix the function setCenter of Shape so that it takes two double variables as parameters and assigns them to x and y of the attribute "center".
Add a default constructor to rectangle. The default values are (0,0) for center, 0 for area, 0 for perimeter (hint: these are the default values for Shape), 1 for length and 1 for width.
Add a constructor with parameters (Point, double, double) to rectangle. The parameter Point should be used to set center, and the double parameters should be used to set length and width, in this order. The constructor should not accept parameters for area and perimeter, but it should call the private helper functions updateArea() and updatePerimeter() to set them to the correct values from length and width.
Overload getArea() and getPerimeter() for Rectangle, so that they call the private helper functions updateArea() and updatePerimeter() before returning the right value.
Overload the operator + for Rectangle. The resulting rectangle should have a width/length equivalent to the width/length of the two rectangles added together.
main. cpp
//Add necessary headers!
#include
#include "point"
#include "shape"
#include "rectangle"
using namespace std;
int main() {
return 0;
}
point. h
#ifndef POINT_H
#define POINT_H
class Point {
private:
double x;
double y;
public:
Point():x(0),y(0) {};
Point(double _x, double _y):x(_x),y(_y) {};
void setX(double _x) { x = _x; };
void setY(double _y) { y = _y; };
double getX() { return x; };
double getY() { return y; };
};

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 22:10
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≀ n ≀ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
question
Computers and Technology, 23.06.2019 08:30
All of these are true about using adhesive except: a. dissimilar materials can be joined. b. mixing tips are product and material specific. c. a specific application gun may be required. d. two-part adhesives are dispensed using two mixing tips
Answers: 3
question
Computers and Technology, 23.06.2019 16:00
An english teacher would like to divide 8 boys and 10 girls into groups, each with the same combination of boys and girls and nobody left out. what is the greatest number of groups that can be formed?
Answers: 2
question
Computers and Technology, 23.06.2019 18:00
Ramona enjoys her job because she is able to kids in an after school program. the work value ramona feels strongest about is a. leadership b. risk c. independence d. work with people select the best answer from the choices provided a b c d
Answers: 1
You know the right answer?
In this exercise, you will be working with 3 classes to test your knowledge of inheritance and compo...
Questions
question
Mathematics, 26.08.2019 18:30
question
Social Studies, 26.08.2019 18:30
Questions on the website: 13722363