C++의 클래스를 연습해보았다.
C++의 클래스는 자바의 클래스와 비슷하지만, 파괴자로 가비지 컬렉터를 따로 작성해줘야 한다. 이번에는 파괴자가 작성되어 있지 않지만 좀더 공부해 보겠다.
#include <iostream>
using namespace std;
class polyhedron {
private:
int V;
int E;
public:
polyhedron()
{
V = 0;
E = 0;
}
polyhedron(int v, int e)
{
V = v;
E = e;
}
int getV()
{
return V;
}
int getE()
{
return E;
}
};
void find_answer(polyhedron X)
{
int answer;
answer = X.getE() - X.getV() + 2;
//cout << "E : " << X.getE() << " V : " << X.getV() << "\n";
cout << answer << "\n";
return;
}
void test_case()
{
int T, i;
int V, E;
cin >> T;
for (i = 0; i < T; i++)
{
cin >> V >> E;
polyhedron X(V, E);
find_answer(X);
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
test_case();
return 0;
# }