Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I also provide an example Thanks BACKGROUND: You have been hired by the ACME Sup

ID: 3704051 • Letter: I

Question

I also provide an example Thanks BACKGROUND: You have been hired by the ACME Supply Corporation to write a program to merge the inventory records of two newly acquired stores. Although the inventory records of these two stores are very similar they need a programmer to conflate the two sets of files, remove any erroneous inventory records, and standardize the inventory measures. TASK: Write a program to merge the two inventory files. The format of the inventory files is described below. Each unique item of inventory has been assigned a unique SK number. This SKU number is a self-checking number consisting of a base number and a modulus-10 check- digit suffix. Both files are sorted in SKU number order and the resulting merged file must be in proper order. Note that some inventory items have incorrect SKU numbers (i.e, the self-check fails on these numbers), these items should nor be placed in the merged file but should be sent to a reject file, as described below. Note also that if the identical SKU item appears in both input files, then the item amounts should be suitably combined and reported as one inventory record. COMPLICATIONS: The inventory measures are not uniformly consistent. Some inventory items have amounts expressed in imperial (aka english; aka U.S. Customary Measure) units. The company needs all inventory measures to be in metrie units. Thus if an inventory amount is expressed as an imperial amount, it must be converted to the equivalent metric amount in the merged file. The units of measure (expressed as character codes) that are within the files are: I Square Inches P Pounds (avoirdupois) Kkilos F Feet C Square Centineters M Meters E Each INPUTIOUTPUT: The format for both the input and the output files is: Positions Description 10-18 19-19 20-20 SKU Nunber (right-juatified) Anount (xxxxxxx.x) Blank Unit of Heasure (see above) NOTE: The amount should have one decimal place. Round as necessary. REJECT FILE: Any inventory records that have invalid inventory numbers are written to the reject file. Do not convert units of measure nor attempt to merge them; these records should look exactly like they did on input. IMPLEMENTATION NOTES: For the completed version of this program, use as your source file name "consolidate-py. A starter skeleton program, is available as Be sure the first function in your source file is main0 and list the remaining functions in hierarchical order (as discussed when we reviewed hicrarchy charts). Do not use any global variables. The input files will be "store1.dat" and "store2.dat you wil need to make a (virtual) copy of these files in your directory. To make these virtual copies i.e. symbolic links), use the commands S 1n -8 SPUB/storel.dat storel.dat S 1n -8 SPUB/store2.dat store2.dat The merged output file must be named "merged.dat". The reject output file must be named INSPIRATION: Pattern your conflation logic after the example SPUB.iconflatc.py we developed in class REQUIRED: You are to electronically submit the source program, a source program listing. and the execution results obtained from running your program. Once you have a working program, the following UNIX commands will do what is required script ola112.1og cat -n consolidate.PY s python3 consolidate-pY $ 1s -1 storel.dat store2.dat merged.dat reject.dat $ we merged.dat reject.dat s cat -n merged.dat s cat -n reject.dat exit $ handin "olal12" consolidate-py ola112.1og

Explanation / Answer

#!/usr/bin/python

#program to read two files and merge the contents of two files another file with specific contents

import shutil;

fname1=store1.dat;

fname2=store2.dat;

fname3=merge.dat;

fname4=reject.dat

fname1=open(store1.dat,”r”);

obtain_record(fname1);

fname2=open(store2.dat,”r”);

obtain_record(fname2);

    print();

    print("Merging the content of two file in",fname3);

    with open(fname3, "w") as sku,amt,uom:

        for f in [fname1, fname2]:

            with open(f, "rb") as eof sku,amt,uom:

                shutil.copyfileobj(fd, sku,amt,uom,1024*1024*10);

    print(" Content merged successfully.!");

    print("Want to see ? (y/n): ");

    checkf=input();

    if eof!==’sku,amt,uom':

     with open(fname4,”w”);

        exit();

    else:

        print();

        b=open(fname3,"r");

        print(b.read());

        b.close();

# Function to obtain the inventory items from the specified files

Def obtain_record(file):

Record=file.readline()

If record==’’:

eof=True;

Return eof 0;

Else:

   eof=False;

int sku;

float amt;

int unit_of_measure=record.split();

return eof (sku,amt,unit_of_measure);

#Function to determine the validity of SKU number

Def is_valid_sku(int sku):

Inventory_number=sku/10;

Check_suffix=sku%10;

If check_digit(inventory_number)==check_suffix:

Return True;

Else:

Return False;

#Function to calculate the modulous-10 check-digit of a input parameter

def check_digit(int number):

int crossfoot=0;

while number>0:

int product=(number%10)*2;

crossfoot+=(product/10)+(product%10);

number=number/10;

crossfoot=crossfoot+(number%10);

number=number/10;

return ((10-crossfoot%10)%10);

#Function to check if a record is in English units and convert to metric system

def convert_to_metric(float amount,int unit_of_measure):

if unit_of_measure==’I’:

#convertion from square inches to square centimeters

    amount=amount*6.4516;

    else if unit_of_measure==’C’:

#conversion from pounds to kilograms

    amount=amount*0.45359237;

else:

#conversion from feet to meters

amount=amount*0.3048;

main(): # finally call the main function to complete the merging activity