Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 121 – Quiz 3 2010 Feb 17 th. Question 2 We want to count how many days there were such that the temperature is at least 1.900 degrees lower than the.

Similar presentations


Presentation on theme: "CS 121 – Quiz 3 2010 Feb 17 th. Question 2 We want to count how many days there were such that the temperature is at least 1.900 degrees lower than the."— Presentation transcript:

1 CS 121 – Quiz 3 2010 Feb 17 th

2 Question 2 We want to count how many days there were such that the temperature is at least 1.900 degrees lower than the previous day and the average temperatures over those days Need a for loop to traverse all the elements in the list and start from the 2 nd day Need nops() function to get the total number of elements in the list Need an if statement to set a condition to check if the temperature is 1.900 degrees lower than the previous day

3 Need a variable to count the days for which the condition is true Need a variable to calculate the total temperature over all the days for which the condition is true The average temperature is the total/count – Script outline counter := 0; total := 0; for i from 2 to nops(Ltemps) do – If (Ltemps[i] - Ltemps[i-1] >= 1.900) then » counter := counter + 1; » total := total + Ltemps[i]; – end if; end do:

4 – A List is a container. Items can be accessed by subscript. – When the loop is done, just print out the count variable and the average temperature is the total temperature divided by the count. – The loop runs from 2 instead of 1, because the first execution of the loop will compare the i th and (i+1) th element. When i =1, the loop compares the 1 st to 0 th element, and 0 th element doesn’t exist. When i=2, it compares the 2 nd to the 1 st element, which makes more sense.

5 Question 3 Use the computational model and script outline used in CS 122 Lab 3 Problem 1 You are asked to input a list of 2 numbers. – [minAngle,maxAngle] – To ensure Blammo lands within 1 meter of a target positioned 110 meters away

6 #Define gravitational constants, initial x,y position, initial velocity, target distance, tolerance, and other constants. #Define a table to contain all angles that allow Blammo to land within 1 meter of the target – angleTab := table(); #Define a loop to test angles – for angle from 10 to 89 by.1 do

7

8 #convert the table to a list – angleList := convert(angleTab, list); #use min and max function to pick up the minimum and maximum angle – minAngle := min(angleList); – maxAngle := max(anlgeList); #Put the two angles into a list – [minAngle,maxAngle];


Download ppt "CS 121 – Quiz 3 2010 Feb 17 th. Question 2 We want to count how many days there were such that the temperature is at least 1.900 degrees lower than the."

Similar presentations


Ads by Google