티스토리 뷰

#include <iostream>
using namespace std;

// Point 클래스를 정의한다.
class Point
{
public:
 // 멤버 함수
 void Print();

 // 생성자들
 Point();
 Point(int initialX, int initialY);
 Point(const Point& pt);

 // 접근자
 void SetX(int value)
 { if(value<0)
  x = 0;
 else if(value<100)
  x=100;
 else
  x=value;
 }
 void SetY(int value) {
  if(value<0)
  y = 0;
 else if(value<100)
  y=100;
 else
  y=value;
 }
 int GetX() {return x;};
 int GetY() {return y;};

private:
 // 멤버 변수
 int x, y;

};

Point::Point(const Point& pt)
{
 x = pt.x;
 y = pt.y;
}

Point::Point(int initialX, int initialY)
{
 SetX(initialX);
 SetY(initialY);
}
Point::Point()
{
 x = 0;
 y = 0;
}
void Point::Print()
{
 cout << "( " << x << ", " << y << ")\n";
}


int main()
{
 // 객체를 생성한다.
 Point pt; // 생성자도 꼼꼼히 봐줘라

 // pt의 x, y 좌표를 대입한다.
 pt.SetX( -50);
 pt.SetY( 50);

 // pt의 x, y좌표를 각각 구해본다.

 cout << "pt.x = " << pt.GetX() << "\n";
 cout << "pt.y = " << pt.GetY() << "\n";

 return 0;
}


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함