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;
}
'π κ°μΈ νλ λͺ¨μμ§ π > βΊ `23 νκ³ C++ νλ‘κ·Έλλ° λΆνΈ μΊ ν βΊ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[μμ 3-7] Circle ν΄λμ€μ μλ©Έμ μμ± λ° μ€ν (0) | 2023.07.11 |
---|---|
[μμ 3-6] Rectangle ν΄λμ€ λ§λ€κΈ° (0) | 2023.07.11 |
[μμ 3-1] Circle ν΄λμ€μ κ°μ²΄ μμ± λ° νμ© (0) | 2023.07.10 |
[μμ 2-7] string ν΄λμ€λ₯Ό μ΄μ©ν λ¬Έμμ΄ μ λ ₯ λ° λ€λ£¨κΈ° (0) | 2023.07.10 |