Question: Part 2. [10 marks] Given a file where each line is a single (32-bit) integer, read in the lines of the file one at a
Part 2. [10 marks] Given a file where each line is a single (32-bit) integer, read in the lines of the file one at a time; output n sums computed the fyllowing way: sum i is the sum modulo 240223 of every vth line starting from the 0 th until you've summed (i+1) lines, where v>0 is the value of the last line. That is, first you output the 0th line. Then you output the sum of the 0 th and vth line. Then you output the sum of the 0 th, vth, and 2vth line, etc. All of this is modulo 240223 , and you treat the list circularly using modular arithmetic. If the file is empty, output 0 . For example, if the input is 10203040504v=4,n=6 then the output is because we output 6(=n) sums, and the sum on line i is the sum of the lines obtained from the 0 th, vth,2vth,,(iv)th lines. For more examples, see the tests in the tests/ directory that have the form lab2-p2-X-in.txt for the input, and the matching lab2-p2-x-out txt for the expected output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
