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

  Create a white paper based on knowledge

Create a white paper based on knowledge

  Describe how logical and physical representations

explain how logical and physical representations of a To-Be system will differ.

  Implementation of type data structures

How can string and word variable type data structures be implemented?

  Explain the difference between object-oriented programming

define the difference between object-oriented programming and procedural (or structural or processual) programming. What, if anything, does the OO model bring to the table and improve upon what was out there pre-OO.

  Execute a class person with two fields name and age

Execute a class Person with two fields name and age.

  Select one physical tamper-resistant device application

Choose one physical tamper-resistant device application and describe its security-related protocol in full. Are there any potential practical attacks on the protocol? would the power analysis attack be feasible in your protocol.

  What are two long term benefits of e-scm

What are two market trends occurring in SCM (Supply Chain Management) industry.

  Show both the subscript of the largest item in arr

show both the subscript of the largest item in arr. want help with writing a program that: Lets arr be an array of 20 integers

  What is a possible downside of making such a choice

The mainframe currently only connects to terminals, but management wants to be able to access it from  desktop. You run a token ring network. The mainframe manufacturer supports Ethernet, but not token ring. maintain an outline of possible solutio..

  Algorithm for computing a topological ordering of a dag

But assume that we're given an arbitrary graph that may or may not be a DAG. Extend the topological ordering algorithm so that given an input directed graph G it outputs one of two thing.

  Programming field as career

Unfortunately, there are fewer women within the programming fields that there are men, encourage women to go into these fields

  Find the monthly amount of interest paid and remaining debt

You have just purchased a stereo system that costs $1000 on the following credit plan: no down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50.

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