home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / POINT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  920 b   |  34 lines

  1. /* POINT.CPP illustrates a simple Point class */
  2.  
  3. #include <iostream.h>    // needed for C++ I/O
  4.  
  5. class Point {        // define Point class
  6.    int X;               // X and Y are private by default
  7.    int Y;
  8. public:
  9.    Point(int InitX, int InitY) {X = InitX; Y = InitY;}
  10.    int GetX() {return X;}  // public member functions
  11.    int GetY() {return Y;}
  12. };
  13.  
  14. int main()
  15. {
  16.    int YourX, YourY;
  17.  
  18.    cout << "Set X coordinate: ";  // screen prompt
  19.    cin >> YourX;                  // keyboard input to YourX
  20.  
  21.    cout << "Set Y coordinate: ";  // another prompt
  22.    cin >> YourY;                  // key value for YourY
  23.  
  24.    Point YourPoint(YourX, YourY);  // declaration calls constructor
  25.  
  26.    cout << "X is " << YourPoint.GetX(); // call member function
  27.    cout << '\n';                        // newline
  28.    cout << "Y is " << YourPoint.GetY(); // call member function
  29.    cout << '\n';
  30.    return 0;
  31. }
  32.  
  33.  
  34.