Download presentation
Presentation is loading. Please wait.
Published byHilary Montgomery Modified over 9 years ago
1
CS001 Introduction to Programming Day 3 Sujana Jyothi (sujana@cs.nuim.ie)sujana@cs.nuim.ie
2
2 What have we learnt so far? Program – sequence of steps Terms learnt: source code, compiler, statement, data-type, variable, constant. Sequence, Decision
3
3 Resources –Use the material from my website. http://www.cs.may.ie/~Sujana/CS001.html Save your work –on your flash drive –or email it to yourself
4
ALGORITHM An algorithm is a systematic list of instructions for accomplishing some task, and the task can be anything that has a recognizable end-point (or result). Often some of the specific steps in the procedure are to be repeated until the task is done. Imagine you have a random, unsorted list of numbers. Our goal is to find the highest number in this list. 1. Pretend the first number in the list is the largest number. 2. Look at the next number, and compare it with this largest number 3. Only if this next number is larger, then keep that as the new largest number 4. Repeat steps 2 and 3 until you have gone through the whole list.
5
ALGORITHM EXAMPLE A farmer has to take three items, a dog, a goat and a cabbage, across a river. He has a boat but it can take two objects at once, in other words, the farmer and one other item only. If the dog and the goat are left together, the dog will bite the goat. If the goat and the cabbage are left together the goat will eat the cabbage. WRITE AN ALGORITHM TO TELL THE FARMER HOW TO GET THE THREE ITEMS ACROSS THE RIVER.
6
Learn Programming Through Scratch Scratch -> "new programming language that lets you create your own animations, games, and interactive art."
7
Statement in Scratch Tells the computer to do something Instructs a sprite to say something Instructs a sprite to go to some location Called BLOCKS in SPRITE
8
Logic Structures Sequence Decision / Selection if statement Looping / Iteration/ Repetition for statement while statement
9
Boolean Expression Boolean expression is an expression that is either true or false. TRUE when the mouse is down FALSE when the mouse is not down TRUE when ??????? FALSE when ????????
10
Decision if statement Instruct a sprite to say hello only if, the user has depressed the mouse button
11
Decision If - else statement Instruct a sprite to say hello or goodbye, depending on whether the user has pressed the mouse button or not.
12
Looping / Iteration/ Repetition
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.