+ All Categories
Home > Documents > CS001 Introduction to Programming Day 3 Sujana Jyothi ([email protected])[email protected].

CS001 Introduction to Programming Day 3 Sujana Jyothi ([email protected])[email protected].

Date post: 18-Dec-2015
Category:
Upload: hilary-montgomery
View: 219 times
Download: 0 times
Share this document with a friend
Popular Tags:
12
CS001 Introduction to Programming Day 3 Sujana Jyothi (sujana @cs.nuim.ie )
Transcript

CS001Introduction to Programming

Day 3

CS001Introduction to Programming

Day 3

Sujana Jyothi([email protected])

2

What have we learnt so far?

• Program – sequence of steps

• Terms learnt: source code, compiler,

statement, data-type, variable, constant.

• Sequence, Decision

3

Resources

• 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

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.

ALGORITHM EXAMPLEA 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.

Learn Programming Through Scratch

Scratch -> "new programming language that lets you create your own animations, games, and interactive art."

Statement in ScratchTells the computer to do something

Instructs a sprite to say something

Instructs a sprite to go to some location

Called BLOCKS in SPRITE

Logic Structures• Sequence

• Decision / Selection if statement

• Looping / Iteration/ Repetition for statement while statement

Boolean Expression

• Boolean expression is an expression that is either true or false.

TRUE when the mouse is downFALSE when the mouse is not down

TRUE when ???????FALSE when ????????

Decision

if statement

Instruct a sprite to say hello only if, the user has depressed the mouse button

Decision

If - else statement

Instruct a sprite to say hello or goodbye, depending on whether the user has pressed the mouse button or not.

Looping / Iteration/ Repetition


Recommended