Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Construct a class named Rectangle that has two double-precision data members nam

ID: 3859314 • Letter: C

Question

Construct a class named Rectangle that has two double-precision data members named length and width.
The class should have the following class functions:
a) A constructor with the default values of 1 for both length and width data members
b) An accessor function named showData() to set a rectangle's length and width
c) A mutator function named setData() to set the rectangle's length and width
d) A class function named perimeter() that calculates and displays the rectangle's perimeter
e) A class function named area() that calculates and displays the rectangle's area
Include the Rectangle class constructed in a working C++ program and exercise all functions.

Explanation / Answer

Answer:

#include<iostream>
#include<math.h>

using namespace std;

class rectangle
{
int value_length;
int value_breadth;
public:
int calculatearea(int l,int b)
{
int area;
area = l * b;
cout << "Area = " << area << " ";
}

int calculateperimeter(int l,int b)
{
int input;
input= 2 * (l + b);
cout << "Perimeter = " << input<< " ";
}
};
int main()
{
int l,b;
rectangle r;
cout << "Enter value_length of rectangle ";
cin >> l ;
cout << "Enter value_breadth of rectangle ";
cin >> b ;
r.calculatearea(l,b);
r.calculateperimeter(l,b);

return 0;
}