Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <sstream>
- #include <fstream>
- #include <iostream>
- #include <vector>
- #include <cstdlib>
- using namespace std;
- class Book
- {
- private:
- string title;
- string authorLastName;
- string authorFirstName;
- string authorMI;
- int isbn;
- double price;
- string publisher;
- int publicationDate;
- int numberPages;
- int inventory;
- public:
- Book(string);
- string getTitle();
- string getAuthorFN();
- string getAuthorLN();
- string getAuthorMI();
- int getISBN();
- double getPrice();
- string getPublisher();
- int getPublicationDate();
- int getPages();
- int getInventory();
- };
- Book::Book(string rowData)
- {
- istringstream columns(rowData);
- string column;
- int counter = 0;
- while (getline(columns, column, ',')) {
- switch (counter) {
- case 0:
- title = column;
- break;
- case 1:
- authorLastName = column;
- break;
- case 2:
- authorFirstName = column;
- break;
- case 3:
- authorMI = column;
- break;
- case 4:
- isbn = stoi(column);
- break;
- case 5:
- price = stoi(column);
- break;
- case 6:
- publisher = column;
- break;
- case 7:
- publicationDate = stoi(column);
- break;
- case 8:
- numberPages = stoi(column);
- break;
- case 9:
- inventory = stoi(column);
- break;
- }
- counter++;
- }
- }
- string Book::getTitle() {
- return title;
- }
- string Book::getAuthorFN() {
- return authorFirstName;
- }
- string Book::getAuthorLN() {
- return authorLastName;
- }
- string Book::getAuthorMI() {
- return authorMI;
- }
- int Book::getISBN() {
- return isbn;
- }
- double Book::getPrice() {
- return price;
- }
- string Book::getPublisher() {
- return publisher;
- }
- int Book::getPublicationDate() {
- return publicationDate;
- }
- int Book::getPages() {
- return numberPages;
- }
- int Book::getInventory() {
- return inventory;
- }
- int main()
- {
- ifstream inputFile;
- inputFile.open("e://books.txt", ios::in);
- if (!inputFile.is_open()) {
- cout << "The file could not be opened or found." << endl;
- system("pause");
- return 1;
- }
- vector<Book> books;
- string rowData;
- getline(inputFile, rowData);
- while (getline(inputFile, rowData)) {
- Book newBook = Book(rowData);
- books.push_back(newBook);
- }
- int userOption, userISBN;
- do {
- cout << "Choose an option from the menu or hit '0' to quit \n\n"
- "1. Display Book Details\n"
- "2. Adjust Inventory counts\n"
- "3. Display Inventory\n\n";
- cin >> userOption;
- cout << endl;
- if (userOption = 1) {
- cout << "Please enter the ISBN number: ";
- cin >> userISBN;
- cout << "\n\n";
- if (userISBN = books[0].getISBN()) {
- cout << "Title: " << books[0].getTitle() << endl;
- cout << "Author: " << books[0].getAuthorFN() << " " << books[0].getAuthorMI() << " " << books[0].getAuthorLN() << endl;
- cout << "Price: $" << books[0].getPrice() << "\n\n";
- } else if (userISBN = books[1].getISBN()) {
- cout << "Title: " << books[1].getTitle() << endl;
- cout << "Author: " << books[1].getAuthorFN() << " " << books[1].getAuthorLN() << endl;
- cout << "Price: $" << books[1].getPrice() << "\n\n";
- } else if (userISBN = books[2].getISBN()) {
- cout << "Title: " << books[2].getTitle() << endl;
- cout << "Author: " << books[2].getAuthorFN() << " " << books[2].getAuthorLN() << endl;
- cout << "Price: $" << books[2].getPrice() << "\n\n";
- } else if (userISBN = books[3].getISBN()) {
- cout << "Title: " << books[3].getTitle() << endl;
- cout << "Author: " << books[3].getAuthorFN() << " " << books[3].getAuthorLN() << endl;
- cout << "Price: $" << books[3].getPrice() << "\n\n";
- } else if (userISBN = books[4].getISBN()) {
- cout << "Title: " << books[4].getTitle() << endl;
- cout << "Author: " << books[4].getAuthorFN() << " " << books[4].getAuthorLN() << endl;
- cout << "Price: $" << books[4].getPrice() << "\n\n";
- } else if (userISBN = books[5].getISBN()) {
- cout << "Title: " << books[5].getTitle() << endl;
- cout << "Author: " << books[5].getAuthorFN() << " " << books[5].getAuthorMI() << " " << books[5].getAuthorLN() << endl;
- cout << "Price: $" << books[5].getPrice() << "\n\n";
- } else if (userISBN = books[6].getISBN()) {
- cout << "Title: " << books[6].getTitle() << endl;
- cout << "Author: " << books[6].getAuthorFN() << " " << books[6].getAuthorLN() << endl;
- cout << "Price: $" << books[6].getPrice() << "\n\n";
- } else if (userISBN = books[7].getISBN()) {
- cout << "Title: " << books[7].getTitle() << endl;
- cout << "Author: " << books[7].getAuthorFN() << " " << books[7].getAuthorLN() << endl;
- cout << "Price: $" << books[7].getPrice() << "\n\n";
- } else if (userISBN = books[8].getISBN()) {
- cout << "Title: " << books[8].getTitle() << endl;
- cout << "Author: " << books[8].getAuthorFN() << " " << books[8].getAuthorLN() << endl;
- cout << "Price: $" << books[8].getPrice() << "\n\n";
- } else if (userISBN = books[9].getISBN()) {
- cout << "Title: " << books[9].getTitle() << endl;
- cout << "Author: " << books[9].getAuthorFN() << " " << books[9].getAuthorMI() << " " << books[9].getAuthorLN() << endl;
- cout << "Price: $" << books[9].getPrice() << "\n\n";
- } else if (userISBN = books[10].getISBN()) {
- cout << "Title: " << books[10].getTitle() << endl;
- cout << "Author: " << books[10].getAuthorFN() << " " << books[10].getAuthorMI() << " " << books[10].getAuthorLN() << endl;
- cout << "Price: $" << books[10].getPrice() << "\n\n";
- } else {
- cout << "The ISBN could not be found";
- }
- }
- else if (userOption = 2) {
- }
- else if (userOption = 3) {
- }
- } while (userOption != 0);
- // for (int i = 0; i < books.size(); i++)
- // {
- // cout << books[i].getTitle() << " -- Number of pages: " << books[i].getPages() << endl;
- // }
- // inputFile.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement