Created
July 15, 2013 00:09
-
-
Save BenMcH/5996703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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