728x90
#include <iostream>
using namespace std;
class Rectangle {
private:
int width, height;
public:
Rectangle(int w, int h);
int getArea();
};
Rectangle::Rectangle(int w, int h)
: width(w), height(h) {}
int Rectangle::getArea()
{
return width * height;
}
int main()
{
int x, y;
cout << "가로 세로 입력 >>";
cin >> x >> y;
Rectangle rect(x,y);
cout << "사각형의 면적은 " << rect.getArea() << endl;
}
반응형
'전공 공부 > C++' 카테고리의 다른 글
클래스 Adder, Calculator 파일 분리 (0) | 2020.12.27 |
---|---|
클래스 Circle 파일 분리(반지름 입력받아 면적 구하기) (0) | 2020.12.27 |
부분 문자열 (0) | 2020.12.26 |
이름, 주소, 나이 출력(문자열 입력) (0) | 2020.12.26 |
문자열 같은지 검사 (0) | 2020.12.26 |