C++ Programming Ch.11 Exercise 9 Solution

Problem: 다음은 Phone 클래스이다. 1 2 3 4 5 6 7 8 9 10 11 class Phone { // 전화 번호를 표현하는 클래스 string name; string telnum; string address; public: Phone(string name="", string telnum="", string address="") { this->name = name; this->telnum = telnum; this->address = address; } }; Phone 클래스의 객체를 입출력하는 아래 코드와 Execution Result를 참조하여 <<, >> 연산자를 작성하고 Phone 클래스를 수정하는 등 프로그램을 완성하라. 1 2 3 Phone girl, boy; cin >> girl >> boy; cout << girl << endl << boy << endl; Execution Result: ...

April 2, 2020 · 2 min · Sobamemil

C++ Programming Ch.7 Exercise 7 Solution

Problem: 2차원 행렬을 추상화한 Matrix 클래스를 활용하는 다음 코드가 있다. 1 2 3 4 5 6 7 8 Matrix a(4,3,2,1), b; int x[4], y[4]={1,2,3,4}; // 2차원 행렬의 4 개의 원소 값 a >> x; // a의 각 원소를 배열 x에 복사. x[]는 {4,3,2,1} b << y; // 배열 y의 원소 값을 b의 각 원소에 설정 for(int i=0; i<4; i++) cout << x[i] << ' '; // x[] 출력 cout << endl; b.show(); (1) <<, >> 연산자 함수를 Matrix의 멤버 함수로 구현하라. ...

March 6, 2020 · 3 min · Sobamemil

C++ Programming Ch.7 Exercise 6 Solution

Problem: 2차원 행렬을 추상화한 Matrix 클래스를 작성하고, show() 멤버 함수와 다음 연산이 가능하도록 연산자를 모두 구현하라. 1 2 3 4 5 6 Matrix a(1,2,3,4), b(2,3,4,5), c; c = a + b; a += b; a.show(); b.show(); c.show(); if(a==c) cout << "a and c are the same" << endl; (1) 연산자 함수를 Matrix의 멤버 함수로 구현하라. (2) 연산자 함수를 Matrix의 프렌드 함수로 구현하라. Execution Result: Objective & Hints: ...

March 6, 2020 · 3 min · Sobamemil

C++ Programming Ch.7 Exercise 5 Solution

Problem: 다음 main()에서 Color 클래스는 3요소(빨강, 초록, 파랑)로 하나의 색을 나타내는 클래스이다(4장 Exercise Problem 1번 참고). 연산자로 색을 더하고, == 연산자로 색을 비교하고자 한다. Execution Result를 참고하여 Color 클래스와 연산자, 그리고 프로그램을 완성하라. 1 2 3 4 5 6 7 8 9 10 11 int main() { Color red(255, 0, 0), blue(0, 0, 255), c; c = red + blue; c.show(); // 색 값 출력 Color fuchsia(255,0,255); if(c == fuchsia) cout << "보라색 맞음"; else cout << "보라색 아님"; } (1) +와 == 연산자를 Color 클래스의 멤버 함수로 구현하라. ...

March 6, 2020 · 3 min · Sobamemil