π κ°μΈ νλ λͺ¨μμ§ π/βΊ `23 νκ³ C++ νλ‘κ·Έλλ° λΆνΈ μΊ ν βΊ
[6μ°¨μ μ μ ] λ©΄μ κ³μ° κΈ°λ₯μ κ°μ§ Rectangle ν΄λμ€λ₯Ό μμ±νκ³ μ 체 νλ‘κ·Έλ¨μ μμ±νλΌ.
lrycro_
2023. 7. 10. 19:45
Q. λ€μ main() ν¨μκ° μ μλνλλ‘ νλ‘κ·Έλλ° νμμ€.
- λλΉ(width)μ λμ΄(height) λ³μλ₯Ό νμ©
- λ©΄μ κ³μ° κΈ°λ₯μ κ°μ§ Rectangle ν΄λμ€λ₯Ό μμ±νκ³ μ 체 νλ‘κ·Έλ¨μ μμ±νλΌ.
int main() {
Rectangle rect;
rect.width = 3;
rect.height = 5;
cout << "μ¬κ°νμ λ©΄μ μ " << rect.getArea() << endl;
}
A.
#include <iostream>
using namespace std;
class Rectangle
{
public:
int width, height;
int getArea();
};
int Rectangle::getArea()
{
return width * height;
}
int main()
{
Rectangle rect;
rect.width = 3;
rect.height = 5;
cout << "μ¬κ°νμ λ©΄μ μ " << rect.getArea() << endl;
}