C modify the program from exercise 2b so that if

This preview shows page 12 - 21 out of 45 pages.

c. Modify the program from Exercise 2b so that if there is more than one record for a book number, you not only print the book information only once, but also print a count of the total number of times the book was borrowed.
Pseudocode: start perform housekeeping( ) while bothDone = "N" perform mainLoop( ) endwhile perform finishUp( ) stop housekeeping( ) declare variables open files count = 1 perform readJan( ) perform readFeb( ) if janId = 9999 then if febId = 9999 then bothDone = "Y" endif else if janId < febId then write janId, janTitle, janAuthor saveId = janId perform readJan( ) else write febId, febTitle, febAuthor saveId = febId perform readFeb( ) endif endif if janId = 9999 then if febId = 9999 then bothDone = “Y” endif endif return readJan( ) read janRec if eof then janId = 9999 endif return readFeb( )
read febRec if eof then febId = 9999 endif return mainLoop( ) if janId < febId then if janId = saveId then count = count + 1 perform readJan( ) else write count write janId, janTitle, janAuthor saveId = janId count = 1 perform readJan( ) endif else if febId = saveId then count = count + 1 perform readFeb( ) else write count write febId, febTitle, febAuthor saveId = febId count = 1 perform readFeb( ) endif endif if janId = 9999 then if febId = 9999 then bothDone = "Y" endif endif return finishUp( ) write count close files return
Flow Chart:
3. Hearthside Realtors keeps a transaction file for each salesperson in the office. Each transaction record contains the salesperson’s first name, date of the sale, and sale price. The records for the year are sorted in descending sale price order. Two salespeople, Diane and Mark, have formed a partnership. Write the flowchart or pseudocode that produces a merged list of their transactions (including name of salesperson, date, and price) in descending order by price.
else write “Diane”, dianePrice, dianeDate perform readDiane( ) endif if markPrice = 99999999 then if dianePrice = 99999999 then bothDone = "Y" endif endif return finishUp( ) close files return
Flow chart:

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture