question archive This is a sequential file maintenance program
Subject:Computer SciencePrice: Bought3
This is a sequential file maintenance program. Pseudocode for the sequential file update process is provided below. The input files should be created as indicated in the section below labeled, Test Data for Files. It is important that you enter the data in order by the SSN on both files. You will create New Master File based on the Old Master File and the Transaction File. The maintenance code on the Transaction File indicates whether the record should be added
(A) or changed (C) or deleted (D).
On a change transaction you must determine which fields to move to the New Master File, the
fields from the Old Master File or the fields from the Transaction File. Any field on the
Transaction File that does not need to be changed will contain spaces or zeros depending on
the data type. Any field on the Transaction File that does need to be changed will contain an
actual value.
When there are errors, write the number, maintenance code, and an error description to a log
file. Errors may exist based on the following conditions:
When the record is not on the Master File and is on the Trans File with a maintenance
code other than an A, the error "Record does not exist. Invalid Maintenance Code"
should be the description.
When the record is on the Master File and is on the Trans file with a maintenance code
other than a C or D, the error "Record already exists. Invalid Maintenance code" should
be the description.
Pseudocode for Sequential File Update Process
000-Mainline
? Open files used in program
? Execute module to read TR file (030-Read-Trans)
? Execute module to read OM file (031-Read-Old-Mast)
? Execute module to make comparisons until there are no more records on the TR file OR the
OM file (100-Rec-Proc). This module will execute until one of the files has no more records
to process.
? Must determine what to do with remaining records on file that has not ended
? When EOF reached on TR File first must execute module to move OM to NM fields and
write NM record (420-Copy-Mast) until no more OM records
? When EOF reached on OM File first must execute module to move TR to NM fields and
write NM record (410-Test-Add) until no more TR records
? Close files used in program
030-Read-Trans
? Read TR file when no more records set appropriate EOF field
031-Read-Old-Mast
? Read OM file when no more records set appropriate EOF field
100-Rec-Process
? Comparison to determine how to process record
IF OM common field (SSN) > TR common field (SSN)
(Should be an ADD - TR mntce code = A)
Execute module to add record (410-Test-Add)
ELSE
IF OM common field (SSN) = TR common field (SSN)
(Should be a Change - TR mntce code = C or Should be a Delete - TR mntce code
= D)
IF TR mntce code a Change( C ) or Delete ( D )
Execute module to process changes and deletes (430-Chg-Dlt)
ELSE
(ERROR - Invalid mntce code - Record exists on Mast File)
Move TR fields and appropriate Mntce message to log output fields
Write line to log
Execute module to copy OM to NM (420-Copy-Mast). Notice module 420-Copy -
Mast contains a read of the OM and the OM file needs to be read
Execute modules to read TR File (030-Read-Trans)
END_IF
ELSE
(No change to OM record)
Execute module to move OM to NM and write NM record (420-Copy-Mast)
END-IF
END-IF.
410-Add-Test
? Check value of TR mntce code
o When value is A execute module to add (460-Move-Write-Add)
o When value is not A, an error exists,
(ERROR - Invalid mntce code - Record does not exists on Mstr)
Move TR fields and appropriate Mntce message to log output fields
Write line to log
? Regardless of TR mntce code value, execute module to read TR file (030-Read-Trans)
420-Copy-Mast
? Move OM to NM fields
? Write NM Record
? Execute module to read OM file (031-Read-Mast)
? No log line necessary
430-Chg-Dlt
? Check value of TR mntce code
o When value is C execute module to determine what fields (TR or OM) to move to NM
and write NM record to file (440-Field-Test)
o When value is D (do not write to OM - write to log only)
Move TR fields and appropriate Mntce message to log output fields
Write line to log
? Regardless of TR mntce code value, execute modules to read TR file (030-Read-Trans) and
OM file (031-Read-Old-Mast)
440-Field-Test
? Move common field value (SSN) from TR or OM to NM field
? Check each TR field (except common field) individually to determine whether to move TR
field or OM field to NM field.
IF alphanumeric TR field > spaces
Move TR field to NM field
ELSE
Move OM field to NM field
END-IF
IF numeric TR field > zeros
Move TR field to NM Fields
ELSE
Move OM field to NM field
END-IF
? After all fields have been checked, write NM record
? Record changed - write to log
Move TR fields and appropriate Mntce message to log output fields
Write line to log
460-Move-Write-Add
? Move all necessary TR fields to NM fields
? After all necessary fields have been moved, write NM record
Record added - write to log
Move TR fields and appropriate Mntce message to log output fields
Write line to log
Test Data for Files
Transaction File
Upd Cd
A
SSN
9 S 0
Name
25 A
City
15 A
Stat
e
2 A
Hours
3 S 0
Rate
5 S 2
A 000000100 CARL JOHNSON ROBBINS NC 040 008.00
C 000000200 000 010.00
D 000000350 000 000.00
A 000000500 SHERRY HOLMES LAURINBURG NC 040 006.00
C 000000550 FAYETTEVILLE 000 000.00
A 000000650 APRIL MILLER HOPE MILLS NC 040 008.00
Old Master File
SSN
9 S 0
Name
25 A
City
15 A
Stat
e
2 A
Hours
3 S 0
Rate
5 S 2
Salary
8 S 2
000000120 BEV JACOBS PEMBROKE NC 030 007.00 000210.00
000000200 MARY BELL SOUTHERN PINES NC 040 008.00 000320.00
000000300 SHARON BOONE FAYETTEVILLE NC 040 010.00 000400.00
000000350 DON BLACK RAEFORD NC 040 010.00 000400.00
000000550 DOUG BAREFOOT PINEHURST NC 040 008.00 000320.00
000000600 BOB JONES WEST END NC 040 007.00 000280.00
000000650 APRIL MILLER HOPE MILLS NC 040 011.00 000440.00
000000700 BILL BERRY PINEHURST NC 040 010.00 000400.00
000000750 DONNA CAIN LUMBERTON NC 040 010.00 000400.00
New Master File
SSN
9 S 0
Name
25 A
City
15 A
Stat
e
2 A
Hours
3 S 0
Rate
5 S 2
Salary
8 S 2
Update/Exception Log
Social Security Number Update Code Description
This is the code we need to input all the transaction
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO; //add to process read/write to files
using static System.Console;
/*
* Name:
* Date:
* Desc: Reads from the master and transaction files to create new master file with unchanged
* old master records, added and changed records omitting deleted records. A log file is created
* showing adds, changes, deletes and errors.
*/
namespace SequentialFileProcessingApp
{
class Program
{
//declare variables at global scope
static StreamReader tReader;
static StreamReader mReader;
static string[] oldMasterRec,
transactionRec;
static void Main(string[] args)
{
string transFilePath = "transactions.txt", //in debug direcory
masterFilePath = "old_master.txt"; //in debug direcory
tReader = new StreamReader(transFilePath);
mReader = new StreamReader(masterFilePath);
ReadMaster();
ReadTransaction();
while (oldMasterRec != null && transactionRec != null)
{
RecProcess();
}
if (transactionRec == null)
{
while (oldMasterRec != null)
{
// write old master record to new master record
WriteLine($"SSN {oldMasterRec[0]} No more Trans recs; Old master rec moved to New Master" ); //REMOVE for TESTING ONLY
ReadMaster(); // get next old master record
}
}
if (oldMasterRec == null)
{
while (transactionRec != null)
{
if (transactionRec[0] == "A")
{
//write new record from transaction file to new master file
WriteLine($"SSN {transactionRec[1]} added to New Master; No more old master recs"); //REMOVE for TESTING ONLY
}
else
{
// Error: Invalid Maintenance Code - record does not exist
WriteLine($"ERROR Update Code {transactionRec[0]} SSN {transactionRec[1]} written to log only "); //REMOVE for TESTING ONLY
}
ReadTransaction(); //get next transaction record
}
}
//close files
tReader.Close();
mReader.Close();
WriteLine($"nSequential file processing complete.");
WriteLine("nPress Any Key to exit application...");
ReadKey();
}
public static void ReadMaster()
{
string line;
line = mReader.ReadLine();
if (line != null)
{
oldMasterRec = line.Split('|');
}
else
{
oldMasterRec = null;
}
}
public static void ReadTransaction()
{
string line;
line = tReader.ReadLine();
if (line != null)
{
transactionRec = line.Split('|');
}
else
{
transactionRec = null;
}
}
public static void RecProcess()
{
int mSSN = int.Parse(oldMasterRec[0]),
tSSN = int.Parse(transactionRec[1]);
if (mSSN > tSSN) //new record
{
if (transactionRec[0] == "A")
{
// move records from current transaction file in transactionRec array to fields in new master rec and write new master record, write record added message to log file
WriteLine($"SSN {transactionRec[1]} added to New Master "); //REMOVE for TESTING ONLY
}
else
{
// Write to log file Error: Invalid Maintenance Code - Record does not exist on the master file
WriteLine($"ERROR Update Code {transactionRec[0]} SSN {transactionRec[1]} written to log only "); //REMOVE for TESTING ONLY
}
ReadTransaction();
}
else
{
if (mSSN == tSSN) //change exisitng record id upd code "C" or "D"
{
if (transactionRec[0] == "C" || transactionRec[0] == "D")
{
if (transactionRec[0] == "C")
{
// write record with changes to new master, write record changed to log
WriteLine($"Update Code { transactionRec[0]} SSN {oldMasterRec[0]} changes written to New Master "); //REMOVE for TESTING ONLY
}
else if (transactionRec[0] == "D")
{
//only write to log that record deleted; DO NOT write to new master
WriteLine($"Update Code { transactionRec[0]} SSN {oldMasterRec[0]} Deleted; Do Not move to new master "); //REMOVE for TESTING ONLY
}
}
else
{
//update code invalid write error to log file
WriteLine($"Update Code { transactionRec[0]} SSN {oldMasterRec[0]} ERROR Invalid Update Code"); //REMOVE for TESTING ONLY
}
ReadMaster();
ReadTransaction();
}
else
{
//write old master record to new master - no changes
WriteLine($"SSN {oldMasterRec[0]} Old Master rec moved to New Master "); //REMOVE for TESTING ONLY
ReadMaster();
}
}
}
}
}