wheelsmanx

CPS 171 Machine Problem 8

Dec 18th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. // ConsoleApplication14.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <sstream>
  8. #include <fstream>
  9. #include <wctype.h>
  10. #include <vector>
  11. #include "book.h"
  12.  
  13. using namespace std;
  14.  
  15. string fileline;
  16. string stringbuffer;
  17. int intbuffer;
  18. int linenumber = 0;
  19. string titleauthor[2];
  20. int bookNumber = 0;
  21. book bbooks[100];
  22. string author;
  23. string bookname;
  24. vector <book> booksList;
  25.  
  26.  
  27. void printnumberofbooks() {
  28. std :: cout << "Number of books: " << booksList.size() << endl;
  29. for (int i = 0; i < 10; i++) {
  30. booksList[i].printbook();
  31. }
  32. }
  33.  
  34. void crossbookref() {
  35. string tempbufferstring;
  36. int tempbufferint;
  37. ifstream fileisbninput;
  38. fileisbninput.open("C:\\temp\\New Text Document2.txt");
  39. while (!fileisbninput.eof()) {
  40. getline(fileisbninput, tempbufferstring);
  41.  
  42. stringstream convert(tempbufferstring);
  43. if (!(convert >> tempbufferint)) {
  44. tempbufferint = 0;
  45. }
  46. for (int i = 0;i < 9; i++) {
  47. if (booksList[i].getIsbn() == tempbufferint) {
  48. std::cout << "Looking up ISBN : " << tempbufferint << endl;
  49. booksList[i].printbook();
  50. std::cout << endl;
  51. break;
  52. }
  53. else if(i == 8) {
  54. std::cout << "Looking up ISBN : " << tempbufferint << endl;
  55. cout << "Was not able to find the book in the database." << endl << endl;
  56. }
  57.  
  58. }
  59.  
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67. int main()
  68. {
  69. ifstream fileInput;
  70. fileInput.open("C:\\temp\\New Text Document.txt");
  71. while (!fileInput.eof())
  72. {
  73. getline(fileInput, stringbuffer);
  74. titleauthor[linenumber] = stringbuffer;
  75. if (linenumber == 2) {
  76. // every third line convert to int
  77. stringstream convert(stringbuffer);
  78. if ( !(convert >> intbuffer) ) {
  79. intbuffer = 0;
  80. }
  81. author = titleauthor[0];
  82. bookname = titleauthor[1];
  83.  
  84. book newbook = book(author, bookname, intbuffer);
  85. bbooks[bookNumber] = newbook;
  86. bookNumber++;
  87. booksList.push_back(newbook);
  88.  
  89. //cout << titleauthor[0] << endl;
  90. //cout << titleauthor[1] << endl;
  91. //cout << intbuffer << endl;
  92. linenumber = 0;
  93. }else
  94. linenumber++;
  95. }
  96. //printnumberofbooks();
  97. crossbookref();
  98. cout << endl;
  99. system("pause");
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment