본문 바로가기
C++

문제 03-1 [구조체 내에 함수정의하기]

by KWONE 2024. 8. 2.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

using namespace std;

struct Point
{
	int xpos;
	int ypos;

	void MovePos(int x, int y)
	{
		xpos += x;
		ypos += y;
	}

	void ShowPosition()
	{
		cout << "(" << xpos << "," << ypos << ")"<<endl;
	}

	void AddPoint(const Point& pos)
	{
		xpos += pos.xpos;
		ypos += pos.ypos;
	}
};

int main()
{
	Point pos1 = { 12,4 };
	Point pos2 = { 20,30 };

	pos1.MovePos(-7, 10);
	pos1.ShowPosition();

	pos1.AddPoint(pos2);
	pos1.ShowPosition();

	return 0;
}