Guest User

Untitled

a guest
Apr 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. start
  2.  
  3. define SIZE 10
  4. define IDSIZE 14
  5.  
  6. void copyBookInfo(ifstream& fin, num ISBN[], string title[], string author[], char avail[], num fileLength)
  7. num getCardNum(ifstream& fin, num arrayID[])
  8. num lookUpTitle(num ISBN[], num fileLength)
  9. num lookUpISBN(string title[], num fileLength)
  10. void isBookAvailable(char avail[], num value)
  11. bool cardNumTest(num cardNumber, num arrayID[])
  12.  
  13.  
  14. inline bool caseInsCharCompareN(char a, char b)
  15. return(toupper(a) == toupper(b))
  16.  
  17.  
  18. bool caseInsCompare(const string& s1, const string& s2)
  19. return((s1.size() == s2.size()) && equal(s1.begin(),s1.end(),s2.begin(),caseInsCharCompareN))
  20.  
  21.  
  22.  
  23. num choiceNum, userISBN, cardNum, posValue, cardAmount = 13, userTitle, ISBN[SIZE], arrayID[IDSIZE], value
  24. bool available, cardMatch
  25. char correctTitle, avail[SIZE]
  26. string title[SIZE], author[SIZE]
  27. ifstream file input
  28. copyBookInfo(fin, ISBN, title, author, avail, SIZE)
  29. do
  30. cardNum = getCardNum(fin, arrayID)
  31. output "What would you like to search by (1 = ISBN, 2 = Title, 3 = Quit)?: "
  32. input choiceNum
  33. if choiceNum is equal to 1 then
  34. userTitle = lookUpTitle(ISBN, SIZE)
  35. if it is not true that userTitle is equal to -1 then
  36. output "The title of the book is: " title[userTitle]
  37. output "Is this title correct (Y/N)?: "
  38. input correctTitle
  39. if correctTitle is equal to 'Y' OR correctTitle is equal to 'y'
  40. value = userTitle
  41. isBookAvailable(avail, value)
  42. endIf
  43. else
  44. output "No such book exists."
  45. endIf
  46. endIf
  47.  
  48. if choiceNum is equal to 2 then
  49. userISBN = lookUpISBN(title, SIZE)
  50. if it is not true that userISBN is equal to -1 then
  51. output "The ISBN of the book is: " ISBN[userISBN]
  52. value = userISBN
  53. isBookAvailable(avail, value)
  54. else
  55. output "The book you are looking for was not found."
  56. endIf
  57. endIf
  58.  
  59. while it is not true that choiceNum is equal to 3
  60. endDoWhile
  61. stop
  62.  
  63.  
  64.  
  65. void copyBookInfo(ifstream& fin, num ISBN[], string title[], string author[], char avail[], num fileLength)
  66. open bookDb "BookDb.dat"
  67. if file fails to open then
  68. output "Book database failed to open"
  69. exit(0)
  70. endIf
  71.  
  72. num i = 0
  73. fileLength = 0
  74. if file is open then
  75. while input file ISBN[i]
  76. ignore file input(1,tab)
  77. get line(input from file,title[i],tab)
  78. get line(input from file,author[i],tab)
  79. input from file avail[i]
  80. fileLength = fileLength + 1
  81. i = i + 1
  82. endWhile
  83. endIf
  84. close file
  85. return
  86.  
  87.  
  88.  
  89.  
  90. num getCardNum(ifstream& fin, num arrayID[])
  91. num cardNumber
  92. bool numTest
  93. open id.dat "ID.dat"
  94. if file fails to open then
  95. output "ID file failed to open"
  96. exit(0)
  97. endif
  98.  
  99. num i = 0
  100. if the file is open then
  101. while the file input is arrayID[i]
  102. i = i + 1
  103. endWhile
  104. endIf
  105.  
  106. close file
  107.  
  108. do
  109. output "Please enter your card number: "
  110. input cardNumber
  111. numTest = cardNumTest(cardNumber, arrayID)
  112. while numTest is equal to false AND (9999 is less than cardNumber AND cardNumber is less than 1000)
  113. endDoWhile
  114. return cardNumber
  115.  
  116.  
  117.  
  118.  
  119. bool cardNumTest(num cardNumber, num arrayID[])
  120. bool testNum = false
  121. for i = 0, i is less than IDSIZE, step 1
  122. if cardNumber is equal to arrayID[i] then
  123. testNum = true
  124. endIf
  125. endFor
  126. return testNum
  127.  
  128.  
  129.  
  130.  
  131. num lookUpTitle(num ISBN[], int fileLength)
  132. num userISBN, posValue = -1
  133. output "Enter the ISBN: "
  134. input userISBN
  135.  
  136. for i = 0, i is less than fileLength, step 1
  137. if userISBN is equal to ISBN[i] then
  138. posValue = i
  139. break
  140. endIf
  141. endFor
  142. return posValue
  143.  
  144.  
  145.  
  146.  
  147. num lookUpISBN(string title[], num fileLength)
  148. string userTitle
  149. num posValue = -1
  150. num i
  151.  
  152. ignore input()
  153. output "Enter the title: "
  154. get line(input, userTitle)
  155.  
  156. for i = 0, i is less than fileLength, step 1
  157. if caseInsCompare(userTitle, title[i]) then
  158. posValue = i
  159. break
  160. endIf
  161. endFor
  162. return posValue
  163.  
  164.  
  165.  
  166.  
  167. void isBookAvailable(char avail[], num value)
  168. if avail[value] is equal to 'Y' then
  169. output "The book is available!"
  170. else
  171. output "The book is unavailable."
  172. endIf
  173. return
Add Comment
Please, Sign In to add comment