CMT1000: Introduction to Programming Ed Currie Lecture 2A: Pizza.

Slides:



Advertisements
Similar presentations
A8 – Control Structures if, if-else, switch Control of flow in Java Any sort of complex program must have some ability to control flow.
Advertisements

Introduction to Programming
CS107 Introduction to Computer Science Lecture 2.
CS107: Introduction to Computer Science Lecture 2 Jan 29th.
The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
Section 10Data Dictionary - Process Descriptors 1 10 THE DATA DICTIONARY : Process Descriptors And Franchise Colleges By MANSHA NAWAZ.
Basics of Computer Programming Web Design Section 8-1.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
CS107 Introduction to Computer Science Lecture 2.
Pseudocode and Algorithms
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Chapter 2: Design of Algorithms
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 3: 1 CMT1000: Introduction to Programming Ed Currie Lecture 3: Program structure.
CS 201 Functions Debzani Deb.
School of Computing Science CMT1000 © Ed Currie Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 1B: Problem Solving.
Chapter 1 Program Design
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
CS 101 – Oct. 5 Computer problem solving Chapter 6: read pp Problem-solving procedure Structure of a solution Examples!
CS001 Introduction to Programming Day 5 Sujana Jyothi
Introduction By: Dr. Javad Razjouyan. Programming Languages.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
Chapter 1 Program Development Asserting Java © Rick Mercer.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
1 Computers Can’t Cook! Programming Methodology Girls Engaged in Math and Science, June 2012 Bri Chapman.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
BY Lecturer: Aisha Dawood.  an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
CS 111 – Oct. 20 Most essential skill in IT: problem solving using the computer –Telling the machine exactly what we want it to do. –Also: making sure.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
ECSE Software Engineering 1I HO 4 © HY 2012 Lecture 4 Formal Methods A Library System Specification (Continued) From Specification to Design.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
Intermediate 2 Computing Unit 2 - Software Development.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
Sequences, Modules and Variables David Millard
Algorithms and Flowcharts
Algorithms 1: Sequences and Modules Yvonne Howard & Rikki Prince
Control Structures: Conditionals, If/Else and Loops David Millard
PROGRAMMING: What’s It All About?
Software Development Expansion of topics page 28 in Zelle
Basics of Computer Programming
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
Transition to Code Upsorn Praphamontripong CS 1110
Using Algorithms Copyright © 2008 by Helene G. Kershner.
Introduction To Flowcharting
Basics of Computer Programming
Basics of Computer Programming
Algorithm and Ambiguity
Chapter 1 Program Development
ALGORITHMS AND FLOWCHARTS
Using Algorithms Copyright © 2008 by Helene G. Kershner.
Problem Solving Techniques
Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
Algorithm and Ambiguity
A programming language
Tonga Institute of Higher Education IT 141: Information Systems
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Unit 1: Principles of Computer Science
Tonga Institute of Higher Education IT 141: Information Systems
Presentation transcript:

CMT1000: Introduction to Programming Ed Currie Lecture 2A: Pizza

Pizza making algorithm Often when devising an algorithm, we will first express it using instructions at a high level of abstraction, that is, in quite general terms, without great detail. How can we do this for a pizza recipe?

First stab –1. Make the base –2. Make the topping –3. Put the topping on the base –4. Cook it Four smaller problems to solve; Not sufficiently detailed yet to enable us to make the pizza

Stepwise refinement needed => an algorithm comprising instructions sufficiently detailed for our processor to follow. The detailed algorithm is said to be more concrete, or at a lower level of abstraction, than the original attempt.

Refinement 1. Make the base => Make the base according to the recipe on page Make the topping ????????? 3. Put the topping on the base ???????? 4. Cook it => Bake for 20 minutes directly on the oven shelf.

It’s like a computer program: Input data Instructions Output An algorithm being executed is generally known as a process, and the thing that is executing it is called a processor Another analogy is that of the text of a play being the algorithm, and the performance of the play being the process.

Sub-programs Make the base according to the recipe on page is asking the cook to execute another algorithm, the one on page 15 for making a pizza base. This idea is very important in writing computer programs.

Question What are the advantages of subalgorithms?

Answer The main algorithm will be more succinct The main algorithm will be easier to understand, as the code for the subalgorithm is not cluttering it up. The subalgorithm can be used over and over again.

Question What would happen if an instruction in an algorithm told the processor to execute the algorithm of which the instruction was a part?

Parameters “Make the base…” says follow the base-making instructions on page but using the quantities of ingredients (input) listed in the current recipe, causing a double quantity of the base to be made. The same instructions can be followed to make any required quantity of the base The quantities of ingredients are parameters to the sub-algorithm.

Question What are the advantages of parameterising an algorithm?

Answer The same algorithm instructions may be told to operate on different data, making the algorithm much more general, versatile and useful.

Re-use of algorithms Sometimes we can re-use an algorithm which we already have available, as with ‘make the base’. This idea of re-use is also extremely important in computer programming. Libraries Java API

Pseudocode and structured programming The English language has enormous expressive power and subtlety.....but it is often hard to be precise when using English to describe something accurately. Computer programming language instructions have precisely one meaning. We often use pseudocode to express our algorithms before final translation into programming languages.

Exercise Try to find as many meanings as you can for the sentence “The woman made the robot fast”

Sequence Consider the instruction “Make the topping” We refined this into the instruction sequence: - Heat the oil in a frying pan - Add the onion, garlic and chillies and fry for 5 minutes etc… We will now further refine this towards something resembling a computer program, using pseudocode notation.

Repetition Heat the oil in a frying pan... How can we be more precise about this? How long should we heat the oil for? Until it sizzles when we add a piece of onion to it. Express using a pseudocode construct called a while loop.

Heat the oil in a frying pan - Put oil in pan - Light gas - Place small piece of onion in pan - WHILE onion doesn’t sizzle Wait 30 seconds –Semantics?

Question –Which of the following are valid boolean expressions? – It is raining. – Is it raining? – Eat my shorts. – Doh!

Question –I am cold and I am wet. –This statement is false. –2 = 2 –2 > 8

Selection –Add the onion –Add the garlic –Add the chillies –Fry for 5 minutes

However, not everyone has a taste for spicy hot pizza! - Add the onion - Add the garlic - IF eater likes hot pizza Add the chillies - Fry for 5 minutes

Some prefer browner onions IF eater likes very brown onions Fry for 10 minutes ELSE Fry for 5 minutes

Test and evaluate Does the pizza taste as we wanted it to? Is it quick and easy to make? Are the ingredients appropriate? Could one or more have been left out? Does it cost too much to make?