944,083 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2223
  • C RSS
Jul 6th, 2006
0

pls check mainLoop() pseudocode for errors

Expand Post »
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.
Similar Threads
Team Colleague
Reputation Points: 186
Solved Threads: 8
Team Member - aka kaynine
aeinstein is offline Offline
643 posts
since May 2002
Jul 6th, 2006
0

Re: pls check mainLoop() pseudocode for errors

>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:
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: why following output ???
Next Thread in C Forum Timeline: Spiral Order Of Matrix





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC