Appendix A (continued)

Maintenance Task for Treatment 1

Task for Low Complexity Version

The context of this question is applications dealing with representation of geometric shapes. We have implemented a class called QUADRI_1, to represent a quadrilateral, and a class called POINT to represent the (x,y) coordinates of a point P.


The class declarations are available in file Wclass1.Hand methods implementation is available in file Wmethod1.cpp. Given the four corner points [p1, p2, p3, p4] of the quadrilateral, this class allows client classes to set the value of each vertex (corner point), and examine the value of each vertex. (Note that [p1, p2, p3, p4] represent the points in a cyclical sequence)

Maintenance Requirements:

(Please remember to note the starting time and the ending time)

You have to extend this class to provide the following two features. (You are free to write any new methods or change any of the existing methods as you deem necessary, but please document all changes.)

1)Determine the perimeter of the quadrilateral: The Perimeter can be computed as explained below: assume pa and pb are two adjacent points, with coordinates (xa,ya) and (xb,yb) respectively

  • length of each side = Square root ((xa - xb)**2 + (ya - yb)**2).

Perimeter is summation of the lengths of all four sides

2)Determine the area of the quadrilateral, using the procedure described below:

  • Drawing a line between points (p1) and (p3) will divide the quadrilateral into 2 triangles, as shown.
  • Now let (p1), (p2) and (p3) be one triangle called “triangle1”. Then (p3), (p4), and (p1) will be the other triangle called “triangle2”.
  • Compute the area of each of triangle. The area of a triangle can be computed by using the formula,

Area = Square root(s*(s-a)*(s-b)* (s-c)) where,

s = (a+b+c)/2, and a, b, c are the lengths of the three sides of the triangle.

  • The area of the quadrilateral is the summation of the areas of both the triangles.
  • You need to test the program for Question 1 using the following main function (to be typed by you; can be changed if necessary), and the test data shown in the main function:

int main ()

{

POINT p1(10,7);

POINT p2(8,12);

POINT p3(23,17);

POINT p4(25,5);

QUADRI_1 quad1(p1, p2, p3, p4); //first quadrilateral

quad1.display();

//Perimeter should be 48.49; Area should be 130.5

POINT p1a(5,3);

POINT p2a(5,11);

POINT p3a(14,16);

POINT p4a(17,6);

QUADRI_1 quad2(p1a, p2a, p3a, p4a); //second quadrilateral

quad2.display();

//Perimeter should be 41.11; Area should be 100.5

return 0;

}

Task for High ComplexityVersion

The context of this question is applications dealing with representation of geometric shapes. We have implemented a class called QUADRI_1, to represent a quadrilateral.


The class declaration is available in file Nclass1.H and methods implementation is available in file Nmethod1.cpp. Given the four corners [(x1,y1), (x2,y2), (x3,y3), (x4,y4)] of the quadrilateral, this class allows client classes to set the value of each vertex (corner), and examine the value of each vertex. (Note that [(x1,y1), (x2,y2), (x3,y3), (x4,y4)] represent coordinates in a cyclical sequence)

Maintenance Requirements:

(Please remember to note the starting time and the ending time)

You have to extend this class to provide the following two features. (You are free to write any new methods or change any of the existing methods as you deem necessary, but please document all changes.)

1)Determine the perimeter of the quadrilateral: The Perimeter can be computed as explained below: assume (xa,ya) and (xb,yb) are two adjacent points

  • length of each side = Square root ((xa - xb)*( xa - xb) + (ya - yb)*( ya - yb)).

Perimeter is summation of the lengths of all four sides

2)Determine the area of the quadrilateral, using the procedure described below:

  • Drawing a line between points (x1,y1) and (x3,y3) will divide the quadrilateral into 2 triangles, as shown.
  • Now let (x1,y1), (x2,y2) and (x3,y3) be one triangle called “triangle1”. Then (x3,y3), (x4,y4), and (x1,y1) will be the other triangle called “triangle2”.
  • Compute the area of each of triangle. The area of a triangle can be computed by using the formula,

Area = Square root(s*(s-a)*(s-b)* (s-c)) where,

s = (a+b+c)/2, and a, b, c are the lengths of the three sides of the triangle.

  • The area of the quadrilateral is the summation of the areas of both the triangles.
  • You need to test the program for Question 1 using the following main function (to be typed by you; can be changed if necessary), and the test data shown in the main function:

int main ()

{

QUADRI_1 quad1(10, 7, 8, 12, 23, 17, 25, 5);

quad1.display();

//Perimeter should be 48.49; Area should be 130.5

QUADRI_1 quad2(5, 3, 5, 11, 14, 16, 17, 6);

quad2.display();

//Perimeter should be 41.11; Area should be 100.5

return 0;

}

1