Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 5 Homework: Logic and Planning Tools A step by step solution guide.

Similar presentations


Presentation on theme: "Lesson 5 Homework: Logic and Planning Tools A step by step solution guide."— Presentation transcript:

1 Lesson 5 Homework: Logic and Planning Tools A step by step solution guide

2 2 Complete this assignment by applying the Problem Solving Method. Tasks: 1.Calculate and output the average of the following marks: 80%, 55%, 75%, 93% You are given $ Calculate and output the minimum number of 100, 50, 20, 10, and 5 dollar bills you receive. 3. Calculate and output the amount of HST (13%) charged on an item, as well as the total cost of the item after taxes. (not included in this guide) Required: a) a statement of the problem; b) a completed Input-Processing-Output Chart; and c) the problem stated in Pseudo-Code; For demonstration purposes a final solution in Javascript code will be given in this solution guide. Lesson 5 IPO / Algorithm Assignment Solution Guide

3 3 Task 1: Calculate and output the average of the following marks: 80%, 55%, 75%, 93%. IPO Solution: INPUT PROCESSINGOUTPUT Enter 4 markstotal marks = mark1+mark2... Average = total marks / 4 Average Pseudocode: a)Enter 4 marks b)Add marks together c)Calculate average (divide sum of marks by number or marks) d)Output average Go to next slide for Javascript “translation”…

4 4 Lesson 5 IPO / Algorithm Assignment Solution Guide Javascript “translation” following pseudocode ( segment only): Task 1: Calculate and output the average of the following marks: 80%, 55%, 75%, 93%. // pseudocode: Enter 4 marks var mark1=80; var mark2=55; var mark3=75; var mark4=93 // pseudocode: Add marks together TotalMarks=mark1+mark2+mark3+mark4 // pseudocode: Calculate average (divide sum of marks by number or marks) average=TotalMarks/4 // pseudocode: Output Average document.write("The average of "+mark1+", "+mark2+", "+mark3+", "+mark4+" is: "+average) Go on to Task 2 solution…

5 5 Lesson 5 IPO / Algorithm Assignment Solution Guide Task 2: You are given $ Calculate and output the minimum number of 100, 50, 20, 10, and 5 dollar bills you receive. IPO Solution: INPUT PROCESSING OUTPUT Enter amount ($265) # of 100's=amount / 100 (parse or floor) remaining $ =amount-(# of 100's x 100)  # of 100's & remaining $ # of 50's=amount / 50 (parse or floor) remaining $ =amount-(# of 50's x 50)  # of 50's & remaining $ repeat for 20,10 & 5 until 0 $ left  # of 20,10 & 5s and remaining $ Go to next slide for pseudocode solution…

6 6 Lesson 5 IPO / Algorithm Assignment Solution Guide Pseudocode: a. input amount b. calculate # of 100's (amount divided by 100), parse or floor to round down c. calculate remaining amount by subtracting from total amount of 100's possible d. print number of 100's and remaining $ e. repeat steps b, c and d for 50, 20, 10 and 5 dollars Task 2: You are given $ Calculate and output the minimum number of 100, 50, 20, 10, and 5 dollar bills you receive. Go to next slide for Javascript “translation”…

7 7 Lesson 5 IPO / Algorithm Assignment Solution Guide Javascript “translation” following pseudocode ( segment only): Task 2: You are given $ Calculate and output the minimum number of 100, 50, 20, 10, and 5 dollar bills you receive. // pseudocode: Input Amount var amount=265 // pseudocode: calculate # of 100's (amount / 100), parse to remove decimal part var N_of_100=parseInt(amount/100) // pseudocode: calculate remaining amount (subtract amount from 100's possible) var amount=amount-(N_of_100*100) // pseudocode: print number of 100's and remaining $ document.write("Number of 100's ====> [ "+N_of_100+" ] ====> [ $"+amount+" ] remaining ") // and repeat for 50’s, 20’s, 10’s and 5’s… var N_of_50=parseInt(amount/50) var amount=amount-(N_of_50*50) document.write(" Number of 50's ====> [ "+N_of_50+" ] ====> [ $"+amount+" ] remaining ") var N_of_20=parseInt(amount/20) var amount=amount-(N_of_20*20) document.write(" Number of 20's ====> [ "+N_of_20+" ] ====> [ $"+amount+" ] remaining ") var N_of_10=parseInt(amount/10) var amount=amount-(N_of_10*10) document.write(" Number of 10's ====> [ "+N_of_10+" ] ====> [ $"+amount+" ] remaining ") var N_of_5=parseInt(amount/5) var amount=amount-(N_of_5*5) document.write(" Number of 5's ====> [ "+N_of_5+" ] ====> [ $"+amount+" ] remaining ") Go to next Slide to TRACE variables…

8 8 var amount=265 var N_of_100=parseInt(amount/100) var amount=amount-(N_of_100*100) document.write("Number of 100's ====> [ "+N_of_100+" ] ====> [ $"+amount+" ] remaining ") Lesson 5 IPO / Algorithm Assignment Solution Guide Task 2 segment revisited: Trace the Variables Result in Browser:

9 9 Lesson 5 IPO / Algorithm Assignment Solution Guide End of IPO Solution Guide Go Back to Task 1 Go Back to Task 2 Go to Variable Trace Example Go to


Download ppt "Lesson 5 Homework: Logic and Planning Tools A step by step solution guide."

Similar presentations


Ads by Google