Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Book {
  7.     public:
  8.         Book MyBook();
  9.  
  10.         void setBookTitle(string i) {
  11.             bookTitle = i;
  12.         }
  13.  
  14.         string getBookTitle() {
  15.             return bookTitle;
  16.         }
  17.  
  18.         void setAuthor(string j) {
  19.             author = j;
  20.         }
  21.  
  22.         string getAuthor() {
  23.             return author;
  24.         }
  25.  
  26.         void setPrice(double k) {
  27.             price = k;
  28.         }
  29.  
  30.         double getPrice() {
  31.             return price;
  32.         }
  33.  
  34.         void setAmountOfCopies(int l) {
  35.             amountOfCopies = l;
  36.         }
  37.  
  38.         int getAmountOfCopies() {
  39.             return amountOfCopies;
  40.         }
  41.  
  42.         double CalcSalePrice() {
  43.             int discount;
  44.             cout << "Please enter discount percentage: ";
  45.             cin >> discount;
  46.             price = price - (price * (discount / 100));
  47.             return price;
  48.         }
  49.  
  50.         int BookSold() {
  51.             int soldCopies;
  52.             cout << "Please enter the amount of copies sold: ";
  53.             cin >> soldCopies;
  54.             amountOfCopies = amountOfCopies - soldCopies;
  55.             return 0;
  56.         }
  57.  
  58.         void DisplayInfo() {
  59.             cout << "Title: " << bookTitle << endl;
  60.             cout << "Author: " << author << endl;
  61.             cout << "Price: R" << price << endl;
  62.             cout << "Copies Left: " << amountOfCopies << endl;
  63.         }
  64.  
  65.     private:
  66.         //book title
  67.         string bookTitle;
  68.         //name of the author
  69.         string author;
  70.         //price of the book
  71.         double price;
  72.         //amount of copies in stock
  73.         int amountOfCopies;
  74. };
  75.  
  76. void bookInput()
  77. {
  78.     string title, author;
  79.     int copies;
  80.     double price;
  81.  
  82.     Book HarryPooter;
  83.     cout << "Please enter the title of the Book: ";
  84.     getline(cin, title);
  85.     HarryPooter.setBookTitle(title);
  86.     cout << "Please enter the author: ";
  87.     getline(cin, author);
  88.     HarryPooter.setAuthor(author);
  89.     cout << "Please enter the price: R";
  90.     cin >> price;
  91.     HarryPooter.setPrice(price);
  92.     cout << "Please enter the amount of copies in stock: ";
  93.     cin >> copies;
  94.     HarryPooter.setAmountOfCopies(copies);
  95. }
  96.  
  97. int main()
  98. {
  99.     bookInput();
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement