C++ Programming Ch.7 Exercise 9 Solution
Problem: λ¬Έμ 8λ²μ Circle κ°μ²΄μ λν΄ λ€μ μ°μ°μ΄ κ°λ₯νλλ‘ μ°μ°μλ₯Ό ꡬννλΌ. 1 2 3 4 Circle a(5), b(4); b = 1+a; // bμ λ°μ§λ¦μ aμ λ°μ§λ¦μ 1μ λν κ²μΌλ‘ λ³κ²½ a.show(); b.show(); Execution Result: Objective & Hints: νλ λ ν¨μλ‘ μ°μ°μ ꡬν μ°μ΅ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include using namespace std; class Circle{ int radius; public: Circle(int radius=0) { this->radius = radius; } void show() { cout << "radius = " << radius << " μΈ μ" << endl; } friend Circle operator+ (int x, Circle c); }; Circle operator+ (int x, Circle c){ c.radius += x; return c; } int main() { Circle a(5), b(4); b = 1+a; // bμ λ°μ§λ¦μ aμ λ°μ§λ¦μ 1μ λν κ²μΌλ‘ λ³κ²½ a.show(); b.show(); }