Week 2 – Basic Constructs 1

Slides:



Advertisements
Similar presentations
RCX Workshop Day 2 Programming with Touch Sensor Light Sensor Repeat CJ Chung Associate Professor of Computer Science Lawrence Technological University.
Advertisements

Lecture 2: Systems Engineering
The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Nawwaf Kharma.  Programming as Problem Solving with Applied Algorithms  Algorithm Design as Instruction selection, configuration and sequencing  The.
CS 536 Spring Global Optimizations Lecture 23.
Week 4 Approaches – Psuedo Code. Last week Introduced the basic concepts Sequential Conditional branching Looping This week Methods to describe problems.
Chapter 2: Design of Algorithms
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
Programming Fundamentals (750113) Ch1. Problem Solving
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
PRE-PROGRAMMING PHASE
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
ALGORITHMS AND FLOWCHARTS
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Equations Reducible to Quadratic
Conditionals CS 103 February 16, Blast from the Past: C14 Dating Problem Statement: Calculate the age of a fossil from its C-14 radioactivity Problem.
1 Algorithms Practice Topics In-Class Project: Tip Calculator In-Class Project: Drawing a Rectangle.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
 Functions/Subroutines  Write it once, use it as many times as you want.
Flowcharts C++ Lab. Algorithm An informal definition of an algorithm is: a step-by-step method for solving a problem or doing a task. Input data A step-by-step.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
Program Design & Development EE 201 C7-1 Spring
Python Programming Module 4 Sensors and Loops Python Programming, 2/e1.
Sensor Information: while loops and Boolean Logic.
Learning outcomes 5 Developing Code – Using Flowcharts
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Python Programming Module 3 Functions Python Programming, 2/e.
Chapter 2 Section 2 Absolute Value
Desinging Programs With Flow Charts
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
CS1001 Programming Fundamentals 3(3-0) Lecture 2
While: Indefinite Loops
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
Think What will be the output?
Teaching design techniques to design efficient solutions to problems
Looping and Random Numbers
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Algorithm and Ambiguity
Frozen Graphics Lesson 3.
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
Programming: Simple Control Structures
Program Design Introduction to Computer Programming By:
Sensors and Logic Switches
Forward Until Touch Robot goes forward until it hits a wall.
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Controlling your quadcopter
Programming Fundamentals (750113) Ch1. Problem Solving
Programming: Simple Control Structures
ALGORITHMS AND FLOWCHARTS
Topic 1: Problem Solving
An Introduction to VEX IQ Programming with Modkit
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Programming: Simple Control Structures
Algorithm and Ambiguity
Flowcharts and Pseudo Code
Programming: Simple Control Structures
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Section 3.7 Switching Circuits
Objectives Construct truth tables for the following logic gates:
Writing Expressions.
Python While Loops.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Warm-Up Study the patterns below to determine the next five numbers in each sequence. You may use the calculator to check your answers. 2, 4, 6, 8, 10...
Obstacle Detection.
Programming: Simple Control Structures
Algorithms, Part 3 of 3 Topics In-Class Project: Tip Calculator
Controlling your quadcopter
Presentation transcript:

Week 2 – Basic Constructs 1 Sequential Conditional branching Looping

Last week Introduced Stepwise refinement There is often more than one solution to a problem Discussion and working in groups is a useful technique to include in problem-solving.

Sequences Instruction 1 Instruction 2 Instruction 3

Sequences The instructions follow on from each other, always the same.

Sequences Starting at the first and ‘flowing’ down.

Conditional Statements If test 1 is true then do instruction 1 If test 2 is true then do instruction 2 if false then do instruction 3

Conditional Statements The flow of the program can be altered by whether a test is true or not.

Looping Sometimes we want to repeat a list of instructions. Go back to instruction 1 Sometimes we want to repeat a list of instructions.

Looping – with a test Instruction 1 Instruction 2 Go back to instruction 1 while test is true Repeat a list of instructions, but only if a test is true.

Problem 2.1 A routine to calculate a tip based on the overall service. No tip if the service is poor 10% tip if the service is okay 15% tip if the service is good or better

Problem 2.1– Problems What does poor, okay or good mean?

Problem 2.1– Problems How do we quantify these? We could use marks out of 10. <3 for poor 3<=marks<=8 for okay >8 for good

Problem 2.1– Problems What is our tip a percentage of? We know this is going to be a percentage of the price of the bill.

Analysis Inputs needed Price of the meal Marks for service

Analysis Outputs Price + tip

Analysis Rules <3 for poor 3<=marks<=8 for okay >8 for good

Design Input the price Input the marks out of 10 If marks<3then Tip=0; If 3<=marks<=8 then Tip =Price*0.1; If marks>8 then Tip=Price*0.15 Display Tip Display Price

Problem 2.2 What would we have to do to the previous routine if we want it to repeated calculated tips?

Problem 2.2 One of the basic constructs is the loop. The next question is what to loop? In this case all the routine needs to loop.

Start of loop 1 Go back to start of loop 1 Input the price Input the marks out of 10 If marks<3 Tip=0; If 3<=marks<=8 Tip =Price*0.1; If marks>8 Tip=Price*0.15 Display Tip and price Go back to start of loop 1

convention instructions that are the result of a particular conditional statement or loop are indented below it signify they belong to that instruction.

Problem 2.3 Design a system to make the robots you met last week move towards a wall detect the wall is there and reverse backwards and turn to the right 90 degrees.

Problem 2.3 Let’s experiment: In small groups use drawings (does need to be neat) to express your ideas while you thinking about this as a group. Then write down your choosen solution as a set of instructions.

Start of one possible solution (needs expanding) Move the robot forward Check if the wall is detected If wall is detected then Go back wards Turn to the right 90 degrees Repeat this whole process

Problem 2.4: Write down a detailed list of instructions to open a bottle. Have a go yourselves Have you thought of all situations?

Problem 2.5 Wall-following robot Keeps the wall to its right and follows the contour of the room. It can touch the wall.

Problem 2.6 Try problems 2.3 or 2.5 with different sensors.