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

-RE-POSTED- This is a C++ advance assignment: I need the program fully workable

ID: 3687183 • Letter: #

Question

-RE-POSTED-

This is a C++ advance assignment: I need the program fully workable in visual studio. I need the program complete 100%. Please do not answer unless correct. Once the code is fully workable paste code on this question board, then I will copy and paste into visual studio. Provide instructions on how to copy and paste properly if need be in order to run the program correctly. Complete extra credit below as well. Everything is provided.

Once again please do not answer unless 100% correct and the code works. Thanks.

Lab 13 Part 1 operator overloading

Programming Assignment 1:

1. Use attached class rectangleType

2. Overload the operators +, *, ==, !=, >>, and <<.

3. Overload the pre- and post-increment and decrement operators to increment and decrement, respectively, the length and width of a rectangle by one unit. (Note that after decrementing the length and width, they must be postive.)

4. Overload the binary operator - to subtract the dimensions of one rectangle from the corresponding dimensions of another rectangle. If the resulting dimensions are not positive, output an appropriate message and do not perform the operation.

5. The operators == and != are overloaded by considering the lengths and widths of rectangles. Redefine the functions to overload the relational operator by considering the areas of rectangles as follows: Two rectangles are the same, if they have the same area; otherwise, the rectangles are not the same.

6. Overload the remaining relational operators using similar definitions.

7. Use attached test program that tests various operations on the class rectangleType

Extra Info provided:

1. Lab13_Part_MainProgram.cpp

#include <iostream>

#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;
}

2. rectangleType.h

#ifndef H_rectangleType
#define H_rectangleType
  
#include <iostream>
using namespace std;

class rectangleType
{
//Overload the stream insertion and extraction operators

public:
void setDimension(double l, double w);
double getLength() const;
double getWidth() const;
double area() const;
double perimeter() const;

//Overload the arithmetic operators

//Overload the increment and decrement operators


//Overload the relational operators

//constructors
rectangleType();
rectangleType(double l, double w);

protected:
double length;
double width;
};

3. rectangleTypelmp.cpp

#include <iostream>
#include <cassert>

#include "rectangleType.h"

using namespace std;

void rectangleType::setDimension(double l, double w)
{
if (l >= 0)
length = l;
else
length = 0;

if (w >= 0)
width = w;
else
width = 0;
}

double rectangleType::getLength() const
{
return length;
}

double rectangleType::getWidth()const
{
return width;
}

double rectangleType::area() const
{
return length * width;
}

double rectangleType::perimeter() const
{
return 2 * (length + width);
}

rectangleType::rectangleType(double l, double w)
{
setDimension(l, w);
}

rectangleType::rectangleType()
{
length = 0;
width = 0;
}

Extra credit (5 Points)

Redo Assignment 1 by overloading the operators as nonmembers of the class rectangleType.

Please complete extra credit as well.

Explanation / Answer

overloading.cpp

//#include "stdafx.h"
#include <iostream>
#include <cassert>

using namespace std;

#define frz system("pause");

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 decrement operators
    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;

        //constructors
    rectangleType();
    rectangleType(double l, double w);

private:
    double length;
    double width;
};

void rectangleType::setDimension(double l, double w)
{
    if (l >= 0)
        length = l;
    else
        length = 0;

    if (w >= 0)
        width = w;
    else
        width = 0;
}

double rectangleType::getLength() const
{
    return length;
}

double rectangleType::getWidth()const
{
    return width;
}

double rectangleType::area() const
{
    return length * width;
}

double rectangleType::perimeter() const
{
    return 2 * (length + width);
}

rectangleType::rectangleType(double l, double w)
{
    setDimension(l, w);
}

rectangleType::rectangleType()
{
    length = 0;
    width = 0;
}


/**********************************************************************

Code the operator overload function definitions for pre and post
decrement and the relational operators prototyped in the class
definition here.

***********************************************************************/
bool rectangleType::operator <= (const rectangleType& rectangle) const
{
   return ( rectangle.area() <= rectangle.area());
}

