Skip to content

Instantly share code, notes, and snippets.

@ssube
Created April 26, 2012 15:40
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 ssube/2500458 to your computer and use it in GitHub Desktop.
Save ssube/2500458 to your computer and use it in GitHub Desktop.
#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;
}
}
#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