Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <stdexcept>
/** Class to store rectangles.
Every rectangle has two numbers which define the side lengths.
We provide methods to calculate various properties. **/
class Rectangle
{
private:
float side1, side2;
public:
Rectangle( float x, float y )
{
if( x<=0 || y<=0 )
throw std::range_error( "Sides must be positive values" );
side1 = x;
side2 = y;
}
float area() const
{
return side1 * side2;
}
float perimeter() const
{
return 2*side1 + 2*side2;
}
void scale( float scaleFactor )
{
if( scaleFactor <= 0 )
throw std::range_error( "Scale Factor must be positive" );
side1 = side1 * scaleFactor;
side2 = side2 * scaleFactor;
}
};