bool rectangleType::operator < (const rectangleType& rectangle) const
{
   return ( rectangle.area() < rectangle.area());
}

bool rectangleType::operator >= (const rectangleType& rectangle) const
{
   return ( rectangle.area() >= rectangle.area());
}

bool rectangleType::operator > (const rectangleType& rectangle) const
{
   return ( rectangle.area() > rectangle.area());
}

rectangleType rectangleType::operator -- ()
{
         ++length;
         ++width;
      return *this;
}

rectangleType rectangleType::operator -- ( int u)
{
   rectangleType temp = *this;
   length++;
   width++;

   return temp;
}

ostream& operator<<(ostream& osObject,
                      const rectangleType& rectangle)
{
    osObject << "Length = " << rectangle.length
             << "; Width = " << rectangle.width;

    return osObject;
}

istream& operator>>(istream& isObject, rectangleType& rectangle)
{
    isObject >> rectangle.length >> rectangle.width;

    return isObject;
}


int main()
{

    rectangleType rectangle1(23, 45);              
    rectangleType rectangle2(12, 10);             
    rectangleType rectangle3;                     
    rectangleType rectangle4;                     

    cout << "rectangle1: " << rectangle1 << endl;                                 

    cout << "rectangle2: " << rectangle2 << endl;                                  
     

    if (rectangle1 <= rectangle2)                 
        cout << "rectangle1 less than or equal"
             << "to rectangle2." << endl;              
    else                                           
        cout << "rectangle1 greater than rectangle2." << endl;

   if (rectangle1 < rectangle2)                 
        cout << "rectangle1 less than rectangle2." << endl;
    else                                           
        cout << "rectangle1 greater or equal to rectangle2." << endl;

   cout << "Set both the length and width of rectangle3 to 5." << endl;

   cin >> rectangle3;
   cout << endl << "rectangle3: " << rectangle3 << endl;

   rectangle3--;

   cout << "After deccrement the length and width of "
       << "rectangle3 by one unit, rectangle3: "
         << rectangle3 << endl;

   rectangle4 = --rectangle3;

   cout << "New dimension of rectangle3: " << rectangle3 << endl;
   cout << "New dimension of rectangle4: " << rectangle4 << endl;

   rectangle4 = rectangle3--;

   cout << "New dimension of rectangle3: " << rectangle3 << endl;
   cout << "New dimension of rectangle4: " << rectangle4 << endl;

   if (rectangle4 >= rectangle3)                 
        cout << "rectangle4 greater than or equal to rectangle3." << endl;
    else                                           
        cout << "rectangle4 less than rectangle3." << endl;

   if (rectangle4 > rectangle3)                 
        cout << "rectangle4 greater than rectangle3." << endl;
    else                                           
        cout << "rectangle4 less than or equal to rectangle3." << endl;

   
   frz;
   return 0;
}

sample output

rectangle1: Length = 23; Width = 45                                                                                                                         
rectangle2: Length = 12; Width = 10                                                                                                                         
rectangle1 less than or equalto rectangle2.                                                                                                                 

rectangle1 greater or equal to rectangle2.                                                                                                                  
Set both the length and width of rectangle3 to 5.                                                                                                           
3                                                                                                                                                           
5                                                                                                                                                           
                                                                                                                                                            
rectangle3: Length = 3; Width = 5                                                                                                                           
After deccrement the length and width of rectangle3 by one unit,                                                                                            
rectangle3: Length = 4; Width = 6                                                                                                                           
New dimension of rectangle3: Length = 5; Width = 7                                                                                                          
New dimension of rectangle4: Length = 5; Width = 7                                                                                                          
New dimension of rectangle3: Length = 6; Width = 8                                                                                                          
New dimension of rectangle4: Length = 5; Width = 7                                                                                                          
rectangle4 greater than or equal to rectangle3.                                                                                                             
rectangle4 less than or equal to rectangle3.