Thread: polygon area

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    4

    polygon area

    hi,
    i need to write a program with 7 files point, triangle & polygon class & header files, and the 7th one has the main function, it calculates the area, it is supposed to take in the points together, i dont see how i need the triangle class but i have 2 use it, how do i store the points if any number of them can be input? and what would be the algorithm to calc the area? how do i reference the points after i take them in??

    cheers

  2. #2
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    This sounds suspiciously like a homework assignment. Why don't you post what you have so far and we help from there ?

    But I will tell you that the area of a triangle is 1/2(base * height)
    Do not make direct eye contact with me.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    4

    some code

    here are some of the files its the polygon.h & polgon.cc im stuck on, since it can have any number of points!!! also the polya.cpp which will be the 'main' part i havent started but i have the algorithm thought out here are 3 of them

    (
    //point class definition represents an x,y co-ordinate pair

    #ifndef POINT_H
    #define POINT_H

    class point {
    friend ostream &operator<<( ostream &output, const point &);
    friend istream &operator>>( istream &input, point &);
    public:

    point( float = 0, float = 0 ); //default constructor
    ~point(); //destructor

    void setX( float ); //set x in co-ordinate pair
    float getX () const; //return x from co-ordinate pair

    void setY( float ); //set y in co-ordinate pair
    float getY () const; //return y from co-ordinate pair

    void print() const; //output point object

    static int getCount(); //return no of objects created

    protected:
    float x; //x part of pair
    float y; //y part of pair

    //static data member
    static int count; // number of point objects instantiated

    }; //end class point

    #endif

    )
    ///////////////////////////////////////////////////////////////////////////
    // triangle class consists of 3 point objects
    (
    triangle.hh

    #ifndef TRIANGLE_HH
    #define TRIANGLE_HH

    #include "point.h"

    class triangle : public point {

    public:
    triangle(float,float,float,float,float,float); // constructor
    ~triangle(); // destructor

    //static int getTriCount(); //return no of objects created

    void print() const; //output point object

    //float getArea(point *, point *, point *);

    //inline float calc_determinant(const point &p1, const point &p2){
    // return(p1.x * p2.y - p2.x * p1.y);

    private:

    point p1, p2, p3;
    // static data member
    //static int tricount; // number of triangle objects created

    }; //end class triangle
    )
    #endif
    /////////////////////////////////////////////////////////////////////
    (
    triangle.cpp

    // triangle class member function definitions

    #include "triangle.h"

    //default constructor
    triangle::triangle(float p1x, float p1y,float p2x, float p2y,float p3x, float p3y):
    p1(point(p1x,p1y)),p2(point(p2x,p2y)),p3(point(p3x ,p3y))
    {

    } // end triangle constructor
    )

    Code:
    //point class definition represents an x,y co-ordinate pair

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Please, use code tags and proper formatting. Your code is unreadable at the moment.Code Tags.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Use point arrays or point pointers () .
    Do not make direct eye contact with me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Point in polygon test - spherical coords
    By bhdz in forum C Programming
    Replies: 1
    Last Post: 11-07-2007, 01:25 PM
  2. Polygon Area and Centroid :(
    By Moni in forum C++ Programming
    Replies: 7
    Last Post: 06-01-2003, 12:39 PM
  3. IDEA: Polygon unions and intersections
    By Magos in forum Contests Board
    Replies: 3
    Last Post: 05-21-2003, 07:16 PM
  4. Need help with switch
    By 3kgt in forum C Programming
    Replies: 2
    Last Post: 02-26-2003, 12:43 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM