Question: Language is C++ In this activity, you will implement a Rectangle class. The Rectangle class should accept two doubles, width and height that it should
Language is C++





In this activity, you will implement a Rectangle class. The Rectangle class should accept two doubles, width and height that it should maintain as private member variables, with the preserved invariant being that both side lengths must be greater than 0 . If at any point this invariant is violated, throw an std: : invalid_argument exception. The class should support two public and const member functions Width and Height that access the respective side lengths. The class should also support two public and void member functions width and Height that accept a double argument and mutate the respective private member variables. Lastly, the class should cinnort a rnnctnuhlir memher function rea that romnutec and returnc the area nf the nhiert \begin{tabular}{|l|l|} \hline Data Member & Description \\ \hline double width & Width of object. \\ \hline double height & Height of object. \\ \hline \end{tabular} Note: We haven't talked about constructors, but they are called at the point of declaration to build an object of a user-defined type. These are special functions that do not specify a return type and are named the same as the class. We will introduce constructors in more detail tomorrow. Your Rectang le type will specify a parameterized constructor. This means you cannot build a Rectang le object with the following statement: Rectangle r;. That will not work. Instead, you must build a Rectangle object by providing the parameterized constructor arguments for its width and height: Rectangle r(1,2);. The declaration of the parameterized constructor will be written as follows inside the class definition: Rectangle(double width, double height); The definition of the parameterized constructor will use a fully qualified name to specify that we are defining a function within the scope of Rectang le: \( \begin{array}{ll}1 & \text { Rectangle:: Rectangle(double width, double height) : width_(width), height_(height) }\{ \\ 2 & / / ~ . . . \text { Check whether width_ and height_ have taken on valid values. } \\ 3 & \}\end{array} \) The colon (:) following the parameter list and before the open-brace { is called the initializer list. Using the initializer list, we have initialized the private data members with the function's arguments for you. All you must do is check whether each data member's value is valid inside the function's body. This should be enough to get you started. rectangle-class-impl rectangle.cc rectangle.hpp driver.cc
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
