명품 C++ programming 실습 문제 7장 9번

문제 : 문제 8번의 Circle 객체에 대해 다음 연산이 가능하도록 연산자를 구현하라. 1 2 3 4 Circle a(5), b(4); b = 1+a; // b의 반지름을 a의 반지름에 1을 더한 것으로 변경 a.show(); b.show(); 2020/03/06 - [C++/명품 C++ programming] - 명품 C++ programming 실습 문제 7장 8번 [명품 C++ programming 실습 문제 7장 8번 문제 : 원을 추상화한 Circle 클래스는 간단히 아래와 같다. 1 2 3 4 5 6 class Circle{ int radius; public: Circle(int radius=0) { this->radius = radius; } void show() { cout « “radius = " « radius «.. ...

March 6, 2020 · 2 min · Sobamemil

명품 C++ programming 실습 문제 7장 8번

문제 : 원을 추상화한 Circle 클래스는 간단히 아래와 같다. 1 2 3 4 5 6 class Circle{ int radius; public: Circle(int radius=0) { this->radius = radius; } void show() { cout « “radius = " « radius « " 인 원” « endl; } }; 다음 연산이 가능하도록 연산자를 프렌드 함수로 작성하라. 1 2 3 4 5 Circle a(5), b(4); ++a; // 반지름을 1 증가 시킨다. b = a++; // 반지름을 1 증가 시킨다. a.show(); b.show(); 실행 결과 : ...

March 6, 2020 · 2 min · Sobamemil

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

문제 : 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 실습 문제 7장 5번

문제 : 다음 main()에서 Color 클래스는 3요소(빨강, 초록, 파랑)로 하나의 색을 나타내는 클래스이다(4장 실습 문제 1번 참고). 연산자로 색을 더하고, == 연산자로 색을 비교하고자 한다. 실행 결과를 참고하여 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

명품 C++ programming 실습 문제 7장 4번

문제 : 1번 ~ 4번 문제까지 사용될 Book 클래스는 다음과 같습니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Book{ string title; int price, pages; public: Book(string title="", int price=0, int pages=0){ this->title = title; this->price = price; this->pages = pages; } void show() { cout « title « " " « price « “원 " « pages « " 페이지” « endl; } string getTitle() { return title; } }; 다음 연산을 통해 책의 제목을 사전 순으로 비교하고자 한다. ...

March 6, 2020 · 2 min · Sobamemil

명품 C++ programming 실습 문제 7장 2번

문제 : 1번 ~ 4번 문제까지 사용될 Book 클래스는 다음과 같습니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Book{ string title; int price, pages; public: Book(string title="", int price=0, int pages=0){ this->title = title; this->price = price; this->pages = pages; } void show() { cout « title « " " « price « “원 " « pages « " 페이지” « endl; } string getTitle() { return title; } }; Book 객체를 활용하는 사례이다. ...

March 6, 2020 · 4 min · Sobamemil

명품 C++ programming 실습 문제 7장 1번

문제 : 1번 ~ 4번 문제까지 사용될 Book 클래스는 다음과 같습니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Book{ string title; int price, pages; public: Book(string title="", int price=0, int pages=0){ this->title = title; this->price = price; this->pages = pages; } void show() { cout « title « " " « price « “원 " « pages « " 페이지” « endl; } string getTitle() { return title; } }; Book 객체에 대해 다음 연산을 하고자 한다. ...

March 6, 2020 · 3 min · Sobamemil