Question: revise the client program ( main . cpp ) to test the other operators. They are - - ( pre and post decrement ) ,

revise the client program (main.cpp) to test the other operators. They are --(pre and post decrement),-(subtract Note: need to check for negative results and error if that is the case), the insertion operator (>> get dimensions from the terminal operator), and the other five comparison operators (==,!=,=,=, and >).
main.cpp:
#include
#include "rectangleType.h"
using namespace std;
int main()
{
rectangleType rectangle1(10,5);
rectangleType rectangle2(8,7);
rectangleType rectangle3;
rectangleType rectangle4;
cout "rectangle1: " rectangle1 endl;
cout "rectangle2: " rectangle2 endl;
rectangle3= rectangle1+ rectangle2;
cout "rectangle3: " rectangle3 endl;
rectangle4= rectangle1* rectangle2;
cout "rectangle4: " rectangle4 endl;
if (rectangle1> rectangle2){
cout "Area of rectangle1 is greater than the area "
"of rectangle2." endl;
} else {
cout "Area of rectangle1 is less than or equal to the area "
"of rectangle2." endl;
}
rectangle1++;
cout "After increment the length and width of "
"rectangle1 by one unit,
rectangle1: "
rectangle1 endl;
rectangle4=++rectangle3;
cout "New dimension of rectangle3: " rectangle3 endl;
cout "New dimension of rectangle4: " rectangle4 endl;
return 0;
}
rectangleType.h:
#ifndef H_rectangleType
#define H_rectangleType
#include
using namespace std;
class rectangleType
{
//Overload the stream insertion and extraction operators
friend ostream& operator(ostream&, const rectangleType &);
friend istream& operator>>(istream&, rectangleType &);
public:
void setDimension(double l, double w);
double getLength() const;
double getWidth() const;
double area() const;
double perimeter() const;
//Overload the arithmetic operators
rectangleType operator +(const rectangleType &) const;
rectangleType operator -(const rectangleType &) const;
rectangleType operator *(const rectangleType&) const;
//Overload the increment and decrement operators
rectangleType operator ++(); //pre-increment
rectangleType operator ++(int); //post-increment
rectangleType operator --(); //pre-decrement
rectangleType operator --(int); //post-decrement
//Overload the relational operators
bool operator ==(const rectangleType&) const;
bool operator !=(const rectangleType&) const;
bool operator =(const rectangleType&) const;
bool operator (const rectangleType&) const;
bool operator >=(const rectangleType&) const;
bool operator >(const rectangleType&) const;
//constructors
rectangleType();
rectangleType(double l, double w);
protected:
double length;
double width;
};
#endif
rectangleType.cpp:
revise the client program ( main . cpp ) to test

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 Programming Questions!