λ°μν
[C++] μμ±μ, μλ©Έμ μ μ¬κ°ν νλ³μ κ΄ν μ½λ μ λλ€.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include<iostream> using namespace std; class Rectangle { public: int width, height; Rectangle(); Rectangle(int w, int h); Rectangle(int l); int isSquare(); ~Rectangle(); }; Rectangle::Rectangle() { width = height = 1; } Rectangle::Rectangle(int w, int h) { width = w; height = h; } Rectangle::Rectangle(int l) { width = height = l; } int Rectangle::isSquare() { if (width == height) return true; else return false; } Rectangle::~Rectangle() { cout << "λλΉ" << width << " λμ΄" << height; if (isSquare() == 1) cout << " μ "; else cout << " μ§"; cout << "μ¬κ°ν μλ©Έ\n" << endl; } int main() { Rectangle rect1; Rectangle rect2(3, 5); Rectangle rect3(3); if (rect1.isSquare()) cout << "rect1μ μ μ¬κ°νμ΄λ€.\n" << endl; if (rect2.isSquare()) cout << "rect2λ μ μ¬κ°νμ΄λ€.\n" << endl; if (rect3.isSquare()) cout << "rect3λ μ μ¬κ°νμ΄λ€.\n" << endl; } | cs |
λ°μν