Thread: Length of line..in polygon

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    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

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    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.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    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


    Thanx for your time buddy

  4. #4
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    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

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    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)
    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.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to get the length of the string in one line
    By transgalactic2 in forum C Programming
    Replies: 15
    Last Post: 03-24-2009, 04:00 AM
  2. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  3. Imposing Line Numbers automatically in the C code
    By cavestine in forum C Programming
    Replies: 14
    Last Post: 10-15-2007, 12:41 AM
  4. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 11:10 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM