Hey everyone, I am working on this project and do not know where to start. Can anyone lead me in the right direction? I am very poor in this background and could use all the help I can get. So, any help would be very much appreciated. Here are the details:

  1. Problem Statement
    Definition: A polyline is a sequence of points P1, P2, … , Pn in a plan. The points are determined by its coordinates: P1(x1, y1), P2 (x2, y2), … , Pn (xn, yn), n≥1.

A polyline is presented as an XML (text) file, called input2.txt. The tag names used in the file are:
• <point> // The tag for a point.
• <x> // The tag for x-coordinate.
• <y> // The tag for y-coordinate.

Example [A Polyline Represented as an XML file]
<Point> <x> 10 </x> <y> 10 </y> </Point>
<Point> <x> 20 </x> <y> 20 </y> </Point>
<x> 10 </x> <y> 40 </y>
<x> 40 </x>
<y> 40 </y>
<Point> <x> 30 </x> <y> 0 </y> </Point>
(A) Write a class PolyLine with the following interface (member functions):
• PolyLine – By default constructor for creating a polyline from an XML text file with name input2.txt.
• length - Calculates the length of the current polyline object (length = sum of all segments = P1P2 + P2P3 + … Pn-1Pn);
• insert – Inserts a new point in the polyline object (first, middle, last);
• remove – Removes a point from the polyline object;
• show – Show the current polyline object as sequence of (x, y) coordinates on the monitor;
• size – the current size of the polyline (number of points);
• store – Store the current polyline object as an XML text file output2.txt.

(B) Write a driver to test the PolyLine class. The driver should offer a friendly menu for multiple executions of all operations on a PolyLine object.
• Creates an object of class PolyLine.
• Calculating the length
• Inserting new node
• Removing a node
• Show the current polyline object
• Show the current size of the polyline
• Exit
Input Data: input2.txt - XML text file, representing a polyline
Output Data: output2.txt - XML text file, representing the updated polyline.

Important Note:
The internal representation of the PolyLine must be a list. You could use the STL List class or you could create your own linked list class.

4 Years
Discussion Span
Last Post by histrungalot

I just want advice of what I should start off with. I know I have to start with the header file, but I do not know how to start it off. I can worry about the implementation and the test driver later, but I really need to know how to start off the header file. Like, what should my private section of my class? I am confused when it comes to all this.


You should do it in pieces.

1.Start with reading and parsing the XML file first. This may be the function that takes you the longest. Create a program the takes in the file name, opens the file and parses out each (x, y) and prints them to the screen. Once you can do that, it's easy to paste that code into the PolyLine constructor.

2.Make a point class that holds the (x,y) pair.

   class Point {
       Point(int xVal, int yVal): x(xVal), y(yVal){};
       int getX() const { return x;};
       int getY() const { return y;};
       Point & setX(int xVal) { x=xVal; return *this;};
       Point & setY(int yVal) { y=yVal; return *this;};
       int x;
       int y;

3.Next you need the PolyLine class with all of the functions that are required.

   class PolyLine {
       PolyLine(string XMLFileName);
       void show();
       bool store(string XMLFileName);
       float  length();
       int size();
       bool  insert();
       bool  remove();
       vector<Point> theLine;

4.As you add each function to the PolyLine class, you will be creating the driver test program at the same time. Add the menu options as you get to them.
5.When testing, use a line that is simple. Like for calculating the length of the line use (0,0) & (3,0) and see that you get 3. Or (0,0) & (3,4) should be 5 (3, 4, 5 triangle).

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.