연재 완료/C++ Lang 예제코드 모음

Cpp_other_ex 0-b. Struct_Cpp

라이피 (Lypi) 2019. 4. 17. 12:09
반응형
Tpoint.h
#pragma once
#include 

class Tpoint
{
private:
	int x;
	int y;

public:
	void SetPosition(int i, int j);
	void Move(int i, int j);
	void Show();

public:
	Tpoint();
	~Tpoint();
};


Tpoint.cpp
#include "Tpoint.h"

void Tpoint::SetPosition(int i, int j)
{
	x = i;
	y = j;
}

void Tpoint::Move(int i, int j)
{
	x += i;
	y += j;
}

void Tpoint::Show()
{
	std::cout << x << " " << y << std::endl;
}


Tpoint::Tpoint()
{
	x = 0;
	y = 0;
}


Tpoint::~Tpoint()
{
	std::cout << "~Tpoint" << std::endl;
}

sample.cpp
#include "Tpoint.h"



int main()
{
	{
		Tpoint p1, p2;
		p1.SetPosition(10, 20);
		p2.SetPosition(20, 30);
		p1.Move(5, 3);
		p2.Move(7, 6);
		p1.Show();
		p2.Show();
	}

	std::cout << "안녕" << std::endl;
}
반응형