I\'m mostly having trouble with the last part... but help on the first two parts
ID: 3864561 • Letter: I
Question
I'm mostly having trouble with the last part... but help on the first two parts would be appreciated as I'm not sure I'm doing it correctly. This should to be done in C++ and none of it meant to be a full program.
1)
a)Write a class that represents a rectangle. Include the side lengths, and getters and setters for the top/bottom side length, left/right side length, and area.
b)Then, write a class that represents a window. Include the same length variables and getters/setters as the rectangle class, a bool variable "open" representing whether the window is open or shut, a function that switches between the window being open or shut, and a getter for open/shut state. All methods are public and all attributes are private.
c)Finally, rewrite the Window class to own a Rectangle object rather than providing its own dimensions. Think about: what can be removed, what has to stay to preserve public access to what is now provide by the internal Rectangle object, and how do those methods need to be changed?
Explanation / Answer
class Rectangle // Class Rectangle
{
private:
float length, width;
public:
Rectangle(); // Constructor
Rectangle(float len,float wid){
length=len;
width=wid;}
float getLength(){return length;}
void setLength(float len){length=len; };
float getWidth(){return width;}
void setWidth(float wid){width=wid;}
float area(float len,float wid) {
return (len*wid);
} // Area funcion
};
class Window{
private:
float length, width;
bool open;
Window();
Window(float len,float wid,bool state){
length=len;width=wid;open=state;}
void setWindowState(bool state){
open=state;}
bool getWindowState(){
return open;}
float getLength(){return length;}
void setLength(float len){length=len; };
float getWidth(){return width;}
void setWidth(float wid){width=wid;}
float area(float len,float wid) {
return (len*wid);
} // Area funcion
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.