[Project 1 expansion (selected)] design a rectangle class to calculate the area, perimeter, and object line of the rectangle and determine whether it is a square. Use a similar constructor to design the main () function and test the designed class.
[Cpp]
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Rectangle
{
Private:
Double length;
Double width;
Public:
Rectangle (): length (1), width (1 ){}
Rectangle (double len, double wid): length (len), width (wid ){}
// Rectangle (double len = 1, double wid = 1): length (len), width (wid ){}
Double area (void );
Double perimeter (void) {return 2 * (length + width );}
Double diagonal (void) {return sqrt (length * length + width * width );}
Bool square_or_not (void) {return length = width? True: false ;}
Void show_message (void );
};
// Rectangle: Rectangle (double len, double wid) {length = len; width = wid ;}
Double Rectangle: area (void)
{
Return length * width;
}
Void Rectangle: show_message (void)
{
Cout <"the length and width of the rectangle are:" <length <'\ t' <width <endl;
Cout <"perimeter:" <perimeter () <"area:" <area () <"diagonal line length:" <diagonal () <endl;
Cout <"Is it a square? "<Square_or_not () <endl;
}
Int main ()
{
Rectangle rect1;
Rect1.show _ message ();
Rectangle rect2 (3, 4 );
Rect2.show _ message ();
Return 0;
}
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Rectangle
{
Private:
Double length;
Double width;
Public:
Rectangle (): length (1), width (1 ){}
Rectangle (double len, double wid): length (len), width (wid ){}
// Rectangle (double len = 1, double wid = 1): length (len), width (wid ){}
Double area (void );
Double perimeter (void) {return 2 * (length + width );}
Double diagonal (void) {return sqrt (length * length + width * width );}
Bool square_or_not (void) {return length = width? True: false ;}
Void show_message (void );
};
// Rectangle: Rectangle (double len, double wid) {length = len; width = wid ;}
Double Rectangle: area (void)
{
Return length * width;
}
Void Rectangle: show_message (void)
{
Cout <"the length and width of the rectangle are:" <length <'\ t' <width <endl;
Cout <"perimeter:" <perimeter () <"area:" <area () <"diagonal line length:" <diagonal () <endl;
Cout <"Is it a square? "<Square_or_not () <endl;
}
Int main ()
{
Rectangle rect1;
Rect1.show _ message ();
Rectangle rect2 (3, 4 );
Rect2.show _ message ();
Return 0;
}