Answer to Question #220197 in C++ for sukki

Question #220197

You are given this class definition:

class Rectangle{
private:
    double side1, side2;    // Side lengths
public:
    Rectangle();    // Default constructor, set side lengths = 0
    Rectangle(double s1, double s2);    // Overloaded constructor
                                        // Set side lengths = s1 and s2
    void setSide(double s1, double s2); // Change side lengths to s1 & s2
    double area();  // Calculate the area of the rectangular
    double perimeter(); // Calculate the perimeter of the rectangular
    double diagonal();  // Calculate the length of the diagonal
    bool isSquare();    // Check if the rectangle is a square
};

Please complete this class.


1
Expert's answer
2021-07-24T07:05:23-0400
#include<iostream>
#include<bits/stdc++.h>
using namespace std;




class Rectangle{
private:
    double side1, side2;    // Side lengths
public:
    Rectangle();    // Default constructor, set side lengths = 0
    Rectangle(double s1, double s2);    // Overloaded constructor
                                        // Set side lengths = s1 and s2
    void setSide(double s1, double s2); // Change side lengths to s1 & s2
    double area();  // Calculate the area of the rectangular
    double perimeter(); // Calculate the perimeter of the rectangular
    double diagonal();  // Calculate the length of the diagonal
    bool isSquare();    // Check if the rectangle is a square
    
};


	Rectangle::Rectangle()
    {
    	side1 = 0;
    	side2 = 0;
	}
	
 	Rectangle::Rectangle(double s1, double s2)
	{
		side1 = s1;
		side2 = s2;
	}
	
	void Rectangle:: setSide(double s1, double s2)
	{
		side1 = s1;
		side2 = s2;
	}
	
	double Rectangle:: area(){
		return side1*side2;
	}
	
		double Rectangle:: perimeter()
	{
		return 2*(side1+side2);
	}
	
	double Rectangle:: diagonal()
	{
		return sqrt((side1*side1) + (side2*side2));
	}
	
	bool Rectangle:: isSquare()
	{
		return side1 == side2;
	}




int main()
{
	Rectangle r(10,5);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS