Академический Документы
Профессиональный Документы
Культура Документы
Questions:
represent a rectangle
What are the functions of this class?
Use the declaration below as a guide
What do we call functions of a class?
class Rectangle {
What arguments do they accept?
public: What are their return types?
void setWidthHeight (int,int); What are the access specifiers?
int area (void); Why do we use them?
int perimeter(void);
Why do we need the setWidthAndHeight()
private:
method?
int width_, height_;
}; Can you see any problems with this class?
Where should we place the
implementation of the class?
Create an executable that
What do we need to alter in
uses the class to compute the
CMakeLists.txt to compile the executable?
area and perimeter of several
rectangles
Create a class for generating an array of random numbers (doubles)
Hint: http://www.cplusplus.com/reference/random/uniform_real_distribution/
Questions:
What are the pinch points here, how to ensure the program does not cause a
segmentation fault?
What is a segmentation fault?
Why do we have N in constructor?
Who is responsible for defining the max length of the array?
Is there any way to make this allocation dynamic?
Write a function that accepts an Array of
Rectangles and returns the combined area of
all Rectangles in the array
Hint:
Use the two previous examples to build upon
Use the declaration of rectangle class below to
work on polymorphism.
class Rectangle {
public:
Rectangle();
void setWidthHeight (double width, double height);
double area ();
double perimeter();
private:
double width_, height_;
};
How could we use polymorphism to allow the class
to be used for a square?