• 코드:
​x
 
1
#include <iostream>
2
using namespace std;
3
​
4
class Rect
5
{
6
private:
7
    double height_;
8
    double width_;
9
public:
10
    Rect(double height, double width);  // 생성자 
11
    void DisplaySize();
12
    Rect operator*(double mul) const;
13
};
14
​
15
int main(void)
16
{
17
    Rect origin_rect(10, 20);
18
    Rect changed_rect = origin_rect * 2;
19
    // Rect changed_rect = 3 * origin_rect;
20
    
21
    changed_rect.DisplaySize();
22
    return 0;
23
}
24
​
25
Rect::Rect(double height, double width)
26
{
27
    height_ = height;
28
    width_ = width;
29
}
30
​
31
void Rect::DisplaySize()
32
{
33
    cout << "이 사각형의 높이는 " << this->height_ << "이고, 너비는 " << this->width_ << "입니다." << endl;
34
}
35
​
36
Rect Rect::operator*(double mul) const
37
{
38
    return Rect(height_ * mul, width_ * mul);
39
}
표준입력 & 실행옵션