Create an instance of the class polygon and read the segment

Assignment Help C/C++ Programming
Reference no: EM13937045

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: EM13937045

Questions Cloud

Language running on any operating system : Task: You are required to create and deliver a presentation providing an analysis of an existing software exploit (therefore you are not required to craft a new, unknown exploit yourself).
Social phenomenon and exoticize the familiar : Choose an everyday social phenomenon and "exoticize the familiar" by describing in careful, perceptive detail its aspects that you would otherwise take for granted. You must focus your essay on ONE specific phenomenon. Your phenomenon must be specifi..
Program containing a function that outputs the elements : Write a program containing a function that outputs the elements stored in the tree (integers) to the screen. The integers have to be output level by level in the order they appear in the tree.
How does the event relate to issues addressed in cyber : Find a Cybersecurity-related current event, activity, or development in the news, briefly summarize the event and reflect on its significance, How does the event relate to issues addressed in cyber
Create an instance of the class polygon and read the segment : 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:
Discuss the importance of diet in the evolution of the brain : Describe two changes to the skull that have occurred in the evolution of modern humans. For each change, suggest one reason why it has occurred.
Create a web layout which works wonderfully : Functionality Functionality is concerned with how everything actually works. A common design mistake is to create a web layout which works wonderfully for one web page, but not for all of the web pages within a site. The amount of space available ..
Program to create a mortgage calculator : I created a mortgage calculator for user to input requested amount and menu. Somehow, I think that I have it half right... I think I have lost my way somehow..See Attached files.
Develop a strategic marketing communication plan : Develop a strategic Marketing communication plan for an online/digital problem being faced by an existing organization, a specific product/service or a brand of your choice.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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