Help with C++ PLEASE

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2008
Posts: 9
Reputation: Nepenthe8 is an unknown quantity at this point 
Solved Threads: 0
Nepenthe8's Avatar
Nepenthe8 Nepenthe8 is offline Offline
Newbie Poster

Help with C++ PLEASE

 
0
  #1
Mar 31st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help with C++ PLEASE

 
0
  #2
Mar 31st, 2008
No ball no play...

In other words, what have you done so far. Post it...
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: Nepenthe8 is an unknown quantity at this point 
Solved Threads: 0
Nepenthe8's Avatar
Nepenthe8 Nepenthe8 is offline Offline
Newbie Poster

Re: Help with C++ PLEASE

 
0
  #3
Apr 1st, 2008
Originally Posted by iamthwee View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help with C++ PLEASE

 
0
  #4
Apr 1st, 2008
Try testing a simple example in int main()
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: Nepenthe8 is an unknown quantity at this point 
Solved Threads: 0
Nepenthe8's Avatar
Nepenthe8 Nepenthe8 is offline Offline
Newbie Poster

Re: Help with C++ PLEASE

 
0
  #5
Apr 1st, 2008
Originally Posted by iamthwee View Post
Try testing a simple example in int main()
what do you mean?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 807
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: Help with C++ PLEASE

 
0
  #6
Apr 1st, 2008
Originally Posted by Nepenthe8 View Post
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.
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.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: Nepenthe8 is an unknown quantity at this point 
Solved Threads: 0
Nepenthe8's Avatar
Nepenthe8 Nepenthe8 is offline Offline
Newbie Poster

Re: Help with C++ PLEASE

 
0
  #7
Apr 1st, 2008
Originally Posted by darkagn View Post
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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help with C++ PLEASE

 
0
  #8
Apr 1st, 2008
For testing, I'd wack it all in one file with a main...

  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class Point
  7. {
  8. public:
  9. Point();
  10. Point ( int x, int y );
  11. int X() const;
  12. int Y() const;
  13. void SetX ( int );
  14. void SetY ( int );
  15.  
  16. private:
  17. int m_X;
  18. int m_Y;
  19. };
  20.  
  21. // point.cpp
  22. Point::Point()
  23. {}
  24.  
  25. Point::Point ( int x, int y ) : m_X ( x ), m_Y ( y )
  26. {}
  27.  
  28. int Point::X() const
  29. {
  30. return m_X;
  31. }
  32. int Point::Y() const
  33. {
  34. return m_Y;
  35. }
  36. void Point::SetX ( int x )
  37. {
  38. m_X = x;
  39. }
  40. void Point::SetY ( int y )
  41. {
  42. m_Y = y;
  43. }
  44.  
  45. // line.h
  46. class Line
  47. {
  48. public:
  49. Line ( const Point&, const Point& );
  50. Point StartPoint() const;
  51. Point EndPoint() const;
  52. void SetStartPoint ( const Point& );
  53. void SetEndPoint ( const Point& );
  54. double Length() const;
  55.  
  56. private:
  57. Point m_StartPoint;
  58. Point m_EndPoint;
  59. };
  60.  
  61. Line::Line (
  62. const Point& start,
  63. const Point& end ) : m_StartPoint ( start ), m_EndPoint ( end )
  64. {}
  65.  
  66. Point Line::StartPoint() const
  67. {
  68. return m_StartPoint;
  69. }
  70. Point Line::EndPoint() const
  71. {
  72. return m_EndPoint;
  73. }
  74. void Line::SetStartPoint ( const Point& start )
  75. {
  76. m_StartPoint = start;
  77. }
  78. void Line::SetEndPoint ( const Point& end )
  79. {
  80. m_EndPoint = end;
  81. }
  82. double Line::Length() const
  83. {
  84. int diffX = m_EndPoint.X() - m_StartPoint.X();
  85. int diffY = m_EndPoint.Y() - m_StartPoint.Y();
  86. return sqrt ( double ( diffX*diffX + diffY*diffY ) );
  87. }
  88.  
  89.  
  90. int main()
  91. {
  92. Point a(4,3);
  93. //a.SetX(4);
  94. //a.SetY(3);
  95.  
  96. Point b(2,1);
  97. //b.SetX(2);
  98. //b.SetY(1);
  99.  
  100. Line myLine(a,b);
  101. cout << myLine.Length();
  102. cout << "\n";
  103.  
  104. system("pause");
  105. }
Last edited by iamthwee; Apr 1st, 2008 at 9:08 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: Nepenthe8 is an unknown quantity at this point 
Solved Threads: 0
Nepenthe8's Avatar
Nepenthe8 Nepenthe8 is offline Offline
Newbie Poster

Re: Help with C++ PLEASE

 
0
  #9
Apr 1st, 2008
oke i tested it, gives me these errors

test.cc: In function `int main()':
test.cc:104: implicit declaration of function `int system(...)'
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help with C++ PLEASE

 
0
  #10
Apr 1st, 2008
OK take out system("pause");

And replace it with cin.get();
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 1204 | Replies: 11
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC