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

Design a function sperate() in your class with no arguments that returns a stand

ID: 3888964 • Letter: D

Question

Design a function sperate() in your class with no arguments that returns a standard array of four rectangles. Calculate the position and size of the four rectangles to correspond to the rectangle which the function was called on. Note that for uneven side length, the rectangles should differ in size by 1. Again, the corner points are part of a rectangle. An example is shown in the attachment.

already have:

class Rectangle{

private:

int d_x_start;

int d_x_end;

int d_y_start;

int d_y_end;

};

and in main.cpp

std::array<Rectangle,4> children = rVec[0].split();

for (auto child:children) {

child.print();

std::cout << std::endl;

}

how to write the seperate function?

Explanation / Answer

#include<iostream>
using namespace std;

class Rectangle
{
int len,brea;
public:
Rectangle(){};
Rectangle(int i,int j)
{
len=i;
brea=j;
}
void display()
{
cout<<"Length="<<len<<",Breadth="<<brea<<endl;
}
Rectangle operator +(Rectangle);
};
Rectangle Rectangle::operator +(Rectangle obj)
{
Rectangle temp;
temp.len=len+obj.len;
temp.brea=brea+obj.brea;
return(temp);
}
int main()
{
Rectangle p1(5,6),p2(7,8),p3(4,5),p4(6,3),p5;
cout<<"The First Rectangle is:";
p1.display();
cout<<" The Second Rectangle is:";
p2.display();
cout<<" The Third Rectangle is:";
p3.display();
cout<<" The Fourth Rectangle is:";
p4.display();
p5=p1+p2+p3+p4;
cout<<" Result Retangle is:";
p5.display();
}

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