Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start
- define SIZE 10
- define IDSIZE 14
- void copyBookInfo(ifstream& fin, num ISBN[], string title[], string author[], char avail[], num fileLength)
- num getCardNum(ifstream& fin, num arrayID[])
- num lookUpTitle(num ISBN[], num fileLength)
- num lookUpISBN(string title[], num fileLength)
- void isBookAvailable(char avail[], num value)
- bool cardNumTest(num cardNumber, num arrayID[])
- inline bool caseInsCharCompareN(char a, char b)
- return(toupper(a) == toupper(b))
- bool caseInsCompare(const string& s1, const string& s2)
- return((s1.size() == s2.size()) && equal(s1.begin(),s1.end(),s2.begin(),caseInsCharCompareN))
- num choiceNum, userISBN, cardNum, posValue, cardAmount = 13, userTitle, ISBN[SIZE], arrayID[IDSIZE], value
- bool available, cardMatch
- char correctTitle, avail[SIZE]
- string title[SIZE], author[SIZE]
- ifstream file input
- copyBookInfo(fin, ISBN, title, author, avail, SIZE)
- do
- cardNum = getCardNum(fin, arrayID)
- output "What would you like to search by (1 = ISBN, 2 = Title, 3 = Quit)?: "
- input choiceNum
- if choiceNum is equal to 1 then
- userTitle = lookUpTitle(ISBN, SIZE)
- if it is not true that userTitle is equal to -1 then
- output "The title of the book is: " title[userTitle]
- output "Is this title correct (Y/N)?: "
- input correctTitle
- if correctTitle is equal to 'Y' OR correctTitle is equal to 'y'
- value = userTitle
- isBookAvailable(avail, value)
- endIf
- else
- output "No such book exists."
- endIf
- endIf
- if choiceNum is equal to 2 then
- userISBN = lookUpISBN(title, SIZE)
- if it is not true that userISBN is equal to -1 then
- output "The ISBN of the book is: " ISBN[userISBN]
- value = userISBN
- isBookAvailable(avail, value)
- else
- output "The book you are looking for was not found."
- endIf
- endIf
- while it is not true that choiceNum is equal to 3
- endDoWhile
- stop
- void copyBookInfo(ifstream& fin, num ISBN[], string title[], string author[], char avail[], num fileLength)
- open bookDb "BookDb.dat"
- if file fails to open then
- output "Book database failed to open"
- exit(0)
- endIf
- num i = 0
- fileLength = 0
- if file is open then
- while input file ISBN[i]
- ignore file input(1,tab)
- get line(input from file,title[i],tab)
- get line(input from file,author[i],tab)
- input from file avail[i]
- fileLength = fileLength + 1
- i = i + 1
- endWhile
- endIf
- close file
- return
- num getCardNum(ifstream& fin, num arrayID[])
- num cardNumber
- bool numTest
- open id.dat "ID.dat"
- if file fails to open then
- output "ID file failed to open"
- exit(0)
- endif
- num i = 0
- if the file is open then
- while the file input is arrayID[i]
- i = i + 1
- endWhile
- endIf
- close file
- do
- output "Please enter your card number: "
- input cardNumber
- numTest = cardNumTest(cardNumber, arrayID)
- while numTest is equal to false AND (9999 is less than cardNumber AND cardNumber is less than 1000)
- endDoWhile
- return cardNumber
- bool cardNumTest(num cardNumber, num arrayID[])
- bool testNum = false
- for i = 0, i is less than IDSIZE, step 1
- if cardNumber is equal to arrayID[i] then
- testNum = true
- endIf
- endFor
- return testNum
- num lookUpTitle(num ISBN[], int fileLength)
- num userISBN, posValue = -1
- output "Enter the ISBN: "
- input userISBN
- for i = 0, i is less than fileLength, step 1
- if userISBN is equal to ISBN[i] then
- posValue = i
- break
- endIf
- endFor
- return posValue
- num lookUpISBN(string title[], num fileLength)
- string userTitle
- num posValue = -1
- num i
- ignore input()
- output "Enter the title: "
- get line(input, userTitle)
- for i = 0, i is less than fileLength, step 1
- if caseInsCompare(userTitle, title[i]) then
- posValue = i
- break
- endIf
- endFor
- return posValue
- void isBookAvailable(char avail[], num value)
- if avail[value] is equal to 'Y' then
- output "The book is available!"
- else
- output "The book is unavailable."
- endIf
- return
Add Comment
Please, Sign In to add comment