# Length of line..in polygon

• 03-27-2006
zap_hax
Length of line..in polygon
Hi,

Hi guys I am new to C++ but never wrote such a program actually i needed your help on this. It seems a difficult one but i hope if u guys could help me.

Thanks alot guys

The point P1 has coordinates {X1,Y1}.
The point P2 has coordinates {X2,Y2}.
The length of the line joining P1 and P2 is given by the equation:
{ (X2 - X1)2 + (Y2 - Y1)2 }1/2

Requirements:

Develop a class specification for the class Point (the data members and the prototypes for the member functions) in the file point.h.
Develop the implementation of the member functions in the file point.cc and test them with a suitable test program.
For example:
//pointTest.cc
Code:

int main()
{
Point P1;
P1.create(24,16); // create a point with coordinates {24,16}
P1.display(); // display the {X,Y} coordinates of P1
.....
}

Develop a class specification for the class Line (the data members and the prototypes for the member functions) in the file line.h.
Develop the implementation of the member functions in the file line.cc and test them with a suitable test program.
For example:
//lineTest.cc
Code:

int main()
{
Point P1;
P1.create(24,16); // create a point with coordinates {24,16}
Point P2;
P2.create(33,42); // create a point with coordinates {33,42}
Line L1;
L1.create(P1,P2); // create a line using points P1 and P2
cout << L1.length() << endl; // display the length of line L1
Line L2;
L2.create(12,30,28,16); // create a line using coordinates {12,30}, {28,16}
L2.display(); // display the coordinates of both points
.....
}

Application:

I need to determine the length of the boundary of an irregular polygon.
The polygon may have up to 9 sides.
The user should be prompted to enter the number of sides and the coordinates of each vertex point.
The program should then calculate and display the total length of the boundary.
I will need to write a main function to implement this using your Point and Line classes and test the program thoroughly.

Junaid
• 03-27-2006
hk_mp5kpdw
Don't get overwhelmed looking at the project as a whole. Break it down into pieces. Start at the beginning, develop that Point class and test it with that sample program.
• 03-27-2006
zap_hax
I am not really overwhelmed but the only thing is the main function of this project,

I cant get to write that...basically in the main the user has to specify how many sides they want and then the program has to tell the user to input n (number specified) coordinates... and has to calculate the length of each side...thats all i need help with

• 03-27-2006
ZuK
Quote:

Originally Posted by zap_hax
It seems a difficult one but i hope if u guys could help me.

No it's a simple one. So where do you see a problem ?
Kurt
• 03-29-2006
Bench82
Quote:

Originally Posted by zap_hax
basically in the main the user has to specify how many sides they want and then the program has to tell the user to input n (number specified) coordinates...

I think this is what hk_ meant by "overwhelmed" - trying to do too much at once. Start your main function just by asking for user input, and passing the data to your object(s)
Quote:

and has to calculate the length of each side..
There's no reason why your main() function has to do this.. It could be done behind-the-scenes by the polygon or line class instead. The less work you do in main() the easier your program should be to break down into managable chunks.
• 03-29-2006
Salem
Well have you written point.h, point.cc and pointtest.cc yet?

From that, you get
- line, which is a pair of points.
Which includes a method to calculate the length of the line

- polyline, which is an array of lines.
Which includes a method to loop over all the lines, calling the line length method, and summing the results.