Link to home
Start Free TrialLog in
Avatar of vixenmrb
vixenmrb

asked on

Using the Point Class - C++

My assignment is to write a definition of a class named Point used to store and manipulate the location of a point in a plane. You need to declare and implement the following member functions:
1 - a member function set that sets the private data after an object of this class is created.
2 - a member function to move the point by an amount along the vertical and horizontal directions  specified by the first and second arguments.
3 - a member function to rotate the point by 90 degrees clockwise around the origin.
4 - two const inspector functions to retrieve the current coordinates of the point.
Embed your class in a test program that requests data for several points from the user, creates the points, then exercises the member functions.

Here is my code below: I am just trying to get it to work. I can work out the test program later..
Right now I am getting 3 errors.. Please help...

Code:

#include <iostream>
#include <cstdlib>

using namespace std;

class Point
{
public:
      Point();
      //member functions  
      void setPoints(double& set_x, double& set_y);
      //void setPointY(double set_y);
      void movePoints(double& move_x, double& move_y);
      void rotatePoints();
      double get_x()const;
      double get_y()const;
      
      //member variables
private:
      double x, y;
      double adjY, adjX;  
};      
int main()
{
      double x1, y1;
      
      setPoints (x1, y1);
      movePoints(x1, y1);
      rotatePoints();

      return 0;
}
Point::Point()
{
      x=0;
      y=0;
}
void Point::setPoints(double& new_x, double& new_y)
{
      x = new_x;
      y = new_y;

      cout << "Enter the X coordinate:" << endl;
      cin >> x;
      cout << "Enter the Y coordinate:" << endl;
      cin >> y;
}
void Point::movePoints(double& move_x, double& move_y)
{        
      x = x+move_x;
    y = y+move_y;

      cout << "Enter the new X coordinate:" << endl;
      cin >> x;
      cout << "Enter the new Y coordinate:" << endl;
      cin >> y;
      cout << "The new position of the coordinates is:"<<endl;
      cout << get_x()<< ""<<get_y()<<endl;
}
void Point::rotatePoints()
{
 adjX = -y;
 adjY = x;
 cout << "Enter the adjusted x coordinate:" <<endl;
 cin >> adjX;
 cout << "Enter the adjusted y coordinate:" <<endl;
 cin >> adjY;
 
}
double Point::get_x()const
{       
      return x;
}
double Point::get_y()const
{
      return y;
}
Avatar of Infinity08
Infinity08
Flag of Belgium image

>> Right now I am getting 3 errors..

And what would those errors be ?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vixenmrb
vixenmrb

ASKER

The errors are on the function calls. It states for example:
error C3861: 'setPoints': identifier not found
I think jkr got that ;)
Thanks IKR - that helped but I am still having a problem understanding the rotation of 90 degrees clockwise. I think I have part of it but not the full formula -- something is missing.. If not a help to my code can you at least give me an explanation about rotating a point. Thanks..
Well, the general solution is given in http://en.wikipedia.org/wiki/Rotation_matrix - since it's 90° (or, p/2), that should be pretty straightforward.
Sorry, that didn't accept the greek letter for PI - make that PI/2 then
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also - I think this has to do with the prob itself. Show this be adding the number to the orig coordinate for example if the orig for x is 1 and y is 1 .. I enter to move it 4 and 5. Should the output be for the new coordinates be 4 and 5 or should it be 5 and 6? Based on the formula it seems like the new coord output should be 5 and 6. This is not what is happening.
IKR gave me exactly what I needed to correct the errors. I still had to work on the rotation part a little more but Infinity08's info also help.. Thanks all...
>> I enter to move it 4 and 5. Should the output be for the new coordinates be 4 and 5 or should it be 5 and 6? Based on the formula it seems like the new coord output should be 5 and 6. This is not what is happening.

Take a closer look at what exactly you are doing in the move function. What are the I/O lines doing there ?