|
badandy519
|
05-29-2006, 02:07 AM
Post subject: anyone know C++
|
#1 (permalink)
|
|
Straight
Join Date: Aug 2005
Location: mckinney, tx
Posts: 223
|
|
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.
|
|
|
Play for FREE and practice your game at...
Join the FTR Poker Forum to disable these banners and start posting!
|
|
|
|
|
|
A(a) + B(b) = C(c)
|
|
|
|
Knytestorme
|
|
Flush
Join Date: May 2005
Location: Australia
Posts: 562
|
|
When exactly is his homework assignment due?
|
|
|
|
badandy519
|
|
Straight
Join Date: Aug 2005
Location: mckinney, tx
Posts: 223
|
|
lol, it's a "her" and it's due at midnight
|
|
|
|
Knytestorme
|
|
Flush
Join Date: May 2005
Location: Australia
Posts: 562
|
|
Well if I wasn't at work I'd consider doing it just for the hell of it but if I did it here they could claim copyright and ownership of the code and sue her for copyright infringement and plagerism so...
It's not an incredibly hard assignment though, is probably about 30 minutes coding with a c++ boox in front of her if she understands the concept of classes, I mean there isn't even any real need to worry about pointers which is usually half the problem for C++ newbies.
|
|
|
|
Pyroxene
|
05-29-2006, 02:32 AM
Post subject: Re: anyone know C++
|
#6 (permalink)
|
|
Straight
Join Date: Dec 2004
Posts: 236
|
|
Quote:
|
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.
|
|
Pyroxene
|
|
Knytestorme
|
|
Flush
Join Date: May 2005
Location: Australia
Posts: 562
|
|
Yeah, that's about it really and anyone with understanding should be able to make the necessary adjustments and write the testcase program for that class.
Only changes I would make to the formating would be along the lines of
#include <iostream>
using namespace std;
class CPoint {
int x, y;
public:
void Point;
void Point ( int, int );
void setX( int );
void setY( int );
void printPoint();
int getX();
int getY();
void ~Point();
};
and then your methods after this, just allows you to get rid of the public keyword in front of each method.
|
|
|
|
Pyroxene
|
|
Straight
Join Date: Dec 2004
Posts: 236
|
|
Quote:
|
Originally Posted by Knytestorme
void ~Point();
|
Forgot about the destructor, my time in Java is showing However, would this class need an explicit destructor or copy constructor?
|
|
Pyroxene
|
|
Knytestorme
|
|
Flush
Join Date: May 2005
Location: Australia
Posts: 562
|
|
depending on how it was being used but I have a fondness for destructors just because it makes it easier to remember and you get in the practise of just auto-inserting them.
For instance if it was used to create objects for a partical emitter class then I would most likely use a destructor class but it also comes down to the environment it is being used in (eg OS, Memory, etc) so to use a poker phrase in this case...it depends
|
|
|
|
bigred
|
|
PROFESSIONAL TROLL
Join Date: Sep 2004
Location: Nest of Douchebags
Posts: 2,184
|
|
ALL YOUR BASE ARE BELONG TO US
|
|
LOL OPERATIONS
|
|
Knytestorme
|
|
Flush
Join Date: May 2005
Location: Australia
Posts: 562
|
|
Move Zig, Move Zig
Send up every Zig
|
|
|