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

Write a program that use a class rectangle and has functions that compute area a

ID: 441786 • Letter: W

Question

Write a program that use a class rectangle and has functions that compute area and perimeter. Use Boolean functinon to determine if the rectangle is a square (if so have a destrucor display it has gone out of scope). 3 overloaded functions, one with no parameter, one with length, and one with both. 1.0 will be set to values if they are invald. Header file will be used to declare class. Test the class by declaring 5 objects. No parameters, valid parameters, only legth, invalid parameters, assinging one to the valid parameters. Display the length, width, area, perimeter, and whether or not they are a square. Here is my code so far: //Rectangle.h //Defintion of class Rectangle #ifndef RECTANGLE_H #define RECTANGLE_H class Rectangle { public: //overloaded constructor functions Rectangle (); Rectangle (length); Rectangle (length, width); //set functions void setLength( double ); void setWidth( double ); //get functions double getLength() const; double getWidth() const; //calculation functions double calcPerimeter() const; double calcArea() const; //test for square booleanSquare (); //print functions void printData(); private: double length; double width; }; #endif //Rectangle.cpp //Rectangle class member functions #include #include #include "Rectangle.h" using namespace std; Rectangle:Rectangle() { setlength(1.0); setwidth(1.0); } Rectangle:Rectangle() { setlength(); setwidth(1.0); } Rectangle:Rectangle() { setlength(); setwidth(); } Rectangle::double calcArea() { return length*width; } Rectangle::double calcPerimeter() { return (2*length)+(2*width); } void Rectangle::setLength (double l) { if (l >= 0 && l <= 20) length = l; else { length = 1.00; cout<<"The length entered is invalid and has been set to 1.00"; } } void Rectangle::setWidth (double w) { if (w >= 0 && w <= 20) width = w; else { width = 1.00; cout<<"The width entered is invalid and has been set to 1.00"; } } double Rectangle::getLength() const { return length; } double Rectangle::getWidth() const { return width; } Rectangle::booleanSquare() { if (length-width < .0001) //true //false ; } void printData() { //length //width //area //perimeter } //Program to calculate the perimeter and area of a rectangle #include #include "Rectangle.h" using namespace std; int main() { Rectangle object1; Rectangle object2 (7.1, 3.5); Rectangle object3 (6.3); Rectangle object4 (21, 22); Rectangle object5 = object2; void printData(); Rectangle object1 (5.4, 10.5); Rectnagle object4 (15.6, 15.6); void printData(); }

Explanation / Answer

//Rectangle.h
//Defintion of class Rectangle
#ifndef
RECTANGLE_H

#endif // RECTANGLE_H
#define RECTANGLE_H
class Rectangle {
public: //overloaded constructor functions
Rectangle ();
Rectangle (length);
Rectangle (length, width); //set functions
void setLength( double );
void setWidth( double ); //get functions
double getLength() const;
double getWidth() const; //calculation functions
double calcPerimeter() const;
double calcArea() const; //test for square
booleanSquare (); //print functions
void printData();
private:
double length;
double width;
};
#endif
//Rectangle.cpp //Rectangle class member functions
#include
#include
#include "Rectangle.h"
using namespace std;
Rectangle:Rectangle() {
setlength(1.0);
setwidth(1.0);
}
Rectangle:Rectangle() {
setlength();
setwidth(1.0);
}
Rectangle:Rectangle() {
setlength();
setwidth();
}
Rectangle::double calcArea() {
return length*width;
}
Rectangle::double calcPerimeter() {
return (2*length)+(2*width);
}
void Rectangle::setLength (double l) {
if (l >= 0 && l <= 20)
length = l;
else {
length = 1.00;
cout<<"The length entered is invalid and has been set to 1.00";
}
}
void Rectangle::setWidth (double w) {
if (w >= 0 && w <= 20)
width = w;
else {
width = 1.00;
cout<<"The width entered is invalid and has been set to 1.00";
}
}
double Rectangle::getLength() const {
return length;
}
double Rectangle::getWidth() const {
return width;
}
Rectangle::booleanSquare() {
if (length-width < .0001) //true //false ;
cout<<"it a square";
}
void printData() { //length //width //area //perimeter
cout<<"length:"<< getLength() ;
cout<<"length:"<< getWidth() ;
cout<<"area:"<< getLength()*getWidth() ;
cout<<"parameter:"<< getLength()+getWidth() ;
} //Program to calculate the perimeter and area of a rectangle
#include
#include "Rectangle.h"
using namespace std;
int main() {
Rectangle object1;
Rectangle object2 (7.1, 3.5);
Rectangle object3 (6.3);
Rectangle object4 (21, 22);
Rectangle object5 = object2;
void printData();
Rectangle object1 (5.4, 10.5);
Rectnagle object4 (15.6, 15.6);
void printData();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote