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

  Calculates and displays the mortgage payment amount

make Use of an array for the mortgage data for the different loans. show the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan.

  Selecting a life-cycle model for project

She wishes your organization to build a product which will monitor the company’s stock, starting with purchasing of leather and keeping track of boots as they are manufactured, distributed to individual stores, and sold to customers.

  How to create a javascript program

Create a JavaScript program that declares and prints an array that contains at least 20 of your favorite songs. For each song, determine the best means for storing the year it was published.

  Developing a pseudocode and the flowchart

Develop a flowchart or puesdocode that carry out the following task:. a) Begin the program. b) Declares the strings. c) Accept an input studentname.

  Asynchronous transmission

Assume that the sender and receiver utilize an asynchronous transmission and agree not to utilize any stop elements.

  Program to persons ability to vote

Write down a program which asks for the user's age. On the basis of their response print "You may vote" (18 years old or older) or "You can't vote"

  Explain the modified scorecard approach

express the Value Based Management approach of demonstrating business value. Explain the Modified scorecard approach to measuring IT value. What is the benefit of this approach? Describe the concept of  balanced score card.

  Recoginizing the error in given code

Identify the problem in the above code, If ( toupper( response[ 0 ] ) == 'Y' )

  Preparing a copy of hard drive

After we have the target media prepared and assembled along with all our tools assembled for investigation we should now make a copy of hard drive.

  Data representation and logic

Representing Text and Numbers, Binary Arithmetic, Interpreting Logical Statements, Logic Puzzle, Binary and Algorithms.

  Application showing files name-size and last modifiaction

Make a file by utilizing any word-processing program or the text editor. Write down an application which shows the file's name, size, and time of the last modification.

  What is the aim of a firewall

Name and explain two of the network devices used to create a network. What is the purpose of a firewall?

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