Lesson Objectives Aims To be able to write an algorithm in Pseudo Code

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

PROBLEM SOLVING TECHNIQUES
ALGORITHMS AND FLOWCHARTS
Review Algorithm Analysis Problem Solving Space Complexity
Chapter 1 Pseudocode & Flowcharts
ALGORITHMS AND FLOWCHARTS
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Looping While-continue.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
By the end of this session you should be able to...
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
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.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
22/11/ Selection If selection construct.
Flowcharting & Algorithms. Quick. Close your Eyes and Listen You are still sitting in the classroom. However, you have been called to the counselor’s.
Concepts of Algorithms CSC-244 Unit Zero Pseudo code, Flowchart and Algorithm Master Prince Computer College Qassim University K.S.A.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Algorithms and Pseudocode
GCSE Computing: Programming GCSE Programming Remembering Python.
Learning Objective To be able to… Understand flow chart symbols Complete and correct flow chart algorithms Create a program based on a flow chart.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Programming revision Revision tip: Focus on the things you find difficult first.
All materials copyright UMBC unless otherwise noted CMSC201 Computer Science I for Majors Lecture 02 – Algorithmic Thinking.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Component 1.6.
GCSE COMPUTER SCIENCE Practical Programming using Python
Learning outcomes 5 Developing Code – Using Flowcharts
ALGORITHMS AND FLOWCHARTS
3.1 Fundamentals of algorithms
GC101 Introduction to computers and programs
Output “Funds not available”
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS1001 Programming Fundamentals 3(3-0) Lecture 2
PROGRAM CONTROL STRUCTURE
Algorithms and Flowcharts
Chapter 5: Control Structure
Teaching design techniques to design efficient solutions to problems
Lesson 3 - Repetition.
Introduction To Flowcharting
( Iteration / Repetition / Looping )
Learning to Program in Python
ALGORITHMS AND FLOWCHARTS
Print slides for students reference
Control Structure Senior Lecturer
Chapter 4: Algorithm Design
ALGORITHMS AND FLOWCHARTS
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
1) C program development 2) Selection structure
Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
If selection construct
Introduction to Algorithms and Programming
If selection construct
Chapter 4: Algorithm Design
Chapter 5: Control Structure
Conditional and iterative statements
Boolean Expressions to Make Comparisons
Flowcharts and Pseudo Code
Introduction to Programming
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Basic Concepts of Algorithm
Therapies. Interpreting and writing algorithms
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
WJEC GCSE Computer Science
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Control Structures.
Introduction to Programming
Presentation transcript:

Lesson Objectives Aims To be able to write an algorithm in Pseudo Code Students may need a copy of the pseudo code guide from the exam spec (appendix 5)

Pseudocode This means ‘fake code’ or ‘almost code’ It’s part way between English sentences, and programming code. It is language neutral (it does not follow the syntax of any particular language – anyone should be able to follow it)

Programs Programs, like Lego models, are made up of basic building blocks When you combine these blocks in the right way you can make almost anything

Programs You have already been using these building blocks when you made flow charts I’ll now show you how the basic building blocks and how they relate to flow chart symbols

Flow Chart equivalent: Purpose: Pseudocode Guide Output Pseudo Code Example: print(“Hello”) Flow Chart equivalent: Purpose: To write a message on the screen, ask a question, show a value Output Final Score

num = input(“Enter a number”) Flow Chart equivalent: Purpose: Pseudocode Guide Input Pseudo Code Example: num = input(“Enter a number”) Flow Chart equivalent: Purpose: To get a piece of data from the user or another source Num = “Enter a number”

Pseudocode Guide Selection Pseudo Code Example: if num = 2 then Is Num = 2? Selection Pseudo Code Example: if num = 2 then output (“you guessed it!”) elseif num < 4 then output (“Almost right!”) endif Flow Chart equivalent: Purpose: To make a decision in a program, to have a range of outputs or things happening depending on an input YES NO Is num < 4? YES NO

Things to do after the loop… Pseudocode Guide Iteration Pseudo Code Example: for i = 1 to 10 … next i Second example: while (i != 11) ... i = i + 1 endwhile Purpose: To do something repeatedly i = 0 Is i < 11 YES Do loop actions… NO i = i + 1 Things to do after the loop…

Pseudocode Algorithm Example Write a pseudo code algorithm which: Asks for a test score/mark Outputs: “Pass” if they scored on, or over 50 “Merit if they scored on, or over 70 “Distinction” if they scored on, or over 90 or “Fail” if below 50 mark = input(“Input mark”) If mark < 50 then print(“Fail”) elseif mark < 70 then print (“Pass”) elseif mark < 90 then print (“Merit”) else print(“Distinction”) endif

Task Using the pseudo code guide and your own knowledge: See if you can write an a pseudo code program for each of the challenges They are graded by difficulty – challenge yourself If you find it too hard, try drawing a flow chart first

Task – Example Answer, Low a) The program asks the user to enter the number of hours they have been working for. The system must output: the number of minutes they have been working the number of seconds they have been working. hoursWorked = input(“Enter the number of hours worked”) numberMinutes = hoursWorked * 60 numberSeconds = numberMinutes * 60 print “number of minutes = “ & numberMinutes Print “number of seconds = “ & numberSeconds

Task – Example Answer, Low b) The program asks for a user's age, and their favourite number. The system must output: the two numbers added together the two numbers multiplied together. age = input(“Enter age”) favNum = input(“Enter favourite number”) print (age + favNum) print (age * favNum)

Activity 2 – Example Answer, Low c) The program asks the user to enter two numbers. Output the largest of these two numbers. num1 = input(“Enter the first number”) num2 = input(“Enter the second number”) if num1 > num2 then print(num1 & “ is larger”) elseif num2 > num1 then print(num2 & “ is larger”) else print(“The numbers are the same”) endif

Activity 2 – Example Answer, Medium a) The program that asks the user to enter the number of letters in the alphabet. Output whether they got it correct, or incorrect. answer = input(“How many letters are in the alphabet?”) if answer == 26 then print(“Correct”) else print(“Incorrect”) endif

Activity 2 – Example Answer, Medium b) The program asks the user to enter a number. The program then outputs the 12 times table for that number, e.g. if they enter 5 it displays 5, 10, 15 etc. number = input(“Enter a number”) for x = 1 to 12 print(x * number) next x

Activity 2 – Example Answer, Medium c) The program asks the user for 2 numbers and a symbol (+, -, /, * or ^). The program then outputs the calculation based on the symbol, e.g. if 2, 3 and + were entered it would output 2 + 3 = 5. num1 = input(“Enter a number”) num2 = input(“Enter a number”) symbol = input(“Enter a symbol”) if symbol == “+” then print(num1 + num2) elseif symbol == “-” then print(num1 – num2)

Activity 2 – Example Answer, Medium elseif symbol == “/” then print(num1 / num2) elseif symbol == “*” then print(num1 * num2) elseif symbol == “^” then print(num1 ^ num2) Else print(“Invalid symbol”) endif

Activity 2 – Example Answer, High a) The amount of water in a fish tank, in litres, is calculated using the formulae: (height x width x depth) / 1000. The program must take the height, width and depth as input and output a suitable message e.g. The tank holds 221.6 litres of water. height = input(“Enter the tank height”) width = input(“Enter the tank width”) depth = input(“Enter the tank depth”) water = (height * width * depth) / 1000 print “The tank holds “ & water & “ litres of water”

Activity 2 – Example Answer, High b) The program takes a number as input, and then outputs this many # symbols. number = input(“Enter a number”) for x = 0 to number print ”#” next x

Activity 2 – Example Answer, High c) A program asks the user to input a whole number. If the user enters an invalid input (e.g. a decimal number) then it tells them their input is invalid and asks for the input again. do number = input(“Enter a whole number”) check = number MOD 2 if check == 1 then print(“This is a whole number”) wholeNumber = true elseif check == 0 then else print(“This is NOT a whole number, try again!”) endif until wholeNumber == true

Plenary What are the symbols used in flowcharts? What are the differences between pseudo code and program code?