9.12 (Enhancing Class Rectangle) Create a more sophisticated Rectangle class tha
ID: 3537177 • Letter: 9
Question
9.12 (Enhancing Class Rectangle) Create a more sophisticated Rectangle class than the one you
created in Exercise 9.11. This class stores only the Cartesian coordinates of the four corners of the
rectangle. The constructor calls a set function that accepts four sets of coordinates and verifies that
each of these is in the first quadrant with no single x- or y-coordinate larger than 20.0. The set function
also verifies that the supplied coordinates do, in fact, specify a rectangle. Provide member functions
that calculate the length, width, perimeter and area. The length is the larger of the two dimensions.
Include a predicate function square that determines whether the rectangle is a square.
9.13 (Enhancing Class Rectangle) Modify class Rectangle from Exercise 9.12 to include a draw
function that displays the rectangle inside a 25-by-25 box enclosing the portion of the first quadrant
in which the rectangle resides. Include a setFillCharacter function to specify the character out of
which the body of the rectangle will be drawn. Include a setPerimeterCharacter function to specify
the character that will be used to draw the border of the rectangle. If you feel ambitious, you might
include functions to scale the size of the rectangle, rotate it, and move it around within the designated
portion of the first quadrant.
note: i have done 9.11 tried 9.12 but has errors.
Explanation / Answer
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
class rectangle
{
public:
int x1,y1,x2,y2,x3,y3,x4,y4;
rectangle(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
check(x1,y1,x2,y2,x3,y3,x4,y4);
}
void check(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
if(x1>20 && y1>20 && x2>20 && y2>20 && x3>20 &&y3>20 && x4>20 && y4>20)
cout<<"all the cordinates are above 20"<<endl;
calc(x1,y1,x2,y2,x3,y3,x4,y4);
}
void calc(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{ int d1,d2;
d1=pow((x2-x1),2)+pow((y2-y1),2);
d1=sqrt(d1);
cout<<sqrt(d1)<<endl;
d2=pow((x3-x1),2)+pow((y3-y1),2);
d2=sqrt(d2);
cout<<"area is "<<sqrt(d1)*d2<<endl;
cout<<"perimeter is"<<2*(d1+d2)<<endl;
}
};
int main(){
rectangle obj(111,21,31,41,51,61,71,81);
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.