Gerald's Lines Landscaping service and geralds lawn maintenance are merging their bussiness and want to merge their customer files. Each file contains a customer number, last name, adress, and property area in square feet, and each file is in customer number order. Design the logic for a program that mergeres the two files into one file containg all customers. Assume there are no identical customer numbers

Respuesta :

Answer:

/Psedocode to merge two input files into one output file

Declaration

  File infile1;

  File infile2;

  File outfile;

  number customer_num1;

  number customer_num2;

  string last_name1;

  string last_name2;

  string address1;

  string address2;

  number property_area1;

  number property_area2;

  string filename;

 

Start

  // get the reference for both the input files

  input filename of first file;

  infile1 = open filename in read mode; // customer file1 in read mode

  input filename of second file;

  infile2 = open filename in read mode; // customer file2 in read mode

 

  // get the reference for the output file

  input filename of output file;

  outfile = open filename in write mode; // output file in write mode

 

  // if both the files exists and can be opened

  if(both input files exists and can be opened) then

 

      // read the first record from both the files

      read customer_num1, last_name1, address1, property_area1 from infile1

      read customer_num2, last_name2, address2, property_area2 from infile2

     

      // read till the end of one of the file is reached

      while(end of infile1 has not been reached and end of infile2 has not been reached)

      do

          // check if customer_num1 < customer_num2 , then write the records of first file to output file, and read the next record from first file

          if(customer_num1 < customer_num2 ) then

              write customer_num1, last_name1, address1, property_area1 to outfile

              read customer_num1, last_name1, address1, property_area1 from infile1

          else // else write the records of second file to output file, and read the next record from second file

              write customer_num2, last_name2, address2, property_area2 to outfile

              read customer_num2, last_name2, address2, property_area2 from infile2

          end if;

      end while;

     

      // if first file has not been read till the end, copy the remaining records from first file to output file

      while(end of infile1 has not been reached)

      do

          write customer_num1, last_name1, address1, property_area1 to outfile

          read customer_num1, last_name1, address1, property_area1 from infile1

      end while;

     

      // if second file has not been read till the end, copy the remaining records from second file to output file

      while(end of infile2 has not been reached)

      do

          write customer_num2, last_name2, address2, property_area2 to outfile

          read customer_num2, last_name2, address2, property_area2 from infile2

      end while;

     

      // close the input files and output file

      close infile1;

      close infile2;

      close outfile;

  else

      print("Unable to open input files");

  end if;  

End

Explanation:

RELAXING NOICE
Relax