๐Ÿ’ป 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



๋ฐ˜์‘ํ˜•