| | |
Help with C++ PLEASE
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hi all
I need help with C++, I need to develop a class specification and an irregular polygon application. I am stuck and don't know what to do.I have tried to solve it but it keeps giving me errors.
If anyone is kindly to help me out, I would be very grateful for it
these are the requirements:
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
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
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
to determine the length of the boundary of an irregular polygon.
The polygon may have between 3 and 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.
You should write a main function to implement this using your Point and Line classes and test the program thoroughly.
Thanks in advance
I need help with C++, I need to develop a class specification and an irregular polygon application. I am stuck and don't know what to do.I have tried to solve it but it keeps giving me errors.
If anyone is kindly to help me out, I would be very grateful for it

these are the requirements:
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
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
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
to determine the length of the boundary of an irregular polygon.
The polygon may have between 3 and 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.
You should write a main function to implement this using your Point and Line classes and test the program thoroughly.
Thanks in advance
•
•
•
•
No ball no play...
In other words, what have you done so far. Post it...
this is what ive got so far...and not sure if its right and am DEFENITELY sure that something is missing.
/ point.h
class Point
{
public:
Point();
Point(int x, int y);
int X() const;
int Y() const;
void SetX(int);
void SetY(int);
private:
int m_X;
int m_Y;
};
// point.cpp
Point::Point()
{
}
Point::Point(int x, int y) : m_X(x), m_Y(y)
{
}
int Point::X() const {return m_X;}
int Point::Y() const {return m_Y;}
void Point::SetX(int x) {m_X = x;}
void Point::SetY(int y) {m_Y = y;}
// line.h
class Line
{
public:
Line(const Point&, const Point&);
Point StartPoint() const;
Point EndPoint() const;
void SetStartPoint(const Point&);
void SetEndPoint(const Point&);
double Length() const;
private:
Point m_StartPoint;
Point m_EndPoint;
};
Line::Line (
const Point& start,
const Point& end) : m_StartPoint(start), m_EndPoint(end)
{
}
Point Line::StartPoint() const {return m_StartPoint;}
Point Line::EndPoint() const {return m_EndPoint;}
void Line::SetStartPoint(const Point& start) {m_StartPoint = start;}
void Line::SetEndPoint(const Point& end) {m_EndPoint = end;}
double Line::Length() const
{
int diffX = m_EndPoint.X() - m_StartPoint.X();
int diffY = m_EndPoint.Y() - m_StartPoint.Y();
return sqrt(double(diffX*diffX + diffY*diffY));
}
Last edited by Nepenthe8; Apr 1st, 2008 at 8:35 am.
•
•
•
•
to determine the length of the boundary of an irregular polygon.
The polygon may have between 3 and 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.
You should write a main function to implement this using your Point and Line classes and test the program thoroughly.
- somehow prompt the user for some coordinates
- use these coordinates to form some lines
- sum the length of the lines with the Length method you wrote for Line
All of this needs to be done inside a main method in order for it to be run.
Give that a go and repost if you still have problems.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
•
•
It seems as though you've done everything up until this point. For this section you need to:
- somehow prompt the user for some coordinates
- use these coordinates to form some lines
- sum the length of the lines with the Length method you wrote for Line
All of this needs to be done inside a main method in order for it to be run.
Give that a go and repost if you still have problems.
oke thanks, an answer which is useful
ill give it a try although thats the point am actually stuck on! For testing, I'd wack it all in one file with a main...
cpp Syntax (Toggle Plain Text)
#include <iostream> #include <cmath> using namespace std; class Point { public: Point(); Point ( int x, int y ); int X() const; int Y() const; void SetX ( int ); void SetY ( int ); private: int m_X; int m_Y; }; // point.cpp Point::Point() {} Point::Point ( int x, int y ) : m_X ( x ), m_Y ( y ) {} int Point::X() const { return m_X; } int Point::Y() const { return m_Y; } void Point::SetX ( int x ) { m_X = x; } void Point::SetY ( int y ) { m_Y = y; } // line.h class Line { public: Line ( const Point&, const Point& ); Point StartPoint() const; Point EndPoint() const; void SetStartPoint ( const Point& ); void SetEndPoint ( const Point& ); double Length() const; private: Point m_StartPoint; Point m_EndPoint; }; Line::Line ( const Point& start, const Point& end ) : m_StartPoint ( start ), m_EndPoint ( end ) {} Point Line::StartPoint() const { return m_StartPoint; } Point Line::EndPoint() const { return m_EndPoint; } void Line::SetStartPoint ( const Point& start ) { m_StartPoint = start; } void Line::SetEndPoint ( const Point& end ) { m_EndPoint = end; } double Line::Length() const { int diffX = m_EndPoint.X() - m_StartPoint.X(); int diffY = m_EndPoint.Y() - m_StartPoint.Y(); return sqrt ( double ( diffX*diffX + diffY*diffY ) ); } int main() { Point a(4,3); //a.SetX(4); //a.SetY(3); Point b(2,1); //b.SetX(2); //b.SetY(1); Line myLine(a,b); cout << myLine.Length(); cout << "\n"; system("pause"); }
Last edited by iamthwee; Apr 1st, 2008 at 9:08 am.
*Voted best profile in the world*
![]() |
Other Threads in the C++ Forum
- Previous Thread: how to read many text file?
- Next Thread: Counter problems!!!
Views: 1204 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






