fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Book {
  7. public:
  8. void assign (string, string, int, float);
  9. string getTitle();
  10. string getAuthor();
  11. int getCopyRightYear();
  12. float getPrice();
  13.  
  14. private:
  15. string title;
  16. string author;
  17. int copyRightYear;
  18. float price;
  19. };
  20.  
  21. void Book::assign (string bookTitle, string bookAuthor, int bookDate, float bookPrice) {
  22. title = bookTitle;
  23. author = bookAuthor;
  24. copyRightYear = bookDate;
  25. price = bookPrice;
  26. }
  27.  
  28. string Book::getTitle() { return title; }
  29. string Book::getAuthor() { return author; }
  30. int Book::getCopyRightYear() { return copyRightYear; }
  31. float Book::getPrice() { return price; }
  32.  
  33. int main()
  34. {
  35. cout << "Here are some of my favorite modern books ...\n" << endl;
  36.  
  37. Book b1, b2, b3, b4, b5;
  38.  
  39. b1.assign("Clean Architecture", "Robert C. Martin", 2017, 33.99);
  40. cout << b1.getTitle() << " authored by " << b1.getAuthor() << " in the year " << b1.getCopyRightYear() << endl;
  41. cout << "Price: $" << b1.getPrice() << "\n\n";
  42.  
  43. b2.assign("The Rust Programming Language", "Steve Klabnik & Carol Nichols", 2019, 44.99);
  44. cout << b2.getTitle() << " authored by " << b2.getAuthor() << " in the year " << b2.getCopyRightYear() << endl;
  45. cout << "Price: $" << b2.getPrice() << "\n\n";
  46.  
  47. b3.assign("Designing Data-Intensive Applications", "Martin Kleppmann", 2017, 49.95);
  48. cout << b3.getTitle() << " authored by " << b3.getAuthor() << " in the year " << b3.getCopyRightYear() << endl;
  49. cout << "Price: $" << b3.getPrice() << "\n\n";
  50.  
  51. b4.assign("Python Crash Course, 2nd Edition", "Eric Matthes", 2019, 29.99);
  52. cout << b4.getTitle() << " authored by " << b4.getAuthor() << " in the year " << b4.getCopyRightYear() << endl;
  53. cout << "Price: $" << b4.getPrice() << "\n\n";
  54.  
  55. b5.assign("Kubernetes Up & Running", "Brendan Burns, Joe Beda, Kelsey Hightower", 2019, 39.99);
  56. cout << b5.getTitle() << " authored by " << b5.getAuthor() << " in the year " << b5.getCopyRightYear() << endl;
  57. cout << "Price: $" << b5.getPrice() << "\n\n";
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Here are some of my favorite modern books ...

Clean Architecture authored by Robert C. Martin in the year 2017
Price: $33.99

The Rust Programming Language authored by Steve Klabnik & Carol Nichols in the year 2019
Price: $44.99

Designing Data-Intensive Applications authored by Martin Kleppmann in the year 2017
Price: $49.95

Python Crash Course, 2nd Edition authored by Eric Matthes in the year 2019
Price: $29.99

Kubernetes Up & Running authored by Brendan Burns, Joe Beda, Kelsey Hightower in the year 2019
Price: $39.99