본문 바로가기

이것저것

[c++]삼각형 넓이 계산 프로그램

#include <iostream>

using namespace std;

class triangle
{
private:
	double base;
	double height;

public:
	void Init(double b, double h)
	{
		base = b;
		height = h;
	}
	double GetArea()
	{
		return(base * height) / 2.0;
	}
};

int main()
{
	triangle tri;
	tri.Init(3, 4);
	cout << "면적 : " << tri.GetArea() << endl;

	return 0;
}

<실행결과>

'이것저것' 카테고리의 다른 글

[c++] 급여 계산 프로그램  (0) 2023.03.23