Computers and Technology

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; };
};

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 18:00, lilkit
Is the following sentence true or false? during meiosis, the two alleles for each gene stay together.
Answers: 3
image
Computers and Technology, 23.06.2019 06:30, eddsworldfrantic
You have a small company and want to keep your costs low, but it is important your employees share data. which network would provide you with the most economical solution?
Answers: 1
image
Computers and Technology, 23.06.2019 12:50, tommy4260
Which syntax error in programming is unlikely to be highlighted by a compiler or an interpreter? a variable name misspelling a missing space a comma in place of a period a missing closing quotation mark
Answers: 1
image
Computers and Technology, 24.06.2019 12:00, log40
Jack is assisting his younger sibling mary with her mathematics assignment, which includes a study of the number system. jack explains to mary that whole numbers are counting numbers that could be used to record the number of fruits in a basket. which data type represents whole numbers? a. integers. b.floating-point numbers. c. strings. d.boolean
Answers: 1
Do you know the correct answer?
In this exercise, you will be working with 3 classes to test your knowledge of inheritance and compo...

Questions in other subjects:

Konu
World Languages, 04.05.2021 22:50
Konu
Mathematics, 04.05.2021 22:50