Modify an instance of the class polygon

Assignment Help Computer Engineering
Reference no: EM1331679

Assume you are participating in a big project that deals with points in a two-dimensional plain. You are given the following structure definitions for points and segments that you should use and not modify:

struct point2D
{
int x;
int y;
};
struct segment2D
{
point2D p1;
point2D p2;
};

A point, therefore, is given by its (x,y)-coordinates.

A segment is a part of a straight line through two points p1 and p2. Assume several segments are stored in a text file. Each segment is encoded by a pair of its endpoints p1=(x1, y1) and p2=(x2, y2). The coordinates of these endpoints are in one text line in following format:
x1 y1 x2 y2

For example, if your file contains coordinates of 4 line segments, the file format is as follows:
-5 10 7 119
16 50 0 70
-5 10 0 70
16 50 7 119

The segments in the file are mixed up, but it is known that they form a polygon if you put them in a proper order. Your task is to figure out this order. More exactly, you must do the following:

* Design a class Polygon with a private variable head. This variable should be the head of a linked list containing the structures of type segment2D. The class has to have a public method sort specified below.

* The sort method of class Polygon should sort the segments in the linked list so that any two consecutive segments with numbers i and i+1 in the sorted list satisfy the following condition: the second endpoint of segment number i is the same as the first endpoint of segment number i+1. Moreover, the first endpoint of the first segment must be the same as the second endpoint of the last one.

* Create an instance of the class Polygon and read the segments from file into the linked list whose head pointer is head.

* Traverse the sorted linked list of segments from head to tail and output the coordinates of the segment endpoints to the screen, one line per segment.

For example, the above segment coordinates should be stored in the sorted linked list and output to the screen as follows:
-5 10 7 119
7 119 16 50
16 50 0 70
0 70 -5 10

Note that sometimes you might need to swap the points p1 and p2 in some segments.

Create your own data file test.dat containing endpoints of at least 10 segments (make sure that they really form a polygon and are mixed up, so that the program indeed has to do some work).

Reference no: EM1331679

Questions Cloud

Designing criminal justice policy : Your supervisor informs you that each criminal justice agency in your community has to develop a new crime fighting strategy for the coming fiscal year that must be based on a crime causation explanation to be presented to the city council for fun..
Design an application that finds all 4 digit numbers : make an application that finds all 4 digit numbers (those would be the numbers in the range 1000-9999) whose value is equal to the sum of each digit raised to the fourth power. MEANINGFUL output should be sent to the screen.
Coordinating with insufficient resources : Coordinating with Insufficient Resources - What are some of the problems that you might run into when allocating scarce resources?
High or low switching costs : Is it good strategy to have high or low switching costs?
Modify an instance of the class polygon : suppose you are participating in a big project that deals with points in a two-dimensional plain
Are discretionary employee benefits an entitlement : Show your views about whether discretionary employee benefits should be an entitlement or something earned based on performance.
Explain how does the availability of substitutes affect : Explain how does the availability of substitutes affect purchasing decisions.
Effectively revamping an hr department : Create the specific job titles you would like to see in your HRM department. Describe why you selected those titles and what tasks to assign to each.
Create class complex for working with complex numbers : modify class Complex for working with complex numbers of the form a + bi, where i is square root of -1. Your class must have two overloaded operators for adding and subtracting the complex numbers.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd