πŸ’» Information/Computer

[C++] μƒμ„±μž, μ†Œλ©Έμž μ •μ‚¬κ°ν˜• νŒλ³„

GigaWatt 2015. 4. 21. 13:46
λ°˜μ‘ν˜•

[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(35);
 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



λ°˜μ‘ν˜•