$29
To complete this assignment, you should hand in 4 files:
q1.pdf
q2.pdf
q3.pdf
q4.png
Note that the first three questions should be handed in as a PDF file. Do not hand in any other files such as Microsoft Word files (e.g. doc). Question 4 needs to be handed in as a proper screenshot in .png format (i.e. not a picture taken with a smartphone).
Q1) Pseudocode and Flow Charts (2 marks)
Below is Figure 1.2 from the textbook, which describes an algorithm for adding two positive numbers together. Convert this pseudocode into a flow chart.
FIGURE 1.2
Given: m 1 and two positive numbers each containing m digits, am_, am_5...; and bo Wanted: cm cro_i cm_2... co, where cmcro_i co.„... ca = (aro_l ao) + (bro_i bo) Algorithm: Step 1 Set the value of carryto 0
Step 2 Set the value of i to 0
Step 3 While the value of i is less than or equal to m — 1, repeat the instructions in Steps 4 through 6
Step 4 Add the two digits ai and bi to the current value of carry to get ci
Step 5 If c, 10, then reset c, to (c, — 10) and reset the value of carry to 1; otherwise, set the new value of carry to 0
Step 6 Add 1 to i, effectively moving one column to the left Step 7 Set co, to the value of carry
Step 8 Print out the final answer, co, co,_, cro_2... co
Step 9 Stop
Algorithm for adding two m-digit numbers
The following three consecutive questions build on one another Q2) Question 2: pseudocode [2 marks]
Envision an algorithm that when given any number n, prints out the sum of 1 to n. E.g. given 6 the algorithm would print 21 (because 1 + 2 + 3 + 4 + 5 + 6 = 21)
Write pseudocode for this algorithm using iteration (looping).
Now modify the algorithm (and pseudocode) so it prints out the sum of even, and uneven numbers as well as the total sum.
For example if n was 6 it would print:
Even numbers sum: 12
Uneven numbers sum: 9
Total sum: 21
Again, to get marks, the algorithm needs to work for any n given.
Q3) Question 3: Flowchart [2 marks]
Create a flow chart from your pseudocode answer to Question 2
Q4) Question 4: Python implementation [4 marks].
Now implement your solution to Question 3 in Python using the application provided at http://www.codeskulptor.org/
Once your application is running properly, please take a screenshot (not a picture with your phone) and save it as q4.png
In order to get marks the picture needs to show your code, the output and the unique url associated with your solution.