Question: C++ programming Using the attached cpp and header files, create a test program that utilizes the files. Make sure you demonstrate all the capabilities of

C++ programming

Using the attached cpp and header files, create a test program that utilizes the files. Make sure you demonstrate all the capabilities of the class(es).

Grading criteria

Demonstrates

no-arg constructor

1 points

2 arg constructor

1 points

destructor

1 points

getArea

1 points

getPerimeter

1 points

getNumRectangles

1 points

getLength

1 points

getWidth

1 points

print

1 points

static variable

1 points

#include "Rectangle.h"

int Rectangle::numRectangles = 0;

Rectangle::Rectangle() { // a no-arg constructor setLength(1); setWidth(1); // default is 1 x 1 numRectangles++; } Rectangle::Rectangle(double l, double w) { setLength(l); setWidth(w); numRectangles++; } Rectangle::~Rectangle() { numRectangles--; } void Rectangle::printRectangle() { cout << "This rectangle is " << length << " x " << width << ". "; cout << "The area is " << getArea() << ", the perimeter is " << getPerimeter() << endl; } double Rectangle::getArea() const { return length * width; } double Rectangle::getPerimeter() const { return 2 * (length + width); } void Rectangle::setLength(double l) { if (l <= 0) { l = 1; } length = l; } void Rectangle::setWidth(double w) { if (w <= 0) w = 1; width = w; } void Rectangle::print() { printRectangle(); }

#ifndef RECTANGLE_H #define RECTANGLE_H #include using namespace std;

class Rectangle { private: double length; double width; void printRectangle(); static int numRectangles; public: Rectangle(); // no-arg constructor or "default" constructor Rectangle(double , double); // constructor - length and width ~Rectangle(); // destructor double getArea() const; double getPerimeter() const; void setLength(double l); void setWidth(double w); double getLength() const { return length; } double getWidth() const { return width; } int getNumRectangles() const { return numRectangles; } void print(); };

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!