Polygon in a Two Dimensional Space (Id-1535)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1535

 

Design a class polygon to represent a polygon in a two dimensional space. Provide member functions to get the details of the polygon and compute area. Area of a polygon with ‘n’ vertices is given by the following formula:

Here the vertices are numbered from 1 to n either clockwise or anticlockwise. The sign of the value changes when numbering is done in the other way. So absolute value is considered.

Derive two classes: triangle and quadrilateral, from the class polygon. Overload the operator [] to get the ‘i-th’ point of the polygon if ‘i’ is less than or equal to the number of vertices ‘n’ and raise an user defined exception outofrange when ‘i’ is greater than ‘n’. Catch the exception in main and print ‘outofrange’.

Input Format

Next six entries are Vertices of a triangle

value of X- coordinate of point1

value of Y- coordinate of point1

….

value of X- coordinate of point6

value of Y- coordinate of point6

Next eight entries are Vertices of a triangle

value of X- coordinate of point1

value of Y- coordinate of point1

….

value of X- coordinate of point8

value of Y- coordinate of point8

index of the vertex  of the polygon, whose coordinate has to be printed.

Output Format

Area of triangle

Area of quadrilateral

Value of X- coordinate and Y- coordinate of point-n separated by tab or print Out of range if index is not in range

Code

Please Comment Working if the code worked to you

If you have other working codes please comment the codes enclosing with <pre> and </pre> 🙂

Example: <pre> Your Code </pre>

C++ Code 

The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

 

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

This site uses cookies and by using the site you are consenting to this.