๋ฐ์ํ
[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 |
๋ฐ์ํ