C++ Programming Ch.5 Exercise 1 Solution

Problem: 두 개의 Circle 객체를 교환하는 swap() 함수를 '참조에 의한 호출'이 되도록 작성하고 호출하는 프로그램을 작성하라. Objective & Hints: 참조에 의한 호출 연습 Execution Result: Code: 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 #include using namespace std; class Circle { int num; public: Circle(); Circle(int num) {this->num = num;} void setNum(int num) {this->num = num;} int getNum() {return num;} }; void swap(Circle &a, Circle &b) { int swap; swap = a.getNum(); a.setNum(b.getNum()); b.setNum(swap); } int main() { Circle a(5), b(10); cout << a.getNum() << " " << b.getNum() << endl; swap(a,b); cout << a.getNum() << " " << b.getNum(); } Explanation: ...

March 5, 2020 · 1 min · Sobamemil