Thread: Please Help!!!!!!!

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Unhappy Please Help!!!!!!!

    /*To me this is like the hardest and most diffucult to understand problem that this book has ever used to explain something. The objective of this program is to show how you can combine two classes that after declared in a .hpp and .cpp file. */

    /*If you could please explain to me what's going on here, you don't have to explain the whole thing just one point would be enought (I think)*/

    // Begin Rect.hpp

    #include <iostream>
    class Point // holds x,y coordinates
    {
    // no constructor, use default
    public:
    void SetX(int x) { itsX = x; }
    void SetY(int y) { itsY = y; }
    int GetX()const { return itsX;}
    int GetY()const { return itsY;}
    private:
    int itsX;
    int itsY;
    }; // end of Point class declaration


    class Rectangle
    {
    public:
    Rectangle (int top, int left, int bottom, int right);
    ~Rectangle () {}

    int GetTop() const { return itsTop; }
    int GetLeft() const { return itsLeft; }
    int GetBottom() const { return itsBottom; }
    int GetRight() const { return itsRight; }

    Point GetUpperLeft() const { return itsUpperLeft; }
    Point GetLowerLeft() const { return itsLowerLeft; }
    Point GetUpperRight() const { return itsUpperRight; }
    Point GetLowerRight() const { return itsLowerRight; }

    void SetUpperLeft(Point Location) {itsUpperLeft = Location;}
    void SetLowerLeft(Point Location) {itsLowerLeft = Location;}
    void SetUpperRight(Point Location) {itsUpperRight = Location;}
    void SetLowerRight(Point Location) {itsLowerRight = Location;}

    void SetTop(int top) { itsTop = top; }
    void SetLeft (int left) { itsLeft = left; }
    void SetBottom (int bottom) { itsBottom = bottom; }
    void SetRight (int right) { itsRight = right; }

    int GetArea() const;

    private:
    Point itsUpperLeft;
    Point itsUpperRight;
    Point itsLowerLeft;
    Point itsLowerRight;
    int itsTop;
    int itsLeft;
    int itsBottom;
    int itsRight;
    };
    // end Rect.hpp


    // Begin rect.cpp

    #include "rect.hpp"
    Rectangle::Rectangle(int top, int left, int bottom, int right)
    {
    itsTop = top;
    itsLeft = left;
    itsBottom = bottom;
    itsRight = right;

    itsUpperLeft.SetX(left);
    itsUpperLeft.SetY(top);

    itsUpperRight.SetX(right);
    itsUpperRight.SetY(top);

    itsLowerLeft.SetX(left);
    itsLowerLeft.SetY(bottom);

    itsLowerRight.SetX(right);
    itsLowerRight.SetY(bottom);
    }


    // compute area of the rectangle by finding cornerssides,
    // establish width and height and then multiply
    int Rectangle::GetArea() const
    {
    int Width = itsRight-itsLeft;
    int Height = itsTop - itsBottom;
    return (Width * Height);
    }

    int main()
    {
    //initialize a local Rectangle variable
    Rectangle MyRectangle (100, 20, 50, 80 );

    int Area = MyRectangle.GetArea();

    std::cout << "Area: " << Area << "\n";
    std::cout << "Upper Left X Coordinate: ";
    std::cout << MyRectangle.GetUpperLeft().GetX();
    return 0;
    }


    /*######################################*/
    /*I know it's long but if some kind soul out there would be nice enough to explain to me just one point I would really appreciate it. If not just give me an example of using two classes together with a .hpp and .cpp file.*/
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Talking Please help me!!!!!!!!!

    Please I need help here, just try that's all I ask for

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    the Point class describes a point in two dimensional space using two integers. Think of a chess board where each square can be located with a row and a column or an x and a y.

    A rectangle can be defined by 4 points. Therefore you can think of a class Rectangle that has as data members 4 instances of class Point, one for each of it's corners. However, to construct a Rectangle out of 4 Points you would need to enter 8 ints. To make it easier on the user, the maker of Rectangle said just give me 4 ints and I will generate the Points to be used to make a Rectangle. The first int will be the top line, the second int will one side, the third will be the bottom line, and the 4th will be the other side, or whatever. Where these lines intersect define 4 sets of ints that can be used to make 4 Points. Therefore the user only needs to enter 4 ints rather than 8. They are converted into private variables and then into Points. Could you think of a better scenario to explain using one class in another, maybe. But this is what was chosen.

    Moral of the story, user friendly coding is not always programmer friendly coding.

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Thanks

    Thanks for your help, your help is greatly appreciated.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed