Complete the class Rectangle that was given below 1Create a

Complete the class Rectangle that was given below.

1.Create a rectangle with a width of 80 and a height of 50 at x = 100, y = 200.
2.Call the translate method to move the rectangle 20 pixels in the x direction and 25 pixels in the y direction.
3.Print the new x and y in this format: x, y (Rectangle has methods to get x and y)
4.Call the grow method the rectangle to make the rectangle 10 units larger on both the left and right side leaving the height unchanged.

------------------------------------------------------------------------------------------------

public class ProcessRectangle
{
public static void main(String[] args)
{
Rectangle rec;
  
System.out.println(rec);
}

}

Solution

In this solution we have created a class with the name as \"rec\" to involve the translation (using trans() function ) and to change the length of the rectangle ( using grow() function ) and both the member functions are then called into the main function \"rec\"

#include<graphics.h>
#include<iostream.h>
class rec

{

int x1=100,y1=200,x2=80,y2=50;
public :

void translate(x1,x2,y1,y2)
{
cout<<\"Here goes the translation ratio of the given rectangle by 20 and 25 in the direction of x and y respectively:\ \";
cleardevice();
x1=x1+20;
y1=y1+25;
rectangle(x1,y1,x2,y2);
getch();
}

void grow(x1,x2,y1,y2)
{
cout<<\"Here goes the growing aspect of the given rectangle by increasing the left and right side of the rectangle by an amount of 10 units in the direction of x only :\ \";
cleardevice();
x1=x1-10;
x2=x2+20;
rectangle(x1,y1,x2,y2);
getch();
}

};

main()
{
int ch,gd=DETECT,gm;
initgraph(&gd,&gm,\"c:\\\\tc\\\\bgi\");
{
cleardevice();

rectangle(100,200,80,50);
cout<<\"here we can start calling the transformations on the rectangle\";

rec x;

x.trans(100,200,80,50);

x.grow(100,200,80,50);
}

Complete the class Rectangle that was given below. 1.Create a rectangle with a width of 80 and a height of 50 at x = 100, y = 200. 2.Call the translate method t
Complete the class Rectangle that was given below. 1.Create a rectangle with a width of 80 and a height of 50 at x = 100, y = 200. 2.Call the translate method t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site