Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output) cycle that is the engine of many imperative programs

In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output) cycle that is the engine of many imperative programs used for processing large amounts of data. Daisy is recently hired by a warehouse. One of her jobs is to keep track of the items ordered by all branches of the company. The company wants to automate the task using a computer program. Being a friend of Daisy, she knows you are a Computer Science major; and she recommended outsourcing the contract for writing the computer program to you. However, the timeline is short; and you only have a limited time to finish the job. The following is a description on the requirements: General requirements: o The program you write must be a Python 3.x program, it cannot be written in any other language, not even in Python 2.x. You have to provide source code, and the company will run your program on a standard Python 3 implementation (without additional installed libraries and/or packages). Your program should produce no errors and/or warnings during execution. o Your program will be a console program. There is no need to produce a window-based graphical user interface. o Your program will have a main function named main. It takes two parameters. The first one being the name of the input data file, and the second is the name of the output result file; both parameters are strings. You can assume that both the input and output files can be open without any problem. Therefore, there is no need to check for the result of opening the files. Input requirements: o The input data file is guaranteed to contain only numbers and plus or minus signs, as well as the space and newline characters. o The first line has only one (1) number, representing the number of items the system should manage. This number is guaranteed to be less than or equal to ten thousand (10,000). o Each of the subsequent lines is a transaction line which contains exactly two (2) numbers, separated by one or more space characters. The first number is an integer representing the item number (the items are numbered from 1 onward); and the second number is an integer representing the quantity ordered by the branches. The two numbers are separated by one or more space characters. o The number of transaction lines is not known in advance but guaranteed to be less than or equal to 1 billion (1,000,000,000).

Output requirements: o For each order line read, you need to echo the line to the output, using the format '%5d %10d' (or the appropriate alternative if you are using the new f-string in Python 3). o If the order data is not valid, you need to output the reason why it is not valid on the same line of the echoed output, using the format '%5d %10d %s'. All invalid orders must be echoed but ignored in the processing. o The followings explain the error conditions (in the following, n represents the number of items involved that is, the number read in on the first line of the input file, and in the example outputs represents a space character): If the item number is not between 1 and n, inclusively, the item is invalid: 13562invaliditemnumber If the quantity is not a positive value, it is invalid: 80-648invalidquantity 850invalidquantity If a line has multiple errors, only one error needs to be reported. The following shows the priority of errors, from high to low: Invalid item. Invalid quantity. The following example shows the echoed line in case of multiple errors: 179-633invaliditemnumber o After you have echoed all order lines, you should output the number of valid orders in a separate line. There should be a single blank line before and after this line. The format should be '%10d'. o After that, you need to output a summary for all items, if and only if there are any orders for that item. The format, again, should be '%5d %10d'. o All lines in the output file should have no trailing space or tab characters.

As an example, executing the program on the provided data-small.txt input file should produce the following output: 76 551 29 716 64 97 135 62 invalid item number 68 483 58 319 95 174 74 342 35 504 62 604 52 102 64 351 80 -684 invalid quantity 82 114 30 322 71 523 42 344 85 0 invalid quantity 82 761 4 480 16 844 87 157 95 505 91 878 11 592 179 -633 invalid item number 5 770 90 857 159 795 invalid item number

-22 127 invalid item number 51 485 92 333 7 918 56 555 90 765 9 695 5 992 -33 -697 invalid item number 24 771 11 346 8 664 49 668 -56 597 invalid item number 34 294 97 743 80 887 99 933 11 113 44 62 22 310 Number of Valid Orders = 42 Summary: 4 480 5 1762 7 918 8 664 9 695 11 1051 16 844 22 310 24 771 29 716 30 322 34 294 35 504 42 344 44 62 49 668 51 485 52 102 56 555 58 319 62 604 64 448 68 483 71 523 74 342 76 551

80 887 82 875 87 157 90 1622 91 878 92 333 95 679 97 743 99 933

Additional information and requirement: 1. Your program code should adhere to the PEP-8 standard (see below). 2. Your program should contain at least three (3) top-level functions (including the main function). You probably will end up having more than 3 functions. 3. You cannot have any import statement in your program. 4. You cannot have any global variables (that is, no variable can be defined outside a function, and the global keyword cannot be used inside a function). 5. You cannot have any class definition in your program (this assignment is NOT about object-oriented programming). 6. You cannot have anything other than top-level function definitions in your program (not even a call to the main function the tester will call it). 7. Since you know the number of items only when you run the program, you will need some sort of lists or matrices to hold the summary data. 8. Since there can be potentially up to 1 billion transactions in the input data file. You cannot read them all into a list and process them later (doing so may cause an out-of-memory error), you must process them as you read them in. 9. Your program must be a Python 3.x program. 10. You can assume that the input file contains no format error (other than the possible incorrect values described above). 11. You must put all the code in a single file named csc322a2.py you cannot use any other name. To demonstrate how this program should work, three (3) sets of data, along with the expected results and a tester driver, are also provided. You can download them and use them to compare with your results.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

4. What action should Cherita Howard take and why?

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago