Created
April 26, 2012 15:40
-
-
Save ssube/2500458 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 <iostream> | |
#include "Rectangle.h" | |
Rectangle::Rectangle() : | |
m_Width(0), m_Height(0), m_Unit('#') | |
{ | |
// empty | |
} | |
Rectangle::Rectangle(int width, int height) : | |
m_Width(width), m_Height(height), m_Unit('#') | |
{ | |
// empty | |
} | |
int Rectangle::GetWidth() | |
{ | |
return m_Width; | |
} | |
void Rectangle::SetWidth(int val) | |
{ | |
m_Width = val; | |
} | |
int Rectangle::GetHeight() | |
{ | |
return m_Height; | |
} | |
void Rectangle::SetHeight(int val) | |
{ | |
m_Height = val; | |
} | |
long Rectangle::GetArea() | |
{ | |
// potential overflow | |
return ((long)m_Width * (long)m_Height); | |
} | |
int Rectangle::GetPerimeterMath() | |
{ | |
// another, but less likely | |
return (m_Width * 2) + (m_Height * 2); | |
} | |
int Rectangle::GetPerimeterUnit() | |
{ | |
return (2 * (m_Width * m_Height)) - 2; | |
} | |
void Rectangle::SetUnit(char val) | |
{ | |
m_Unit = u; | |
} | |
char Rectangle::GetUnit() | |
{ | |
return m_Unit; | |
} | |
void Rectangle::Print() | |
{ | |
for (int w = 0; w < m_Width; ++w) | |
{ | |
for (int h = 0; h < m_Height; ++h) | |
{ | |
cout << m_Unit; | |
} | |
cout << endl; | |
} | |
} |
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
#ifndef RECTANGLE_H | |
#define RECTANGLE_H | |
class Rectangle | |
{ | |
private: | |
int m_Width; | |
int m_Height; | |
char _unit; | |
public: | |
Rectangle(); | |
Rectangle(int, int); | |
int GetWidth(); | |
void SetWidth(int); | |
int GetHeight(); | |
void SetHeight(int); | |
long GetArea(); | |
int GetPerimeterMath(); | |
int GetPerimeterUnit(); | |
void SetUnit(char); | |
char GetUnit(); | |
void Print(); | |
}; | |
#endif // RECTANGLE_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment