Select Page
Poker Forum
Over 1,292,000 Posts!
Poker ForumFTR Community

anyone know C++

Results 1 to 11 of 11
  1. #1

    Default anyone know C++

    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.
  2. #2
    Guest
    A(a) + B(b) = C(c)
  3. #3
    When exactly is his homework assignment due?
  4. #4
    lol, it's a "her" and it's due at midnight
  5. #5
    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.
  6. #6

    Default Re: anyone know C++

    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
  7. #7
    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.
  8. #8
    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
  9. #9
    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
  10. #10
    bigred's Avatar
    Join Date
    Sep 2004
    Posts
    15,437
    Location
    Nest of Douchebags
    ALL YOUR BASE ARE BELONG TO US
    LOL OPERATIONS
  11. #11
    Move Zig, Move Zig
    Send up every Zig

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •