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 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 24.06.2019 13:30
Type the correct answer in the box. spell all words correctly. what is the default margin width on all four sides of a document? by default, the document has a margin on all four sides.
Answers: 1
question
Computers and Technology, 24.06.2019 15:30
What is the total number of time zones that can be configured to show by default in a calendar in outlook 2016?
Answers: 1
question
Computers and Technology, 24.06.2019 17:40
File i/o activity objective: the objective of this activity is to practice working with text files in c#. for this activity, you may do all code in the main class. instructions: create an app that will read integers from an input file name numbers.txt that will consist of one integer per record. example: 4 8 25 101 determine which numbers are even and which are odd. write the even numbers to a file named even.txt and the odd numbers to a file named odd.txt.
Answers: 3
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, 03.12.2019 21:31
question
Mathematics, 03.12.2019 21:31
Questions on the website: 13722367