Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication14.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <fstream>
- #include <wctype.h>
- #include <vector>
- #include "book.h"
- using namespace std;
- string fileline;
- string stringbuffer;
- int intbuffer;
- int linenumber = 0;
- string titleauthor[2];
- int bookNumber = 0;
- book bbooks[100];
- string author;
- string bookname;
- vector <book> booksList;
- void printnumberofbooks() {
- std :: cout << "Number of books: " << booksList.size() << endl;
- for (int i = 0; i < 10; i++) {
- booksList[i].printbook();
- }
- }
- void crossbookref() {
- string tempbufferstring;
- int tempbufferint;
- ifstream fileisbninput;
- fileisbninput.open("C:\\temp\\New Text Document2.txt");
- while (!fileisbninput.eof()) {
- getline(fileisbninput, tempbufferstring);
- stringstream convert(tempbufferstring);
- if (!(convert >> tempbufferint)) {
- tempbufferint = 0;
- }
- for (int i = 0;i < 9; i++) {
- if (booksList[i].getIsbn() == tempbufferint) {
- std::cout << "Looking up ISBN : " << tempbufferint << endl;
- booksList[i].printbook();
- std::cout << endl;
- break;
- }
- else if(i == 8) {
- std::cout << "Looking up ISBN : " << tempbufferint << endl;
- cout << "Was not able to find the book in the database." << endl << endl;
- }
- }
- }
- }
- int main()
- {
- ifstream fileInput;
- fileInput.open("C:\\temp\\New Text Document.txt");
- while (!fileInput.eof())
- {
- getline(fileInput, stringbuffer);
- titleauthor[linenumber] = stringbuffer;
- if (linenumber == 2) {
- // every third line convert to int
- stringstream convert(stringbuffer);
- if ( !(convert >> intbuffer) ) {
- intbuffer = 0;
- }
- author = titleauthor[0];
- bookname = titleauthor[1];
- book newbook = book(author, bookname, intbuffer);
- bbooks[bookNumber] = newbook;
- bookNumber++;
- booksList.push_back(newbook);
- //cout << titleauthor[0] << endl;
- //cout << titleauthor[1] << endl;
- //cout << intbuffer << endl;
- linenumber = 0;
- }else
- linenumber++;
- }
- //printnumberofbooks();
- crossbookref();
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment