fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Book {
  5. string title;
  6. int price, pages;
  7. public:
  8. Book(string title = "", int price = 0, int pages = 0) {
  9. this->title = title; this->price = price; this->pages = pages;
  10. }
  11. void show() {
  12. cout << title << ' ' << price << "원 " << pages << " 페이지" << endl;
  13. }
  14. string getTitle() { return title; }
  15.  
  16.  
  17. Book& operator += (const int n) {
  18. this->price += n;
  19. return *this;
  20. }
  21.  
  22. Book& operator -= (const int n) {
  23. this->price -= 500;
  24. return *this;
  25. }
  26. };
  27.  
  28.  
  29. int main() {
  30. Book a("C++ Primer", 28000, 300), b("Advanced C++", 33000, 500);
  31. a += 500; // 책 a의 가격 500원 증가
  32. b -= 500; // 책 b의 가격 500원 감소
  33.  
  34. a.show();
  35. b.show();
  36. }
Success #stdin #stdout 0s 4372KB
stdin
Standard input is empty
stdout
C++ Primer 28500원 300 페이지
Advanced C++ 32500원 500 페이지