辅导案例-COMP90059

  • May 15, 2020

COMP90059 Introduction to ProgrammingSemester 2, 2019School of Computing and Information SystemsThe University of MelbourneAssignment 1Due date: Sunday 8th September 2019, 11.30pmThis assignment is worth 20 marks, and will count as 10% of your final mark in this subject. Theassignment specification is on the COMP90059 GROK environment, under the heading ‘Assignment 1’(https://groklearning.com/learn/unimelb-comp90059-2019-s2/ass1/0/).There are FOUR (4) questions in this assignment worth a total of 20 marks (accounting for 10% towardsyour final mark). Answer all four questions. This is an individual project. While you may discuss theproblems with your classmates, you must not show written solutions to another student or use writtensolutions from another student.You are reminded that your submission for this project is to be your own individual work. For most people,collaboration will form a natural part of the undertaking of this project. However, it is still an individualtask, and so reuse of code or excessive influence in algorithm choice and development will be consideredmisconduct. We will check submissions for originality and will invoke the University’s Academic Mis-conduct policy (http://academichonesty.unimelb.edu.au/policy.html) where inappropriate lev-els of collusion or plagiarism appear to have taken place. Your code will be passed through our plagiarismsoftware.Late submissions: A 10% penalty will be applied for each ‘late’ day and no late submissions will beaccepted after 5 days from deadline. If you submit after the deadline, your submission will be treated aslate and will be penalised.Marking Rubric for this assignment: A sample marking rubric is uploaded on the LMS for your informa-tion.Note:Three types of automated test cases will be run against your submission on GROK: (i) example test casesfrom the examples given to you in the specification – you will see a tick mark if you pass them; (ii) hiddentest cases—you won’t see the test cases but you will receive a tick if your code has passed each of them; and(iii) assessment test cases, which you will not see, but the markers will see and use to assess your project.Read the specification carefully and follow the instructions for each question.Only assessment test cases will be used to calculate your mark, as outlined in the marking rubric. Makesure to employ good programming strategies and use relevant comments and formatting of the code. Five(5) marks out of the 20 will be allocated to computational approach to solving the questions. One (1) markis allocated to formatting, commenting and the use of descriptive variable names.Good Luck!Dr Antonette Mendoza, semester 2 20191BackgroundIn this assignment we are using Python concepts taught in weeks 1–5 of the semester. This includes• expressions, statements, programs, data types, operators and strings,• built-in functions and methods, such as mathematical functions or string methods,• control flow, such as making decisions, looping over a range, or advanced looping.The assignment will be submitted via GROK and assessment will be carried out using GROK test cases.The questions have been entered into GROK and initial test cases provided to get you started. You areencouraged to generate your own test cases and test your code thoroughly to avoid surprises.For each question, you are asked to write a short Python program. The program for each question will beself-contained and will use the input() function to gather information from the user (or the test case), andthe print() statement to report its results.Each question gives sample sessions with the program you are to write, giving the input and the requiredoutput. Due to the GROK assessment process, your output is required to match the sample exactly, includingspacing. You should have practiced this procedure in the week 2–5 labs.You are not expected to check the input for errors, and nor are you expected to print error messages orthrow exceptions. On the other hand, there is no penalty for applying ordinary defensive programmingpractices.Question 1 (3 marks): Valid IP Address?Private usable IP addresses falls in the range 10.0.0.1 to 10.255.255.255 inclusive, meaning the first partmust be 10, and the following parts must between 0-255, except for the last part it should be between 1-255.Write a program that takes as input an IP address and returns ”IP address is valid” if that input was a validIP address, otherwise ”IP address is not valid”. The output must match the examples below.Note that your program should deal with the leading zeros in each part of the IP address.Here’s one example of how your program should work:Enter IP address: 010.000.000.001IP address is validHere’s another example:Enter IP address: 10.0.0.0IP address is not validThird example:Enter IP address: 10.899.0.209IP address is not validYou may assume that all input to your program will consist of positive integers separated by full stops.2Question 2 (4 marks): Ewwoks everywhereConsider a special type of animal known as an Ewwok that reproduces following the rules below:• An Ewwok dies six months after it is born. That is, if an Ewwok is born in month 0, it will die inmonth 6.• An Ewwok gives birth to two Ewwoks every two months until it dies. That is, if an Ewwok is bornin month 0, it will reproduce in months 2 and 4. It does not reproduce in month 6 or beyond.• In each month, among all the Ewwoks that have been alive for exactly three months, there is one thatdies. That is, if there are n (n> 0) Ewwoks that are born in month 0, one of them will die in month3.Given an integer initial representing the number of Ewwoks born in month 0, and an integer m representinga month, your task in this question is to write a program that calculates and returns the number of Ewwoksalive in month m.For example, if there is 1 Ewwok born in month 0 (initial = 1):• In month 1, there is 1 Ewwok.• In month 2, there are 3 Ewwoks (2 are born by the initial Ewwok).• In month 3, there are 2 Ewwoks (the initial Ewwok dies).• In month 4, there are 6 Ewwoks (4 are born).• In month 5, there are 5 Ewwoks (1 of the Ewwoks born in month 2 dies).• In month 6, there are 15 Ewwoks (10 are born).• In month 7, there are 14 Ewwoks (1 of the Ewwoks born in month 4 dies).• In month 8, there are 39 Ewwoks (the remaining Ewwok born in month 2 dies; 26 are born).• …You may assume that initial >= 0 and m >= 0.First sample session with the program:Enter initial population of Ewwoks? 2Find population in month? 8Ewwok population in month 8 is 105Second sample session with the program:Enter initial population of Ewwoks? 5Find population in month? 10Ewwok population in month 10 is 825Third sample session with the program:Enter initial population of Ewwoks? 1Find population in month? 48Ewwok population in month 8 is 20424869889Question 3 (6 marks): Dodgy Computer Credit!The motto of Dodgy Computer Store is ”Buy now, pay later!” The store loans customers money to buy aproduct, and the customer must pay off the loan over time. The Dodgy Computer Store repayment plan hasthe following rules and definitions:3Purchase priceThe initial cost of the product.Down PaymentA one-off payment at the beginning of the loan, which is 12% of the purchase price.Monthly RepaymentsRepayments must be made every month. Repayments are fixed at 6% of the purchase price. Each month’spayment includes some of the original loan, and some interest. For example, if the purchase price is $100,then each monthly repayment will be $6, including interest.Opening & Closing BalanceThe size of the loan at the start of a month is referred to as the opening balance, and the size of the loan atthe end of a month is the closing balance. For instance, if the closing balance in January is $10, then theopening balance in February is $10. (The opening/closing balance do not include interest.)InterestThere is an annual interest rate of 15%, and interest is calculated and paid monthly. The amount of interestto repay each month is calculated asinterest=opening balance∗0.1512PrincipalThe principal is the amount of the original loan repayed each month. In other words,principal= repayment− interestWrite a program that takes the purchase price (a float) as input. The program must print a table, with appro-priate headers, of the payment schedule for the lifetime of the loan, not including the down payment. Thecolumns of the table, and their widths, are as follows:Month (7 spaces wide)The month number, beginning from 1Opening Bal (13 spaces wide)The opening balance for the monthInterest (10 spaces wide)The interest paid for the monthPrincipal (11 spaces wide)The principal paid for the monthRepayment (11 spaces wide)The total repayment for the monthClosing Bal (13 spaces wide)The closing balance for the monthNotes:1. You should round the closing balance and the interest to 2 decimal places when you calculate themeach month.2. The final repayment will be smaller than the other repayments (see the final month of the exampletables below).3. The monthly repayment must be at least $0.01, otherwise the loan might never be paid off!4. Table entries are left-aligned, and every cell has one space padding on the left and right. If an entryin the table contains more digits than fit in the column, the column should expand to fit the number,along with one space padding on either side.5. The table header will always be the same width, no matter how big the numbers in the table.6. When you correctly implement the repayment plan, you will find that many (but not all) loans havea lifetime of 17 months. This is because Dodgy Computer Store offers customers a 17-month repay-ment plan. You do not need to explicitly implement this in your program.4Here’s an example of how your program should work:Enter purchase price ($): 100———————————————————————-Month | Opening Bal | Interest | Principal | Repayment | Closing Bal———————————————————————-1 | 88.00 | 1.10 | 4.90 | 6.00 | 83.102 | 83.10 | 1.04 | 4.96 | 6.00 | 78.143 | 78.14 | 0.98 | 5.02 | 6.00 | 73.124 | 73.12 | 0.91 | 5.09 | 6.00 | 68.035 | 68.03 | 0.85 | 5.15 | 6.00 | 62.886 | 62.88 | 0.79 | 5.21 | 6.00 | 57.677 | 57.67 | 0.72 | 5.28 | 6.00 | 52.398 | 52.39 | 0.65 | 5.35 | 6.00 | 47.049 | 47.04 | 0.59 | 5.41 | 6.00 | 41.6310 | 41.63 | 0.52 | 5.48 | 6.00 | 36.1511 | 36.15 | 0.45 | 5.55 | 6.00 | 30.6012 | 30.60 | 0.38 | 5.62 | 6.00 | 24.9813 | 24.98 | 0.31 | 5.69 | 6.00 | 19.2914 | 19.29 | 0.24 | 5.76 | 6.00 | 13.5315 | 13.53 | 0.17 | 5.83 | 6.00 | 7.7016 | 7.70 | 0.10 | 5.90 | 6.00 | 1.8017 | 1.80 | 0.02 | 1.80 | 1.82 | 0.00Here’s another example:Enter purchase price ($): 12345678———————————————————————-Month | Opening Bal | Interest | Principal | Repayment | Closing Bal———————————————————————-1 | 10864196.64 | 135802.46 | 604938.22 | 740740.68 | 10259258.422 | 10259258.42 | 128240.73 | 612499.95 | 740740.68 | 9646758.473 | 9646758.47 | 120584.48 | 620156.20 | 740740.68 | 9026602.274 | 9026602.27 | 112832.53 | 627908.15 | 740740.68 | 8398694.125 | 8398694.12 | 104983.68 | 635757.00 | 740740.68 | 7762937.126 | 7762937.12 | 97036.71 | 643703.97 | 740740.68 | 7119233.157 | 7119233.15 | 88990.41 | 651750.27 | 740740.68 | 6467482.888 | 6467482.88 | 80843.54 | 659897.14 | 740740.68 | 5807585.749 | 5807585.74 | 72594.82 | 668145.86 | 740740.68 | 5139439.8810 | 5139439.88 | 64243.00 | 676497.68 | 740740.68 | 4462942.2011 | 4462942.20 | 55786.78 | 684953.90 | 740740.68 | 3777988.3012 | 3777988.30 | 47224.85 | 693515.83 | 740740.68 | 3084472.4713 | 3084472.47 | 38555.91 | 702184.77 | 740740.68 | 2382287.7014 | 2382287.70 | 29778.60 | 710962.08 | 740740.68 | 1671325.6215 | 1671325.62 | 20891.57 | 719849.11 | 740740.68 | 951476.5116 | 951476.51 | 11893.46 | 728847.22 | 740740.68 | 222629.2917 | 222629.29 | 2782.87 | 222629.29 | 225412.16 | 0.005Question 4 (6 marks): Keeping SecretsWrite a program that encrypts text. The program requires the following user input:1. the text to encrypt;2. a positive integer primer. Valid primer values include: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25;3. a second positive integer numberEach letter is shifted to the position n, where n is given by:(primer ∗position of each letter+number)For example, if primer = 1, and number = 1, ’A’ will become ’B’ since(1∗0[The alphabetic position of ’A’]+1) = 1[The alphabetic position of ’B’].In general, this setting will shift all alphabets by 1 place.The program should ignore non-alphabetic characters. Encryption should return shifted alphabetic charac-ters of same case. You can assume primer and number are positive integers.First sample session with the program:Enter text: boohooEnter primer: 5Enter positive integer: 8naanaaSecond sample session with the program:Enter text: AnythingEnter primer: 2Enter positive integer: 3Primer must be 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, or 25End of assignment.6

LATEST POSTS
MOST POPULAR

ezAce多年来为广大留学生提供定制写作、留学文书定制、语法润色以及网课代修等服务,超过200位指导老师为您提供24小时不间断地服务。