Problem 18.docx

  • Uploaded by: Jan Ryan R. Relunia
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Problem 18.docx as PDF for free.

More details

  • Words: 484
  • Pages: 3
The Apgar Medical Group keeps a patient file for each doctor in the office. Each record contains... Question: The Apgar Medical Group keeps a patient file for each doctor in the office. Each record contains the patient's first and last name, home address, and birth year. The records are sorted in ascending order by birth year. Two doctors, Dr. Best and Dr. Cushing, have formed a partnership. Using pseudocode, design the logic that produces a merged list of their patients in ascending order by birth year. Then modify the program so it does not display patients' names but only produces the number of patients born each year.

Algorithms, Merging two Sorted Lists: To design the logic asked for in the question, we'll apply a merging algorithm to combine two sorted lists of records into a single sorted list by visiting the records of both lists, comparing them record by record and adding the smaller record to the final list each time until all of the records of both lists have been visited.

Answer and Explanation: We will represent the person medical record as follows:

struct PersonRecord { string first_name; string last_name; int date_of_birth; }; /*

The input will be two lists that are already sorted based on date of birth. In most modern programming languages, a sorted list is usually represented as an array or a vector where each element can be referenced by an index. The algorithm below is a straightforward way to combine the two sorted lists.

*/

int i = 0; // index to track Dr A's list int j = 0; // index to track Dr B's list int k = 0; // index to track combined list PersonRecord combined_list[drbest.length + drcushing.length]; while (i < drbest.length and j
This loop will add the remaining records from Dr. Best's list:

while (i < drbest.length) { combined_list[k] = drbest[i]; i = i + 1; k = k + 1; }

This loop will add the remaining records from Dr. Cushing's list:

while (j < drcushing.length)

{ combined_list[k] = drcushing[j]; j = j + 1; k = k + 1; } /*

At this point both list were merged into one. To output the records, just iterate on every record and print the names and date of birth:

*/ for (i = 0; i < combined_list.length; i=i+1) { print first_name, last_name, date_of_birth } count = 1; // count of people date of birth date_of_birth = combined_list[0].date_of_birth for (i = 1; i < combined_list.length; i=i+1) { if (combined_list[i].date_of_birth != date_of_birth) { print date_of_birth, count count = 1

// reset the count

} else { count = count + 1 } } print date_of_birth, count

// same date of birth as previous record

Related Documents

Problem
June 2020 31
Problem
June 2020 29
Problem
December 2019 39
Problem
December 2019 43
Problem
May 2020 21
Problem
November 2019 33

More Documents from ""

Problem 18.docx
April 2020 6
Problem 20.docx
April 2020 8
Prob16 - 20.pptx
April 2020 6
Problem07-10.pptx
April 2020 5
001
August 2019 32
Golicyn_klamstwa
June 2020 19