fork download
  1. //*******************************************************
  2. //
  3. // Homework: 3
  4. //
  5. // Name: Naomi Jones
  6. //
  7. // Class: Survey, Summer 2025
  8. //
  9. // Date: June 15, 2025
  10. //
  11. // Description: Program which prints "my five
  12. // favorite books".
  13. //
  14. //
  15. //********************************************************
  16.  
  17. #include <iostream>
  18. #include <string>
  19.  
  20. using namespace std;
  21.  
  22. // class Book
  23. // with six private data fields: book title, author, copyright, price, binding, and pages
  24. // six public methods to retrieve fields (called "getters")
  25. // and one public non-default constructor
  26.  
  27. class Book {
  28.  
  29. public:
  30.  
  31. // member function prototypes
  32. void assign (string, string, int, float, string, int); // this is your constructor
  33. string getTitle(); // these are getter functions
  34. string getAuthor();
  35. int getDate();
  36. float getPrice();
  37. string getBinding();
  38. int getPages();
  39.  
  40.  
  41. private:
  42.  
  43. // data members
  44. string title;
  45. string author;
  46. int date;
  47. float price;
  48. string binding;
  49. int pages;
  50. };
  51.  
  52.  
  53. // these are the actual member functions
  54.  
  55. // this member function is a "constructor" that will create a new book
  56. void Book::assign (string bookTitle, string bookAuthor, int bookDate, float bookPrice, string bookBinding, int bookPages) {
  57. title = bookTitle;
  58. author = bookAuthor;
  59. date = bookDate;
  60. price = bookPrice;
  61. binding = bookBinding;
  62. pages = bookPages;
  63. }
  64.  
  65. // this member function is a "getter" that will retrieve that book title value
  66. string Book::getTitle() {
  67. return title;
  68. }
  69.  
  70. // this member function is a "getter" that will retrieve the primary book author value
  71. string Book::getAuthor() {
  72. return author;
  73. }
  74.  
  75. // this member function is a "getter" that will retrieve the year the book was copyrighted
  76. int Book::getDate() {
  77. return date;
  78. }
  79.  
  80. // this member function is a "getter" that will retrieve the list price of the book
  81. float Book::getPrice() {
  82. return price;
  83. }
  84.  
  85. // this member function is a "getter" that will retrieve the binding
  86. string Book::getBinding() {
  87. return binding;
  88. }
  89.  
  90. // this member function is a "getter" that will retrieve the number of pages
  91. int Book::getPages() {
  92. return pages;
  93. }
  94.  
  95.  
  96.  
  97. int main()
  98.  
  99. {
  100.  
  101. // Set up space to create 5 instances of the class Book to use with our constructor
  102. Book b1, b2, b3, b4, b5;
  103.  
  104. // TODO: Step 1) Use our assign constructor to create the first book, use b1
  105.  
  106. b1.assign ("Reading Jackie", "William Kuhn", 2010, 27.95, "hardcover", 368);
  107.  
  108. // TODO: Step 2) Use assign constructor again to create another book, again, use b2
  109.  
  110. b2.assign ("Camera Girl", "Carl Sferrazza Anthony", 2023, 29.99, "hardcover", 400);
  111.  
  112. // TODO: Step 3) Use constructor (its called assign) again to create and print book 3 information, use b3
  113.  
  114. b3.assign ("The Estate of Jacqueline Kennedy Onassis", "Sotheby's", 1996, 45.00, "paperback", 584);
  115.  
  116. // TODO: Step 4) Use constructor again to create and then print information about book 4, use b4
  117.  
  118. b4.assign ("Jackie, Janet & Lee", "J. Randy Taraborrelli", 2018, 19.99, "paperback", 576);
  119.  
  120. // TODO: Step 5) Use constructor again to create and then print information about book 5, use b5
  121.  
  122. b5.assign ("Ask Not", "Maureen Callahan", 2024, 32.99, "hardcover", 400);
  123.  
  124.  
  125. cout << "Here are some of my favorite books ...\n" << endl;
  126.  
  127. // print book details
  128. cout << b1.getTitle() << " authored by " << b1.getAuthor() << " in the year " << b1.getDate() << "." << endl;
  129. cout << "The price of this book is: $" << b1.getPrice() << "." << endl;
  130. cout << "The binding is " << b1.getBinding() << "." << endl;
  131. cout << "The number of pages is " << b1.getPages() << "." << endl;
  132. cout << "\n" << endl;
  133.  
  134. cout << b2.getTitle() << " authored by " << b2.getAuthor() << " in the year " << b2.getDate() << "." << endl;
  135. cout << "The price of this book is: $" << b2.getPrice() << "." << endl;
  136. cout << "The binding is " << b2.getBinding() << "." << endl;
  137. cout << "The number of pages is " << b2.getPages() << "." << endl;
  138. cout << "\n" << endl;
  139.  
  140. cout << b3.getTitle() << " authored by " << b3.getAuthor() << " in the year " << b3.getDate() << "." << endl;
  141. cout << "The price of this book is: $" << b3.getPrice() << "." << endl;
  142. cout << "The binding is " << b3.getBinding() << "." << endl;
  143. cout << "The number of pages is " << b3.getPages() << "." << endl;
  144. cout << "\n" << endl;
  145.  
  146. cout << b4.getTitle() << " authored by " << b4.getAuthor() << " in the year " << b4.getDate() << "." << endl;
  147. cout << "The price of this book is: $" << b4.getPrice() << "." << endl;
  148. cout << "The binding is " << b4.getBinding() << "." << endl;
  149. cout << "The number of pages is " << b4.getPages() << "." << endl;
  150. cout << "\n" << endl;
  151.  
  152. cout << b5.getTitle() << " authored by " << b5.getAuthor() << " in the year " << b5.getDate() << "." << endl;
  153. cout << "The price of this book is: $" << b5.getPrice() << "." << endl;
  154. cout << "The binding is " << b5.getBinding() << "." << endl;
  155. cout << "The number of pages is " << b5.getPages() << "." << endl;
  156. cout << "\n" << endl;
  157.  
  158. return (0);
  159. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Here are some of my favorite books ...

Reading Jackie authored by William Kuhn in the year 2010.
The price of this book is: $27.95.
The binding is hardcover.
The number of pages is 368.


Camera Girl authored by Carl Sferrazza Anthony in the year 2023.
The price of this book is: $29.99.
The binding is hardcover.
The number of pages is 400.


The Estate of Jacqueline Kennedy Onassis authored by Sotheby's in the year 1996.
The price of this book is: $45.
The binding is paperback.
The number of pages is 584.


Jackie, Janet & Lee authored by J. Randy Taraborrelli in the year 2018.
The price of this book is: $19.99.
The binding is paperback.
The number of pages is 576.


Ask Not authored by Maureen Callahan in the year 2024.
The price of this book is: $32.99.
The binding is hardcover.
The number of pages is 400.