fork download
  1. // Attached: Lab_10_Part1
  2. // ===========================================================
  3. // File: Lab_10_Part1
  4. // ===========================================================
  5. // Programmer: Elaine Torrez
  6. // Class: CMPR 121
  7. // ===========================================================
  8.  
  9. #include <iostream>
  10. #include <string>
  11. using namespace std;
  12.  
  13. class Book
  14. {
  15. private:
  16. string isbn;
  17. int year;
  18. double price;
  19. static int bookCount;
  20.  
  21. public:
  22. Book()
  23. {
  24. isbn = "";
  25. year = 0;
  26. price = 0.0;
  27. bookCount++;
  28. }
  29.  
  30. Book(string bookIsbn, int bookYear, double bookPrice)
  31. {
  32. isbn = bookIsbn;
  33. year = bookYear;
  34. price = bookPrice;
  35. bookCount++;
  36. }
  37.  
  38. void displayBook() const
  39. {
  40. cout << "ISBN: " << isbn << endl;
  41. cout << "Year: " << year << endl;
  42. cout << "Price: " << price << endl;
  43. }
  44.  
  45. int getCount()
  46. {
  47. return bookCount;
  48. }
  49. };
  50.  
  51. int Book::bookCount = 0;
  52.  
  53. int main()
  54. {
  55. Book bookOne("0-12345-9", 1990, 12.50);
  56. Book bookTwo("0-54321-9", 2001, 7.75);
  57. Book bookThree;
  58.  
  59. cout << "Here is book #1:\n";
  60. bookOne.displayBook();
  61.  
  62. cout << endl;
  63. cout << "Here is book #2:\n";
  64. bookTwo.displayBook();
  65.  
  66. cout << endl;
  67. cout << "There are " << bookOne.getCount() << " books.\n";
  68.  
  69. return 0;
  70. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Here is book #1:
ISBN:  0-12345-9
Year:  1990
Price: 12.5

Here is book #2:
ISBN:  0-54321-9
Year:  2001
Price: 7.75

There are 3 books.