CS001 Introduction to Programming Day 2 Sujana Jyothi
2 What will you learn today? Useful Terms in Programming Sequence & Selection
3 Resources –Use the material from my website. Save your work –on your flash drive –or it to yourself
What is programming? Technical Common Sense Logical Thinking & execution simpler than logic puzzles Need not be a cryptic activity Concepts are similar to daily activities
Useful terms used in Programming Source code The actual text used to write the instructions for a computer program. This text is then translated into something meaningful the computer can understand. Compiler A software tool that translates source code into data that the computer can understand.
Useful terms used in Programming Data type The classification of pieces of information in a program. Typically, there are data types for integers (whole numbers), floating-point numbers (numbers with a decimal part), and single characters.
Useful terms used in Programming Variable A container which represents a value in a program. Variables can store different types of data including numeric values, single characters, and text strings. The value of a variable can change all throughout a program. Constant The same thing as a variable with one major difference - the value of a constant does not change, while the value of a variable can change all throughout a program.
8 Structured Programming Constructs Use only three constructs — sequence (statements, blocks) — selection (if, switch) — iteration (loops like while and for)
Activities Recipe Assembly instructions for a toy Map out the plan at amusement park A busy day schedule What is common to all of these?
Activities Recipe Assembly instructions for a toy Map out the plan at amusement park A busy day schedule What is common to all of these? SEQUENCE
Any valid expression terminated by a semicolon is a statement. Statements may be grouped together by surrounding them with a pair of curly braces { }. Such a group is syntactically equivalent to one statement and can be inserted where ever one statement is legal. Sequence
Such a group, known as a block, has one entry point (the first statement) and one exit point (the last statement). From now, whenever we mention statement, understand that you may substitute a block instead. Sequence
Activities Drive car or take DART bus? Party or study? Fly or drive? What is common to all of these?
Activities Drive car or take DART bus? Party or study? Fly or drive? What is common to all of these? DECISION
if (expression) statement1 else statement2 if and else are independent constructs, in that if can occur without else (but not the reverse). Selection (Decision)
“Guess The Number Game": (Suppose, these are the instructions for the robot to play me at the game) 1. Think of a random number between 1 and 1000 and don't tell me it. 2. Ask me to guess what the number is. Say "What is your Guess?". 3. Listen to my answer. 4. If my answer is less than the number you thought of, say "Too Small" and then GOTO step If my answer is more than the number you thought of, say "Too Big" and then GOTO step Say "Well Done! You got the right answer!" Example to write a Program