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 26 27 28 29 30 31 | #include <iostream> #include <string> using namespace std; 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 << " 페이지" << '\n'; } string getTitle() { return title; } friend bool operator<(string b, Book a); }; bool operator<(string b, Book a) { if (b < a.title) return true; else return false; } int main() { Book a("청춘", 20000, 300); string b; cout << "책 이름을 입력하세요>>"; getline(cin, b); if (b < a) cout << a.getTitle() << "이 " << b << "보다 뒤에 있구나!" << '\n'; } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 7장 6번 (0) | 2018.06.18 |
|---|---|
| 명품 C++ Programming 실습문제 7장 5번 (0) | 2018.06.17 |
| 명품 C++ Programming 실습문제 7장 3번 (0) | 2018.06.17 |
| 명품 C++ Programming 실습문제 7장 2번 (0) | 2018.06.17 |
| 명품 C++ Programming 실습문제 7장 1번 (0) | 2018.06.17 |