Skip to content

Instantly share code, notes, and snippets.

@BenMcH
Created July 15, 2013 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenMcH/5996703 to your computer and use it in GitHub Desktop.
Save BenMcH/5996703 to your computer and use it in GitHub Desktop.
#include "Rectangle.h"
#include "iostream"
using namespace std;
void main()
{
cout<< "Welcome! This will give you information of a given rectangle or square.\nJust follow the instructions and you will see."<<endl;
double width, height;
cout << "Enter the width" << endl;
cin>>width;
cout<<"Enter the height"<<endl;
cin>>height;
Rectangle r(width,height);
cout << "Area: " << r.getArea()<<endl << "Perimeter: " << r.getPerimeter()
<< "\nDiagonal Length: " << r.getDiagonalLength() << "\nIs a square: "
<< boolalpha << r.isSquare() <<"\n\nPress enter to exit";
cin.ignore();
cin.ignore();
}
#include <cmath>
class Rectangle
{
public:
double width, height;
Rectangle(double, double);
double getArea();
double getPerimeter(){return (2* width) + (2*height);};
double getDiagonalLength(){return sqrt(pow(width,2.0) + pow(height, 2.0));};
bool isSquare(){return width == height;};
};
Rectangle::Rectangle(double a, double b)
{
width = a;
height = b;
}
double Rectangle::getArea()
{
return width * height;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment