Assigned 9/15/2017-Due 9/18/2017 at NOON Introduction: In this in class assignme
ID: 3885984 • Letter: A
Question
Assigned 9/15/2017-Due 9/18/2017 at NOON Introduction: In this in class assignment, you will program a basic class for a rectangle. Here is what your class should include Private members length and width. Use the data type of double. . Default Constructor Overloaded constructor to accept length and width as arguments Public methods for . o Setting the length o Setting the width o Getting the length o Getting the width o Getting the area o Getting the perimeter In order to test your code, write a main function that Creates a first rectangle using the default constructor Sets the length and width of the first rectangle using the methods Displays the length, width, area, and perimeter of the first rectangle Creates a second rectangle using the overloaded constructor Displays the length, width, area, and perimeter of the second rectangle. Displays the sum of the perimeters Displays the difference between the areas · . This submission MUST be done with 3 different files. Put the class definition in rectangle.h, the implementation of the methods in rectangle.cpp, and the main function in main.cpp. WRITE A MAKEFILE THAT WILL COMPILE THIS. In rectangle.h and rectangle.cpp, use comments to label your methods as either Constructors, Accessors or Mutators. Recommendations: .Get the class and implementations of the methods working in main.cpp. Once when your code is working, then worry about separating them into the different filesExplanation / Answer
Driver:
#include <iostream>
#include "rectangle.h"
using namespace std;
int main() {
rectangle r1(5, 7);
cout << "Rectangle 1" << endl;
cout << " Length: " << r1.getLength() << endl;
cout << " Width: " << r1.getWidth() << endl;
cout << " Area: " << r1.getArea() << endl;
cout << " Perimeter: " << r1.getPerimeter() << endl;
rectangle r2();
r2.setLength(10);
r2.setWidth(3);
cout << "Rectangle 2" << endl;
cout << " Length: " << r2.getLength() << endl;
cout << " Width: " << r2.getWidth() << endl;
cout << " Area: " << r2.getArea() << endl;
cout << " Perimeter: " << r2.getPerimeter() << endl;
}
rectangle.cpp
#include "rectangle.h"
rectangle::rectangle() {
length = 0;
width = 0;
}
rectangle::rectangle(int l, int w) {
length = l;
width = w;
}
void rectangle::setLength(int l) {
length = l;
}
void rectangle::setWidth(int w) {
width = w;
}
int rectangle::getLength() {
return length;
}
int rectangle::getWidth() {
return width;
}
int rectangle::getArea() {
return length * width;
}
int rectangle::getPerimeter() {
return 2 * (length + width);
}
rectangle.h
#ifndef RECTANGLE_H
#define RECTANGLE_H
class rectangle {
private:
int length;
int width;
public:
rectangle();
rectangle(int l, int w);
void setLength(int l);
void setWidth(int w);
int getLength();
int getWidth();
int getArea();
int getPerimeter();
};
#endif
I hope this rectangle class will help