Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include "rectangle.h"
- //initialize static variable
- int Rectangle::count = 0;
- int Rectangle::getCount()
- {
- return count;
- }
- Rectangle::~Rectangle()
- {
- //cout << "destructor called" << endl;
- }
- Rectangle::Rectangle()
- {
- //cout << "default constructor called" << endl;
- //initialize length and width
- length = 1;
- width = 1;
- //count it
- count++;
- }
- //parameterized constructor
- Rectangle::Rectangle(double len, double wid)
- {
- //cout << "parameterized constructor called" << endl;
- //store len and wid into the private variables
- length = len;
- width = wid;
- //count it
- count++;
- }
- Rectangle::Rectangle(double value)
- {
- length = width = value;
- //count it
- count++;
- }
- double Rectangle::getPerim()
- {
- return 2 * (length + width);
- }
- double Rectangle::getArea() const
- {
- //cout << "in getArea length is " << length << endl;
- //double area; //local variable to getArea
- //area = length * width;
- //return area;
- //calculate and return the area
- return length * width;
- }
- bool Rectangle::setLength(double length)
- {
- //make sure len is good
- if (length <= 0) //bad data
- return false;
- //store len into private variable length
- this->length = length;
- this->length = length;
- return true;
- }
- /*
- //class function defintions go here
- bool Rectangle::setLength(double len)
- {
- //make sure len is good
- if (len <= 0) //bad data
- return false;
- //store len into private variable length
- length = len;
- return true;
- }
- */
- /*
- double Rectangle::getLength()
- {
- //return the value of length
- return length;
- }
- */
- void Rectangle::setWidth(double wid)
- {
- //store wid in width
- width = wid;
- }
Advertisement
Add Comment
Please, Sign In to add comment