Starting from:
$35

$29

ASSIGNMENT 3 Solution

This assignment will be submitted electronically through conneX (as described in `Submission Instructions' below). Do not submit a hard copy of your answers; paper submissions will not be marked. All code submissions must be your own work. How-ever, you are permitted to use the posted Pep/8 code as the basis for your submissions if proper attribution is given.










Question 1: Computing Polynomials [10 marks]




Download the le PQR.pep, which contains a Pep/8 program that reads three values P, Q and R from the user, then prints a value RESULT. As provided, the program is missing some code. Modify the provided le so that the value of RESULT which is printed at the end of the program is equal to 3P + 2Q + R. Submit the resulting le (still called PQR.pep) electronically to conneX.







Question 2: Finding the maximum [20 marks]




Examine the provided le EnterNumbers.pep, which reads two values NUM1 and NUM2 from the user, then prints the sum NUM1 + NUM2. Your task is to write a program, called Max2.pep, which reads two values from the user and prints the maximum of the two. Submit your program electronically to conneX.







Question 3: Multiplication [30 marks]




The Pep/8 processor does not contain a multiplication instruction. However, since there are addition instructions, it is possible to perform multiplication by repeated addition. This exercise focuses on the special case of multiplying numbers by 9 with repeated addition:




9 + 9 + : : : + 9 = 9n

| {z }




n




Examine the le Multiply9.pep, which reads a value INPUT from the user, then computes and prints the value 9 INPUT. The program is already functional (when the user enters a non-negative value), and uses a loop which repeatedly adds 9 to produce the nal result.




Your task is to write a program MultiplyYZ.pep which reads two numbers y and z from the user, then prints out the product y z. Your code is not required to handle negative input values correctly (but it should be able to handle any values for y and z between 0 and 100). You may want to use the code in EnterNumbers.pep as the basis for your submission. Running your code should produce output formatted similar to the format of the example below (where values in blue represent user input).







1



Enter a number: 5




Enter a number: 6




Numbers entered: 5 6




Product: 30




Bonus (optional) [10 marks] You will receive 10 bonus marks if your submission for question 3 correctly handles multiplication when the input values y and z are in the range 100 to 100.










Submission Instructions




All submissions for this assignment will be accepted electronically. Submit your three .pep les through the Assignments tab on conneX. You are permitted to delete and resubmit your assignment as many times as you want before the due date, but no submissions or resubmissions will be accepted after the due date has passed.




Ensure that each le contains a comment with your name and student number, and that the les for each question are named as follows:




Question 1: PQR.pep




Question 2: Max2.pep




Question 3: MultiplyYZ.pep




If you do not name your les correctly, or if you do not submit them electronically, it will not be possible to mark your submission and you will receive a mark of zero.




After submitting your assignment, conneX will automatically send you a con rmation email. If you do not receive such an email, your submission was not received. If you have problems with the submission process, send an email to the instructor before the due date.





















































































2

More products