pls check mainLoop() pseudocode for errors

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2002
Posts: 633
Reputation: aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice 
Solved Threads: 9
Team Colleague
aeinstein's Avatar
aeinstein aeinstein is offline Offline
Team Member - aka kaynine

pls check mainLoop() pseudocode for errors

 
0
  #1
Jul 6th, 2006
Hi All,

The following problem solution has given me fits!!!:mad: The problem states that a library records monthly book withdrawls, capturing the Library of Congress Number, Author and Title, for each month (sorted by the Library of Congress Number for each withdrawl). The initial problem required the merger of the January and Feburary files - which I was able to do without difficulty, but the follow-on problem required that any redundant records, regardless of file of origin, not be written to the merged file. I think I've gotten it, but I've gone through it so many times by now that I'm not sure if I really have it, or if I'm just chasing my tail trying to get a solution. Any help/pointers would be greatly appreciated!

FYI I've included code blocks for the overall program as well as each component module, but it's the mainLoop() module that I'm actually concerned about.

Program pseudocode
  1. comment: merge files "janResources" & "febResources" w/o writing duplicate
  2. comment: resource information (ie, ...LibCongressNum, ...Author & ...Title)
  3. comment: assignment operator is "=" and equals comparison operator is "=="
  4. Start
  5. perform houseKeeping()
  6. while bothAtEof == "N" then
  7. perform mainLoop()
  8. endwhile
  9. perform finishUp()
  10. Stop

houseKeeping() module pseudocode
  1. houseKeeping()
  2. declare variables:
  3. comment: file: "janResources"
  4. char janLibCongressNum = null
  5. char janAuthor = null
  6. char janTitle = null
  7. comment: file: "febResources"
  8. char febLibCongressNum = null
  9. char febAuthor = null
  10. char febTitle = null
  11. comment: end processing flag variable
  12. char bothAtEof = "N"
  13. comment: record comparison variable
  14. char previousLibCongressNum = null
  15. comment: files: "janResources" & "febResources"
  16. open files
  17. read janResources
  18. if eof then
  19. janLibCongressNum = "ZZZZZZZZZZ"
  20. endif
  21. read febResources
  22. if eof then
  23. febLibCongressNum = "ZZZZZZZZZZ"
  24. endif
  25. if janLibCongressNum == "ZZZZZZZZZZ" then
  26. if febLibCongressNum == "ZZZZZZZZZZ" then
  27. bothAtEof = "Y"
  28. endif
  29. endif
  30. return
mainLoop()pseudocode
  1. mainLoop()
  2. comment: if the value of "janLibCongressNum" is < "febLibCongressNum", the
  3. comment: assumption is that "janResources" is not at eof & the record must
  4. comment: be written; subsequent comparison of "janLibCongressNum" ensures
  5. comment: that duplicate resource info is not written to file.
  6. if janLibCongressNum < febLibCongressNum then
  7. if janLibCongressNum == previousLibCongressNum then
  8. while janLibCongressNum == previousLibeCongresNum then
  9. read janResources
  10. endwhile
  11. if eof then
  12. janLibCongressNum = "ZZZZZZZZZZ"
  13. endif
  14. else
  15. set previousLibCongress = janLibCongressNum
  16. write janLibCongressNum, janAuthor, janTitle
  17. read janResources
  18. if eof file then
  19. janLibCongressNum = "ZZZZZZZZZZ"
  20. endif
  21. endif
  22. else
  23. comment: if the value of "janLibCongressNum" is > "febLibCongressNum", the
  24. comment: assumption is that "febResources" is not at eof & the record must
  25. comment: be written; subsequent comparison of "febLibCongressNum" ensures
  26. comment: that duplicate resource info is not written to file.
  27. if febLibCongressNum < janLibCongressNum then
  28. if febLibCongressNum == previousLibCongressNum then
  29. while febLibCongressNum == previouLibCongressNum then
  30. read febResources
  31. endwhile
  32. if eof then
  33. febLibCongressNum = "ZZZZZZZZZZ"
  34. endif
  35. else
  36. set previousLibCongressNum = febLibCongressNum
  37. write febLibCongressNum, febAuthor, febTitle
  38. read febResources
  39. if eof then
  40. febLibCongressNum = "ZZZZZZZZZZ"
  41. endif
  42. endif
  43. else
  44. comment: if the value of "janLibCongressNum" equals "febLibCongressNum",
  45. comment: it must be determined if either record (or both), is a duplicate
  46. comment: record - the easiest way to do this is to determine if the equity
  47. comment: value has already been written, requiring one or the other
  48. comment: variable's value to be compared to the last record written & then
  49. comment: letting the next iteration of "mainLogic()" to process the other
  50. comment: equity value; for simplicity the "janLibCongressNum" variable was
  51. comment: chosen for the first equity camparison.
  52. if janLibCongressNum == febLibCongressNum then
  53. if janLibCongressNum == previousLibCongressNum then
  54. while previousLibCongresNum == janLibCongressNum then
  55. read janResources
  56. endwhile
  57. if eof then
  58. janLibCongressNum = "ZZZZZZZZZZ"
  59. endif
  60. else
  61. set previousLibCongressNum = janLibCongressNum
  62. write janLibCongressNum, janAuthor, janTitle
  63. read janResources
  64. if eof then
  65. janLibCongressNum = "ZZZZZZZZZZ"
  66. endif
  67. endif
  68. endif
  69. endif
  70. endif
  71. if janLibCongressNum == "ZZZZZZZZZZ" then
  72. if janLibCongressNum == "ZZZZZZZZZZ" then
  73. bothAtEof = "Y"
  74. endif
  75. endif
  76. return
  77.  

finishUp() pseudocode
  1. finishUp()
  2. close files
  3. return

TIA
Last edited by aeinstein; Jul 6th, 2006 at 1:49 am.
"I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use." - Galileo Galilei

"Science without religion is lame. Religion without science is blind." - Albert Einstein

"Good judgment comes from experience, experience comes from bad judgment." - author unknown

"Anyone who has never made a mistake has never tried anything new." - Albert Einstein

(why "aeinstein"?)

Peace Be with You
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: pls check mainLoop() pseudocode for errors

 
0
  #2
Jul 6th, 2006
>but the follow-on problem required that any redundant records, regardless of file of origin, not be written to the merged file

The sudo code for this is:-

  1. if ( records = redundant) then
  2. don't write to file
  3. endif
  4. else
  5. write to file
  6. end
  7.  

:lol:
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 1782 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC