
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

This sounds suspiciously like a homework assignment. Why don't you post what you have so far and we help from there :D ?
But I will tell you that the area of a triangle is 1/2(base * height)

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 coordinate 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 coordinate pair
float getX () const; //return x from coordinate pair
void setY( float ); //set y in coordinate pair
float getY () const; //return y from coordinate 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 coordinate pair

Please, use code tags and proper formatting. Your code is unreadable at the moment.Code Tags.

Use point arrays or point pointers (:D) .