In: Computer Science
I want to indent this c++ program
#include<iostream> using namespace std; class Rectangle{ private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; double getPerimeter() const; bool isSquare() const; }; void Rectangle::setWidth(double w){ width = w; } void Rectangle::setLength(double l){ length = l; } double Rectangle::getWidth() const{ return width; } double Rectangle::getLength() const{ return length; } // Added Method definitions double Rectangle::getArea() const{ return (width * length); } double Rectangle::getPerimeter() const{ return (2 * width + 2 * length); } bool Rectangle::isSquare() const{ if(width==length) return true; return false; } int main(){ Rectangle kitchen; Rectangle bedroom; Rectangle square; double totalArea, totalPerimeter; kitchen.setWidth(15); kitchen.setLength(12); bedroom.setWidth(10); bedroom.setLength(12); totalArea = kitchen.getArea() + bedroom.getArea(); cout << "Your house has total area: " << totalArea << " sq ft.\n"; totalPerimeter = kitchen.getPerimeter() + bedroom.getPerimeter(); cout << "Your house has total perimeter: " << totalPerimeter << " ft.\n"; square.setWidth(10); square.setLength(10); if(square.isSquare()){ cout << "This object is a square! Area: " << square.getArea(); } return 0; }
#include <iostream>
using namespace std;
class Rectangle
{
private:
double width;
double length;
public:
void setWidth(double);
void setLength(double);
double getWidth() const;
double getLength() const;
double getArea() const;
double getPerimeter() const;
bool isSquare() const;
};
void Rectangle::setWidth(double w)
{
width = w;
}
void Rectangle::setLength(double l)
{
length = l;
}
double Rectangle::getWidth() const
{
return width;
}
double Rectangle::getLength() const
{
return length;
}
// Added Method definitions
double Rectangle::getArea() const
{
return (width *length);
}
double Rectangle::getPerimeter() const
{
return (2 *width + 2 *length);
}
bool Rectangle::isSquare() const
{
if (width == length)
return true;
return false;
}
int main()
{
Rectangle kitchen;
Rectangle bedroom;
Rectangle square;
double totalArea, totalPerimeter;
kitchen.setWidth(15);
kitchen.setLength(12);
bedroom.setWidth(10);
bedroom.setLength(12);
totalArea = kitchen.getArea() + bedroom.getArea();
cout << "Your house has total area: " << totalArea << " sq ft.\n";
totalPerimeter = kitchen.getPerimeter() + bedroom.getPerimeter();
cout << "Your house has total perimeter: " << totalPerimeter << " ft.\n";
square.setWidth(10);
square.setLength(10);
if (square.isSquare())
{
cout << "This object is a square! Area: " << square.getArea();
}
return 0;
}