명품 C++ programming 실습 문제 5장 5번

문제 : 다음 Circle 클래스가 있다. 1 2 3 4 5 6 7 8 class Circle{ int radius; public: Circle(int r) {radius =r;} int getRadius() {return radius;} void setRadius(int r) {radius = r;} void show() {cout « “반지름이 " « radius « “인 원” « endl;} }; Circle 객체 b를 a에 더하여 a를 키우고자 다음 함수를 작성하였다. 1 2 3 4 void increaseBy(Circle a, Circle b) { int r = a.getRadius() + b.getRadius(); a.setRadius(r); } 다음 코드를 실행하면 increaseBy() 함수는 목적대로 실행되는가? ...

March 5, 2020 · 2 min · Sobamemil

명품 C++ programming 실습 문제 5장 3번

문제 : 다음과 같이 작동하도록 combine() 함수를 작성하라. 1 2 3 4 5 6 int main() { string text1(“I love you”), text2(“very much”); string text3; // 비어있는 문자열 combine(text1, text2, text3); // text1과 " “, 그리고 text2를 덧붙여 text3 만들기 cout « text3; // “I love you very much” 출력 } 실행 결과 : 목적 및 힌트 : string 클래스와 참조 사용 연습 코드 : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include #include using namespace std; void combine(string t1, string t2, string &t3){ t3 = t1 + " " + t2; } int main() { string text1(“I love you”), text2(“very much”); string text3; // 비어있는 문자열 combine(text1, text2, text3); // text1과 " “, 그리고 text2를 덧붙여 text3 만들기 cout « text3; // “I love you very much” 출력 } 설명 : ...

March 5, 2020 · 1 min · Sobamemil