|
Re: anyone know C++
 Originally Posted by badandy519
A friend of mine needs this done....
A point is a an X and Y coordinate pair (2 integers). Design a class that stores the data for a point and has the following methods a default constructor, a constructor that takes an x and y coordinates, set x coordinate, set y coordinate, print the point data to the screen, return the x coordinate, return the y coordinate . Write a test program to test this class and all its methods.
I have not done any C++ in several years. Switched to Java and forgot everything. It will be something like this:
public class Point {
int x;
int y;
public Point()
{
x = 0;
y = 0;
}
public Point ( int initX, int initY )
{
x = initX;
y = initY;
}
public void setX( int newX )
{
x = newX;
}
public void setY( int newY )
{
y = newY;
}
public void printPoint()
{
printf( "X = %d, Y = %d\n", x, y );
}
public int getX( )
{
return x;
}
public int getY()
{
return y;
}
};
That should get you started, I may have some syntax problems. You might consider using cout instead of printf in the printPoint method, but that is up to how the professor likes it. cout is great from an academic point of view, but printf is what gets used in the real world. Even Java added a multi-argument printf-like method in 1.5.
Other things, I specifically picked parameters names to not mask the member variable names. You can rename them to mask and use the this keyword. Again, shoot for what the professor would want.
|