Question: PLEASE ANSWER THE FOLLOWING QUESTIONS FOR THE ATTACHED CODE. C++ CODE using namespace std; #include #include Rectangle.h /*----------------------------------------------------------------------------- Name: default constructor for class Rectangle Purpose:
PLEASE ANSWER THE FOLLOWING QUESTIONS FOR THE ATTACHED CODE. C++ CODE

using namespace std;
#include
#include "Rectangle.h"
/*----------------------------------------------------------------------------- Name: default constructor for class "Rectangle"
Purpose: Initialize the dimensions of a rectangle to 0.0 -----------------------------------------------------------------------------*/
Rectangle::Rectangle() { Length_ = 0.0; Width_ = 0.0; }
/*----------------------------------------------------------------------------- Name: value constructor for class "Rectangle"
Purpose: Initialize the contents of a rectangle Receive: The length and width of a rectangle -----------------------------------------------------------------------------*/
Rectangle::Rectangle( double Len, double Wid ) { if (Len
if (Wid
/*----------------------------------------------------------------------------- Name: length
Purpose: Return the length of a rectangle Return: The length -----------------------------------------------------------------------------*/
double Rectangle::length() const { return Length_; }
/*----------------------------------------------------------------------------- Name: width
Purpose: Return the width of a rectangle Return: The width -----------------------------------------------------------------------------*/
double Rectangle::width() const { return Width_; }
/*----------------------------------------------------------------------------- Name: perimeter
Purpose: Return the length of the perimeter of a rectangle Return: The length of the perimeter -----------------------------------------------------------------------------*/
double Rectangle::perimeter() const { return 2.0 * Length_ + 2.0 * Width_; }
/*----------------------------------------------------------------------------- Name: area
Purpose: Return the area of a rectangle Return: The area -----------------------------------------------------------------------------*/
double Rectangle::area() const { // INCOMPLETE
return 0.0; }
/*----------------------------------------------------------------------------- Name: is_valid
Purpose: Test whether or not the rectangle is valid Return: The Boolean value for the result of the test -----------------------------------------------------------------------------*/
bool Rectangle::is_valid() const { return Length_ > 0.0 && Width_ > 0.0; }
/*----------------------------------------------------------------------------- Name: write
Purpose: Write a rectangle into the output stream -----------------------------------------------------------------------------*/
void Rectangle::write( ostream& Out ) const { Out
/*----------------------------------------------------------------------------- Name: read
Purpose: Read a rectangle from the input stream -----------------------------------------------------------------------------*/
void Rectangle::read( istream& In ) { char Ch; double Len, Wid;
In >> Ch; if (Ch != '[' || !In.good()) { In.setstate( ios::failbit ); } else { In >> Len >> Ch; if (Ch != ',' || !In.good()) { In.setstate( ios::failbit ); } else { In >> Wid >> Ch; if (Ch != ']' || !In.good()) { In.setstate( ios::failbit ); } else { if (Len
if (Wid
/*----------------------------------------------------------------------------- Name: operator
Purpose: Put a rectangle into an output stream Receive: The output stream The rectangle which is to be written Return: The output stream (for chaining) -----------------------------------------------------------------------------*/
ostream& operator
return Out; }
/*----------------------------------------------------------------------------- Name: operator>>
Purpose: Extract a rectangle from an input stream, where the rectangle is in the form '[ x.x, x.x ]' Receive: The input stream The rectangle which is to be read Return: The input stream (for chaining) -----------------------------------------------------------------------------*/
istream& operator>>( istream& In, Rectangle& Item ) { Item.read( In );
return In; }
/*----------------------------------------------------------------------------- Name: operator==
Purpose: Compare two rectangles for equality Receive: The two rectangles to be compared Return: The Boolean result of the comparison -----------------------------------------------------------------------------*/
bool operator==( const Rectangle& One, const Rectangle& Two ) { return (One.length() == Two.length() && One.width() == Two.width()) || (One.length() == Two.width() && One.width() == Two.length()); }
/*----------------------------------------------------------------------------- Name: operator!=
Purpose: Compare two rectangles for inequality Receive: The two rectangles to be compared Return: The Boolean result of the comparison -----------------------------------------------------------------------------*/
bool operator!=( const Rectangle& One, const Rectangle& Two ) { // INCOMPLETE
return false; }
Part A. (1 point each) Examine the definition of type "Rectangle", which is contained in the files named "Rectangle.*", then answer the questions below: 1. Give the declaration of the constructor for type "Rectangle". 2. If the constructor is called without any arguments, what default values are used for the dimensions of the rectangle? 3. How many bytes of memory are reserved for an object of type "Rectangle"? Explain your answer. 4. Give the declaration of function "perimeter". 5. Explain the use of "const" in the declaration of function "perimeter". 6. Give the declaration of function "operator==". 7. Explain the use of "const" in the declaration of function "operator==". 8. Examine the definition of function "read" and give an example of a properly formatted rectangle (a character sequence that will be accepted by "read"). 9. Under what circumstances will function "read" indicate that the operation was not successful
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
