Home / Expert Answers / Computer Science / nbsp-nbsp-a-construct-a-c-class-named-rectangle-that-has-double-precision-data-members-n-pa533

(Solved):     a. Construct a C++ class named Rectangle that has double-precision data members n ...



a. Construct a C++ class named Rectangle that has double-precision data members named length and width.
b. The class should h

 

f/ include an implementation of double perimeter() accessor function here
// accessor calculating area double Rectangle:: are

 

a. Construct a C++ class named Rectangle that has double-precision data members named length and width. b. The class should have member (accessor) functions named double perimeter (), double area () and double diagonal () to calculate a rectanglés perimeter, area, and diagonal, c. a member (mutator) function void setData (double, double) to set a rectangle's length and width, d. and a member (accessor) function void showData() that displays a rectangle's length, width, perimeter (using double perimeter()), area (using double area()), and diagonal (using double diagonal()). Display data with 1 decimal point of accuracy. e. Include the Rectangle class constructed above in a working \( \mathrm{C}++ \) program. Complete the solution below. SOLUTION: public: Rectangle(double, double); I/ constructor with default length and width of \( 0.0 \) double perimeter(); \( \quad \) /f accessor calculating perimeter double area() ; \( \quad \) /I accessor calculating area double diagonal); \( \quad \) (f accessor calculating diagonal. void setData(double, double); void showData(); \( \quad \) (y accessor displaying rectangle info \}; If implementation section If Constructor Rectangle:: Rectangle(double len \( =0 . \theta \), double wid \( =0 . \theta) \) \{ length = len; width = wid; 8 f/ include an implementation of double perimeter() accessor function here // accessor calculating area double Rectangle:: area() \{ return (length * width); 3 If include an implementation of double diagonal() accessor function here \( f / \) diagonal \( =\operatorname{sqrt}( \) length*length \( + \) width*width \( ) \) If include an implementation of void setData(double len, double wid) mutator function here I) include an implementation of void showData() accessor function here int main() Rectangle a, b, c(3.6,4.5); \( 1 f \) declare three objects double length, width; cout «< "InInfo on Rectangle a: \( \backslash n^{\prime \prime} ; \) a. showData(); /f include code to display Rectangle \( c \) If include a do-while loop to allow user to enter length and width II populate Rectargle b using setData() mutator If display Rectangle b \( f f \) terminate the \( 10 o p \) when negative value of length or width is entered return \( 9 ; \) 3 My C++ Progran copied and pasted from MSVisual Studio


We have an Answer from Expert

View Expert Answer

Expert Answer


Method to compute diagonal of a rectangle : diagonal() method : double Rectangle::diagonal() { return sqrt(length*length + width *width
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe