Pseudo-Code Conditional Branches

Slides:



Advertisements
Similar presentations
Statistics and Probability
Advertisements

MATLAB Examples. CS 1112 MATLAB Examples Find the number of positive numbers in a vector x = input( 'Enter a vector: ' ); count = 0; for ii = 1:length(x),
Computer Programming Lab 8.
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
Use logic to teach the computer how to play a game
Main task -write me a program
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Z. Z Scissors Paper Stone  Scissors beats paper (cuts it)  Paper beats rock (wraps it)  Rock beats scissors (blunts it)  Showing the same is a draw.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Cosc175/testing1 Testing Software errors are costly GIGO Preventing Errors –Echo checking –Range and limit checking –Defensive programming.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
WARM UP MULTIPLE CHOICE Which function has an output of j=27 for an input of a = 3. (Lesson 1.8) a)j = 4a + 15 b)j = 15a + 4 c)j = 15 ∙ 4a d)j = 27a 3.
1 Program Development l Problem definition l Problem analysis l Algorithm design l Program coding l Program testing l Program documentation.
Rock, Paper, Scissors A Probability Experiment.
Inequalities Symbols and line graphs. Symbols  < is less than  > is greater than  < is less than or equal to  > is greater than or equal to points.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
Learning Difficulties in Computer Programming By Dr SC Li.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
Using GA’s X 3 – y 2 + Z = Create a random population Function name – population Inputs: – N, size of the population – R, range of values for each.
Graphing Linear Inequations y > y is greater than  all points above the line are a solution y < y is less than  all points below the line are a solution.
S U C C E S S I O N. Z Z Scissors Paper Stone  Scissors beats paper (cuts it)  Paper beats rock (wraps it)  Rock beats scissors (blunts it)
I’m fine.I’m great!I’m very good. I’m not good. I’m tired.I’m hungry!
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Design of Rock-Paper-Scissors end Print instructions Play game Ask user If (s)he wants to play again Play again? Y Print stats: wins, losses and ties start.
Control Structures: Conditionals, If/Else and Loops David Millard
PYTHON PROGRAMMING Year 9. Objective and Outcome Teaching Objective Today we will look at conditional statements in order to understand how programs can.
Starter What does the following code do?
Writing algorithms Introduction to Python.
More on Functions (Part 2)
Input and Output Upsorn Praphamontripong CS 1110
Entry Ticket: Algorithms and Program Construction
--- Price List --- A - Marshmallow: £0.20 B - Bubble gum: £0.30
Modelling and Simulating Social Systems with MATLAB
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Simple Probability Things to know and do:
Introduction to Programming
Fundamental Principle of Counting
12.1 – Probability Distributions
Unit 2 Smarter Programming.
Chapter 4: Control Structures
@TeacherToolkit, license CC BY-NC-ND 3.0
Problem Solving and Programming CS140: Introduction to Computing 1 8/21/13.
The Maker.
Writing Functions( ) (Part 5)
Combining Sequential and Simultaneous Moves
Conditional Statements
Control Structure Senior Lecturer
Programming Funamental slides
1) C program development 2) Selection structure
C Graphing Functions.
Partner Battle.
Computational Thinking for KS3
Introduction to Programming
Exploring Computer Science Lesson 4-11
More on Functions (Part 2)
Chapter 5: Control Structure
LO: Draw and use a tree diagram to find conditional probabilities.
Big problem  small steps
Learning Intention I will learn about programming using selection (making choices) with one condition.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Console.WriteLine(“Good luck!”);
Flowcharts and Pseudo Code
Programming Concepts and Database
SIMPLE INEQUALITIES.
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Learning Intention I will learn about selection with multiple conditions.
Introduction to Programming
Presentation transcript:

Pseudo-Code Conditional Branches Class Activity ICS B Spring 2015 Anham Liaqat

Exercise 1 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z What is output of above program if input is a) X is 3 b) X is 4 c) X is 2 IF X is less than 4 Z = 2 END IF

Exercise 2 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z What is output of above program if input is a) X is 1 b) X is 5 c) X is 4 IF X is less than 4 Z = 2 ELSE Z = 4 END IF

Exercise 3 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z What is output of above program if input is a) X is 3 b) X is 4 c) X is 1 IF X is less than 4 Z = 1 END IF IF X is equal to 3 Z = 2 END IF

Exercise 4 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z What is output of above program if input is a) X is 3 b) X is 4 c) X is 2 IF X is less than 4 Z = 3 END IF IF X is equal to 3 Z = 2 END IF

Exercise 5 Z = 1 INPUT X INPUT Y OUTPUT Z Input Variables: X, Y Pseudocode: Z = 1 INPUT X INPUT Y OUTPUT Z What is output of above program if input is X is 3 and Y is 4 X is 3 and Y is 2 X is 2 and Y is 3 IF X is equal to 3 END IF IF Y is greater than X Z = 4 ELSE Z = 5 END IF

Exercise 6 Input Variable: X Pseudocode: INPUT X Z = 1 OUTPUT Z IF X is less than 4 Z = 1 ELSE END IF  1.What is output of this program if input is X is 3 X is 4 X is 5   2. For what input in X, the output variable Z is set to 2? IF X is equal to 3 Z = 2 ELSE END IF IF X is equal to 4 Z = 3 ELSE Z = 4 END IF

Exercise 7 Write pseudocode for a program which takes a year as input (e.g. 2014) and determines whether or not it is a leap year. A leap year is a multiple of 4, and if it is a multiple of 100, it must also be a multiple of 400.

Exercise 7 Solution There are more then one solutions. This is only one of them

Exercise 8 Write and run a program that plays the game of “Rock, paper, scissors.” In this game, two players simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice dominates the other.. The rules are: paper dominates (wraps) rock, rock dominates (breaks) scissors, and scissors dominate (cut) paper. You can use 1=rock,2=paper,3=scissors Sample Input: 1 1 Sample Output: Draw Sample Input: 1 2 Sample Output: 2nd player wins

Exercise 8 Solution There are more then one solutions. This is only one of them