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 = 0int 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("청춘"20000300);
    string b;
    cout << "책 이름을 입력하세요>>";
    getline(cin, b);
    if (b < a)
        cout << a.getTitle() << "이 " << b << "보다 뒤에 있구나!" << '\n';
}
cs


+ Recent posts