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

comment: merge files "janResources" & "febResources" w/o writing duplicate 
comment: resource information (ie, ...LibCongressNum, ...Author & ...Title)
comment: assignment operator is "=" and equals comparison operator is "=="
Start
  perform houseKeeping()
  while bothAtEof == "N" then
    perform mainLoop()
  endwhile
  perform finishUp()
Stop

houseKeeping() module pseudocode

houseKeeping()
  declare variables:
  comment: file: "janResources"
    char janLibCongressNum = null
    char janAuthor = null
    char janTitle = null
  comment: file: "febResources"
    char febLibCongressNum = null
    char febAuthor = null
    char febTitle = null
  comment: end processing flag variable
    char bothAtEof = "N"
  comment: record comparison variable
    char previousLibCongressNum = null
  comment: files: "janResources" & "febResources"
  open files
  read janResources
  if eof then
    janLibCongressNum = "ZZZZZZZZZZ"
  endif
  read febResources
  if eof then
    febLibCongressNum = "ZZZZZZZZZZ"
  endif
  if janLibCongressNum == "ZZZZZZZZZZ" then
    if febLibCongressNum == "ZZZZZZZZZZ" then
      bothAtEof = "Y"
    endif
  endif
return

mainLoop()pseudocode

mainLoop()
comment: if the value of "janLibCongressNum" is < "febLibCongressNum", the
comment: assumption is that "janResources" is not at eof & the record must
comment: be written; subsequent comparison of "janLibCongressNum" ensures
comment: that duplicate resource info is not written to file.
  if janLibCongressNum < febLibCongressNum then
    if janLibCongressNum == previousLibCongressNum then
      while janLibCongressNum == previousLibeCongresNum then
        read janResources
      endwhile
      if eof then
        janLibCongressNum = "ZZZZZZZZZZ"
      endif
    else
      set previousLibCongress = janLibCongressNum
      write janLibCongressNum, janAuthor, janTitle
      read janResources
      if eof file then
        janLibCongressNum = "ZZZZZZZZZZ"
      endif
    endif		 
  else
comment: if the value of "janLibCongressNum" is > "febLibCongressNum", the
comment: assumption is that "febResources" is not at eof & the record must
comment: be written; subsequent comparison of "febLibCongressNum" ensures
comment: that duplicate resource info is not written to file.
    if febLibCongressNum < janLibCongressNum then
      if febLibCongressNum == previousLibCongressNum then
        while febLibCongressNum == previouLibCongressNum then
          read febResources
        endwhile
        if eof then
          febLibCongressNum = "ZZZZZZZZZZ"
        endif
      else
        set previousLibCongressNum = febLibCongressNum
        write febLibCongressNum, febAuthor, febTitle
        read febResources
        if eof then
          febLibCongressNum = "ZZZZZZZZZZ"
        endif
      endif
    else 
comment: if the value of "janLibCongressNum" equals "febLibCongressNum",
comment: it must be determined if either record (or both), is a duplicate
comment: record - the easiest way to do this is to determine if the equity
comment: value has already been written, requiring one or the other
comment: variable's value to be compared to the last record written & then
comment: letting the next iteration of "mainLogic()" to process the other
comment: equity value; for simplicity the "janLibCongressNum" variable was
comment: chosen for the first equity camparison.
      if janLibCongressNum == febLibCongressNum then
        if janLibCongressNum == previousLibCongressNum then
          while previousLibCongresNum == janLibCongressNum then
            read janResources
          endwhile
          if eof then
            janLibCongressNum = "ZZZZZZZZZZ"
          endif
        else
          set previousLibCongressNum = janLibCongressNum
          write janLibCongressNum, janAuthor, janTitle
          read janResources
          if eof then
            janLibCongressNum = "ZZZZZZZZZZ"
          endif
        endif
      endif
    endif
  endif
  if janLibCongressNum == "ZZZZZZZZZZ" then
    if janLibCongressNum == "ZZZZZZZZZZ" then
      bothAtEof = "Y"
    endif
  endif
return

finishUp() pseudocode

finishUp()
  close files
return

TIA :)

Member Avatar for iamthwee

>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:-

if ( records = redundant) then
  don't write to file
endif
 else
    write to file
 end

:lol:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.