Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.83 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <sstream>
  4. #include <fstream>
  5. #include <iostream>
  6. #include <vector>
  7. #include <cstdlib>
  8. using namespace std;
  9.  
  10.  
  11. class Book
  12. {
  13. private:
  14.     string title;
  15.     string authorLastName;
  16.     string authorFirstName;
  17.     string authorMI;
  18.     int isbn;
  19.     double price;
  20.     string publisher;
  21.     int publicationDate;
  22.     int numberPages;
  23.     int inventory;
  24. public:
  25.     Book(string);
  26.     string getTitle();
  27.     string getAuthorFN();
  28.     string getAuthorLN();
  29.     string getAuthorMI();
  30.     int getISBN();
  31.     double getPrice();
  32.     string getPublisher();
  33.     int getPublicationDate();
  34.     int getPages();
  35.     int getInventory();
  36. };
  37.  
  38. Book::Book(string rowData)
  39. {
  40.     istringstream columns(rowData);
  41.     string column;
  42.  
  43.     int counter = 0;
  44.     while (getline(columns, column, ',')) {
  45.         switch (counter) {
  46.         case 0:
  47.             title = column;
  48.             break;
  49.         case 1:
  50.             authorLastName = column;
  51.             break;
  52.         case 2:
  53.             authorFirstName = column;
  54.             break;
  55.         case 3:
  56.             authorMI = column;
  57.             break;
  58.         case 4:
  59.             isbn = stoi(column);
  60.             break;
  61.         case 5:
  62.             price = stoi(column);
  63.             break;
  64.         case 6:
  65.             publisher = column;
  66.             break;
  67.         case 7:
  68.             publicationDate = stoi(column);
  69.             break;
  70.         case 8:
  71.             numberPages = stoi(column);
  72.             break;
  73.         case 9:
  74.             inventory = stoi(column);
  75.             break;
  76.         }
  77.  
  78.         counter++;
  79.     }
  80. }
  81.  
  82. string Book::getTitle() {
  83.     return title;
  84. }
  85. string Book::getAuthorFN() {
  86.     return authorFirstName;
  87. }
  88. string Book::getAuthorLN() {
  89.     return authorLastName;
  90. }
  91. string Book::getAuthorMI() {
  92.     return authorMI;
  93. }
  94. int Book::getISBN() {
  95.     return isbn;
  96. }
  97. double Book::getPrice() {
  98.     return price;
  99. }
  100. string Book::getPublisher() {
  101.     return publisher;
  102. }
  103. int Book::getPublicationDate() {
  104.     return publicationDate;
  105. }
  106. int Book::getPages() {
  107.     return numberPages;
  108. }
  109. int Book::getInventory() {
  110.     return inventory;
  111. }
  112.  
  113.  
  114. int main()
  115. {
  116.     ifstream inputFile;
  117.     inputFile.open("e://books.txt", ios::in);
  118.     if (!inputFile.is_open()) {
  119.         cout << "The file could not be opened or found." << endl;
  120.         system("pause");
  121.         return 1;
  122.     }
  123.  
  124.     vector<Book> books;
  125.  
  126.     string rowData;
  127.     getline(inputFile, rowData);
  128.  
  129.  
  130.     while (getline(inputFile, rowData)) {
  131.         Book newBook = Book(rowData);
  132.         books.push_back(newBook);
  133.     }
  134.  
  135.     int userOption, userISBN;
  136.     do {
  137.         cout << "Choose an option from the menu or hit '0' to quit \n\n"
  138.             "1. Display Book Details\n"
  139.             "2. Adjust Inventory counts\n"
  140.             "3. Display Inventory\n\n";
  141.         cin >> userOption;
  142.         cout << endl;
  143.         if (userOption = 1) {
  144.             cout << "Please enter the ISBN number: ";
  145.             cin >> userISBN;
  146.             cout << "\n\n";
  147.             if (userISBN = books[0].getISBN()) {
  148.                 cout << "Title: " << books[0].getTitle() << endl;
  149.                 cout << "Author: " << books[0].getAuthorFN() << " " << books[0].getAuthorMI() << " " << books[0].getAuthorLN() << endl;
  150.                 cout << "Price: $" << books[0].getPrice() << "\n\n";
  151.             } else if (userISBN = books[1].getISBN()) {
  152.                 cout << "Title: " << books[1].getTitle() << endl;
  153.                 cout << "Author: " << books[1].getAuthorFN() << " " << books[1].getAuthorLN() << endl;
  154.                 cout << "Price: $" << books[1].getPrice() << "\n\n";
  155.             } else if (userISBN = books[2].getISBN()) {
  156.                 cout << "Title: " << books[2].getTitle() << endl;
  157.                 cout << "Author: " << books[2].getAuthorFN() << " " << books[2].getAuthorLN() << endl;
  158.                 cout << "Price: $" << books[2].getPrice() << "\n\n";
  159.             } else if (userISBN = books[3].getISBN()) {
  160.                 cout << "Title: " << books[3].getTitle() << endl;
  161.                 cout << "Author: " << books[3].getAuthorFN() << " " << books[3].getAuthorLN() << endl;
  162.                 cout << "Price: $" << books[3].getPrice() << "\n\n";
  163.             } else if (userISBN = books[4].getISBN()) {
  164.                 cout << "Title: " << books[4].getTitle() << endl;
  165.                 cout << "Author: " << books[4].getAuthorFN() << " " << books[4].getAuthorLN() << endl;
  166.                 cout << "Price: $" << books[4].getPrice() << "\n\n";
  167.             } else if (userISBN = books[5].getISBN()) {
  168.                 cout << "Title: " << books[5].getTitle() << endl;
  169.                 cout << "Author: " << books[5].getAuthorFN() << " " << books[5].getAuthorMI() << " " << books[5].getAuthorLN() << endl;
  170.                 cout << "Price: $" << books[5].getPrice() << "\n\n";
  171.             } else if (userISBN = books[6].getISBN()) {
  172.                 cout << "Title: " << books[6].getTitle() << endl;
  173.                 cout << "Author: " << books[6].getAuthorFN() << " " << books[6].getAuthorLN() << endl;
  174.                 cout << "Price: $" << books[6].getPrice() << "\n\n";
  175.             } else if (userISBN = books[7].getISBN()) {
  176.                 cout << "Title: " << books[7].getTitle() << endl;
  177.                 cout << "Author: " << books[7].getAuthorFN() << " " << books[7].getAuthorLN() << endl;
  178.                 cout << "Price: $" << books[7].getPrice() << "\n\n";
  179.             } else if (userISBN = books[8].getISBN()) {
  180.                 cout << "Title: " << books[8].getTitle() << endl;
  181.                 cout << "Author: " << books[8].getAuthorFN() << " " << books[8].getAuthorLN() << endl;
  182.                 cout << "Price: $" << books[8].getPrice() << "\n\n";
  183.             } else if (userISBN = books[9].getISBN()) {
  184.                 cout << "Title: " << books[9].getTitle() << endl;
  185.                 cout << "Author: " << books[9].getAuthorFN() << " " << books[9].getAuthorMI() << " " << books[9].getAuthorLN() << endl;
  186.                 cout << "Price: $" << books[9].getPrice() << "\n\n";
  187.             } else if (userISBN = books[10].getISBN()) {
  188.                 cout << "Title: " << books[10].getTitle() << endl;
  189.                 cout << "Author: " << books[10].getAuthorFN() << " " << books[10].getAuthorMI() << " " << books[10].getAuthorLN() << endl;
  190.                 cout << "Price: $" << books[10].getPrice() << "\n\n";
  191.             } else {
  192.                 cout << "The ISBN could not be found";
  193.             }
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.         }
  201.         else if (userOption = 2) {
  202.  
  203.         }
  204.         else if (userOption = 3) {
  205.  
  206.         }
  207.  
  208.  
  209.  
  210.  
  211.     } while (userOption != 0);
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.     //  for (int i = 0; i < books.size(); i++)
  244.     //  {
  245.     //      cout << books[i].getTitle() << "  --  Number of pages: " << books[i].getPages() << endl;
  246.     //  }
  247.     //  inputFile.close();
  248.    
  249.         system("pause");
  250.         return 0;
  251.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement