Retrieved de https://studentshare.org/logic-programming/1603239-array-structure-proposal
https://studentshare.org/logic-programming/1603239-array-structure-proposal.
Array Structure In order to assist the library administrator in managing the daily tasks and the billing department in determining any outstanding payments, three types of details were required to be saved; client’s data, the issuance details and the daily rates for each book. As these details could not be represented by three basic data types, customized data types (class objects) were made to represent the three entities i.e. the client, issuance and daily rate. The ‘Client’ object includes the details about the client i.e. the first and last name, address (data type: string, variable size) and the library number.
The library number is unique for each client and has data type long (4 bytes). A ‘Client’ object would roughly be 34 to 40 bytes in size.The ‘Issuance’ object contains the issuance details of the client. It includes the client’s library number for identification (data type: long, 4 bytes), the book number (unique) of the book issued (data type: long, 4 bytes), the book’s name (data type: string of variable length) and the date of issuing (data type: date, 3 bytes ). The status of the book whether having been returned to the library or not is also saved in the object (data type: Boolean, 1 byte).
An ‘Issuance’ object would roughly be 32 bytes in size.The ‘Daily Rate‘ object comprises of the book’s number (data type: long, 4 bytes) and the daily issue rate (data type: decimal, 5 bytes) of that book. A ‘Daily Rate’ object would be 9 bytes in size.In order to save data comprising of multiple records of clients, issuance and daily rates, arrays were made of these objects.Structural PseudocodeMain Declare maxClients as Integer Declare maxIssuances as IntegerSet maxClients to 20Set maxIssuances to 50Declare Clients[maxClients] as ClientDeclare Issuance[maxIssuances] as IssuanceClients = ReadClientsDataFromFile()Issuance = ReadIssuanceDataFromFile()Declare ClientLibNumDisplay “Enter Client’s Library Number”Input ClientLibNumDisplayClientDetails(parameter: ClientLibNum)DisplayBooksIssued(parameter: ClientLibNum)DisplayClientDuePayments(parameter: ClientLibNum)End ProgramClass ClientDeclare Private First_Name as StringDeclare Private Last_Name as StringDeclare Private Address as StringDeclare Private Library_Number as LongPublic Client()First_Name = “”Last_Name = “”Address = “”Library_Number = 0End ConstructorPublic Subprogram SetFirstName (parameter: fname) First_Name = fnameEnd SubprogramPublic Subprogram SetLastName (parameter: lname) Last_Name = lnameEnd SubprogramPublic Subprogram SetAddress (parameter: add) Address = addEnd SubprogramPublic Subprogram SetLibraryNum (parameter: libnum) Library_Number = libnumEnd SubprogramPublic Subprogram getFirstName () Return First_NameEnd SubprogramPublic Subprogram getLastName () Return Last_NameEnd SubprogramPublic Subprogram getAddress () Return AddressEnd SubprogramPublic Subprogram getLibraryNumber () Return Library_NumberEnd SubprogramEnd ClassClass IssuanceDeclare Library_Number as LongDeclare Book_Name as StringDeclare Book_Number as LongDeclare Date_Issued as DateDeclare Returned as BooleanPublic Issuance()Set Library_Number = 0Set Book_Name = “”Set Book_Number = 0Set Date_Issued = “0/0/0”Set Returned = FalseEnd ConstructorPublic Subprogram SetLibraryNum (parameter: libnum) Library_Number = libnumEnd SubprogramPublic Subprogram SetBookName (parameter: bname) Book_Name = bnameEnd SubprogramPublic Subprogram SetBookNumber (parameter: bnum) Book_Number = bnumEnd SubprogramPublic Subprogram SetDateIssued (parameter: idate) Date_Issued = idateEnd SubprogramPublic Subprogram getLibraryNumber () Return Library_NumberEnd SubprogramPublic Subprogram getBookName () Return Book_NameEnd SubprogramPublic Subprogram getBookNumber () Return Book_NumberEnd SubprogramPublic Subprogram getDateIssued () Return Date_IssuedEnd SubprogramEnd ClassClass BookDailyRatesDeclare Private Book_Number as LongDeclare Private DailyRate as DecimalPublic Subprogram SetBookNum (parameter: libnum) Library_Number = libnumEnd SubprogramPublic Subprogram SetDailyRate (parameter: rate) DailyRate = rateEnd SubprogramPublic Subprogram getBookNum () Return Book_Number End SubprogramPublic Subprogram getDailyRate () Return DailyRate End SubprogramEnd ClassSubProgram DisplayClientDetails(parameter: ClientLibNum) Declare count as Integer Set count = 0 While count < maxClients If (Client[count].
getLibraryNumber() == ClientLibNum) Display “Name:” + Client[count].getFirstName() + Client[count].getLastName() Display “Address: ” + Client[count].getAddress() End If Set count = count + 1 End WhileEnd SubProgramSubProgram DisplayBooksIssued(parameter: ClientLibNum) Declare count as Integer Set count = 0 While count < maxIssuances If (Issuance[count].getLibraryNumber() == ClientLibNum) Display “Book Number:” + Issuance[count].getBookNumber() Display “Book Name: ” + Issuance[count].
getBookName() Display “Date Issued: ” + Issuance[count].getDateIssued()Display “Returned: ” + Issuance[count].getReturned() End If Set count = count + 1 End WhileEnd SubProgramSubProgram DisplayClientDuePayments(parameter: ClientLibNum) Declare count as Integer Declare totalBooks as Integer Declare totalDueAmount Set count = 0 Set totalBooks = 0 Set totalDueAmount = 0 While count < maxIssuances If (Issuance[count].getLibraryNumber() == ClientLibNum AND Issuance[count].getReturned==False) Declare dueAmount as Decimal Declare numOfDays as IntegerDeclare presentDate = Date.Now()Declare dailyRate as DecimalSet dailyRate = getDailyRateOfBook(parameter: Issuance[count].
getBookNumber())Set numOfDays = Issuance[count].getDateIssued() – presentDateSet dueAmount = numOfDays x dailyRate Display “Book Name: ” + Issuance[count].getBookName() Display “Due Payment:” + dueAmount totalBooks = totalBooks + 1 totalDueAmount = totalDueAmount + dueAmount End If Set count = count + 1 End While Display “Total Books Still Issued: ”+ totalBooks Display “Total Unpaid Dues: ” + totalDueAmountEnd SubProgramSub Program getDailyRateOfBook(parameter: book_num) Declare maxBooks as Integer Set maxBooks to 200 Declare BookRates[maxBooks] as BookDailyRates BookRates = ReadBookRatesFromFile()Declare count as IntegerSet count to 0While count < maxBooksIf BookRates[count].
getBookNumber()==book_num Return BookRates[count].getDailyRate()End IfEnd WhileEnd SubProgramReferencesAbout.com (2012). Structured Programming. Retrieved from http://javascript.about.com/library/blstruc3.htm Dalbey, J. (2012). Pseudocode Standards. Retrieved from http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html iJava2 (2012). What is an Array? Design, Logic, Pseudocode of An Array. Retrieved from http://www.ijava2.com/array-design-logic-pseudocode-array/
Read More