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.

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic
Advertisements

Repetition There are three different ways that a set of instructions can be repeated, and each way is determined by where the decision to repeat is.
Repeating Actions While and For Loops
Standard Algorithms. Many algorithms appear over and over again, in program after program. These are called standard algorithms You are required to know.
CS150 Introduction to Computer Science 1
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Elementary Data Structures and Algorithms
LAB-10 1-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
A revision guide for programming with python. 1.A program is a set of instructions that tells a computer what to do. 2.The role of a programmer is to.
Rate of Change and Slope
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
CS122 Engineering Computation Lab Lab 3 Bruce Char Department of Computer Science Drexel University Spring 2011.
Application of Data Programming Blocks. Objectives  Understand the use of data programming blocks and their applications  Understand the basic logic.
Homework Questions? Discuss with the people around you. Do not turn in Homework yet… You will do it at the end of class.
Coding Design Tools Rachel Gauci. What are Coding Design Tools? IPO charts (Input Process Output) Input- Make a list of what data is required (this generally.
CSC 211 Data Structures Lecture 13
Previously Repetition Structures While, Do-While, For.
CSE1222: Lecture 7The Ohio State University1. logExample.cpp // example of log(k) for k = 1,2,..,8... int main() { cout
CREATING COMPLEX QUERIES WITH NESTED QUERIES CS1100: Data, Databases, and Queries CS1100Microsoft Access1.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
CS121 Quiz 3 Fall 2012 Quiz Tips. Quiz 1 Tips Question 1 From the many calculation choices, use eval to calculate the dependent variable P(s), but use.
CS 121 – Quiz 4 Questions 5 and 6. Question 5 We are given Blammo’s initial angle of elevation, initial velocity, and the height of the center of the.
CSCI-100 Introduction to Computing
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Control Structures RepetitionorIterationorLooping Part I.
CS123 – Quiz 4 Spring, 2013 Quiz Hints. Quiz 4 Hints Question 1 – Working with list elements  Create as a table 1st and convert to a list at the end.
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Winter 2012.
CS122 Engineering Computation Lab Lab 3 Bruce Char Department of Computer Science Drexel University Winter 2010.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
CS 115 Lecture 17 2-D Lists Taken from notes by Dr. Neil Moore.
Repetitive Structures
NEW UNIT: Samples & Populations
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
What’s cheating and what is not?
C++ Programming: CS150 For.
Work and Power Quiz Solutions
Reasoning in Psychology Using Statistics
Arrays, Part 1 of 2 Topics Definition of a Data Structure
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Control Structure Senior Lecturer
While Loops.
Control Structure Senior Lecturer
One-Dimensional Array Introduction Lesson xx
Incline Lab General Info
Loops CIS 40 – Introduction to Programming in Python
Repetition Structures
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Review for Test1.
CHAPTER 6: Control Flow Tools (for and while loops)
For loops Taken from notes by Dr. Neil Moore
CS2011 Introduction to Programming I Loop Statements (I)
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Presentation transcript:

CS 121 – Quiz Feb 17 th

Question 2 We want to count how many days there were such that the temperature is at least 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 degrees lower than the previous day

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:

– 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.

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

#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

#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];