Problem-Solving and Control Structures By Faith Brenner

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
Introduction to Flowcharting
Introduction to Flowcharting
Basics of Computer Programming Web Design Section 8-1.
ITEC113 Algorithms and Programming Techniques
Chapter 3 Planning Your Solution
The Program Design Phases
CSC103: Introduction to Computer and Programming
The Logical Structure of Algorithms. Algorithms Steps necessary to complete a task or solve a problem. Example: Recipe for baking a cake –Will contain.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Programming Concepts Chapter 3.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Flowcharts. Problem Solving Computer programs are written to solve problems or perform tasks Programmers translate the solutions or tasks into a language.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
ITEC113 Algorithms and Programming Techniques
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Program Design BUILDING A HOUSE. Steps to Designing a Program 1. Define the Output 2. Develop the logic to get that output 3. Write the program.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
ICS124 Session 9 Flowcharting 1. By the end of this section the student will be able to:  Name the three structures of the Structure Theorem  Identify.
Problem Solving Flowcharts. Flowcharts Introduction  Flowcharts allow us to create a visual representation of a solution to a problem DRAW  With flowcharts,
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Chapter 3 Structured Program Development in C C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
Creating Flowcharts Principles of Engineering
Creating a Flowchart Computer Integrated Manufacturing
ALGORITHMS AND FLOWCHARTS
Understand Problem Solving Tools to Design Programming Solutions
Creating Flowcharts Name of PowerPoint CIM Name of Lesson
FLOWCHARTS Part 1.
Basics of Computer Programming
Introduction to Computing
The Selection Structure
Introduction to Flowcharting
Understand Problem Solving Tools to Design Programming Solutions
Introduction To Flowcharting
Basics of Computer Programming
Basics of Computer Programming
Basics of Computer Programming
Programming Fundamentals
Creating Flowcharts Principles of Engineering
Creating Flowcharts AIM:
Microsoft Visual Basic 2005 BASICS
ALGORITHMS AND FLOWCHARTS
Lecture 2: Logical Problems with Choices
Unit# 9: Computer Program Development
Creating Flowcharts Principles of Engineering
Problem-Solving and Control Structures By Faith Brenner
Creating Flowcharts Name of PowerPoint CIM Name of Lesson
Structured Program
Understanding the Three Basic Structures
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
` Structured Programming & Flowchart
Introduction to Problem Solving and Control Statements
Faculty of Computer Science & Information System
Chapter 2- Visual Basic Schneider
ME 142 Engineering Computation I
Problem Solving Designing Algorithms.
Chapter 5: Control Structure
Flowcharts and Pseudo Code
ICT Gaming Lesson 2.
Creating Flowcharts Name of PowerPoint CIM Name of Lesson
Creating Flowcharts Principles of Engineering
Basic Concepts of Algorithm
Creating Flowcharts Principles Of Engineering
Creating Flowcharts Name of PowerPoint CIM Name of Lesson
Structural Program Development: If, If-Else
Introduction to Programming
Presentation transcript:

Problem-Solving and Control Structures By Faith Brenner Programming Logic Problem-Solving and Control Structures By Faith Brenner

Goals of Session By participating in this lesson, the students will be able to: Identify common flowcharting symbols Differentiate between the 3 main control structures given case scenarios or pseudocode Identify the flowcharting symbols used for each type of control structure

Control Structures The basic building blocks of all computer programs are control structures. In this lesson, we will discuss the 3 types of control structures – sequential, selection, and repetition in terms of real life activities. We will also look at a tool that can be used to develop the logic of a problem solution – flowcharting. With flowcharting, will discuss how control structures are represented graphically.

Problem-Solving Everything we do can be broken down into a series of small steps to accomplish a task. To successfully complete a task - steps must be completed in the right order Steps have a certain flow. They can: go in a sequence (sequence control structure) be skipped, depending on the context or situation (decision or selection control structure) be repeated (repetition control structure)

Problem-Solving – Food for Thought If we were making a cake, would it come out right if we put all of the ingredients in cake pan and then put it in the oven to bake before we actually measured and mixed all of the ingredients together? PROBABLY NOT! The steps must be in executed in the proper logical order and all steps must be completed so that we get the expected results.

Problem-Solving Practice planning out an activity: Think about how you would go about making a sandwich (step by step). Write down all of the steps you can think of in the process of making a sandwich.

Graphical Representation of a Process In the exercise you just did, you described a task using words (those dreaded “word problems”). This is called pseudocode. For some tasks, it is easier to see how the process is carried out using symbols to graphically represent the process, called a flowchart. A flowchart uses basic symbols to represent different types of steps.

SYMBOLS USED IN FLOWCHARTS ELLIPSE – terminator PARALLELOGRAM – input or output RECTANGLE - process DIAMOND - decision CIRCLE – connector ARROW – flowlines

ELLIPSE – TERMINATOR Used to indicate beginning and ending of a process (start/stop)

PARALLELOGRAM – INPUT/OUTPUT Used to depict input -any needed data into the process (information to be gathered) or output from a process (such as a report)

RECTANGLE - PROCESS Used depict any single step in the solution to a problem (process) not involving making a decision or input/output

DIAMOND - DECISION Depicts a decision being made and the alternate logic paths to be followed as a result of that decision There is one entrance into a decision symbol and at least two exists from it It contains the condition or questions that must result in a yes/no, true/false response (called a Boolean response)

ARROWS - FLOWLINES Used to connect the various symbols in a flowchart and to indicate the direction of flow of the logic (which step is next) Flow is usually left to right or top to bottom

CIRCLE - CONNECTOR Used to connect two portions of a flowchart when the flowchart cannot be placed on a single page A letter or number is placed inside the two connectors that match A

QUICK CHECK -IDENTIFY THE SYMBOLS Click on the link below to complete a matching task with the flowcharting symbols. You will be asked to match the definition or function with the flowcharting symbol. To match, drag the words with your mouse over the symbol and drop it onto the symbol. Click the “check” button to check your work. Matching Game

Quick Review The small steps in any process have a certain flow to be accomplished in a specific order. (sequence). Steps can: go in a sequence be skipped, depending on the context or situation be repeated The flow of the steps is called a control structure

PROCESS CONTROL STRUCTURES There are 3 main control structures: SEQUENCE REPETITION (LOOP OR ITERATION) DECISION (SELECTION) Special selection - CASE SELECTION

SEQUENCE CONTROL STRUCTURE Used when the flow of the process is step by step with no repetition of steps and no decision to be made Every activity starts with this structure – a series of steps put together one after another in the proper order

REPETITION CONTROL STRUCTURE Also know as a loop or iteration Used to show when steps of a process are to be repeated Always combined with a decision, which will determine whether or not the steps in the loop are to be complete and when the steps are not to be repeated anymore Keyword used to identify – while, until, repeat

REPETITION CONTROL STRUCTURE (con’t) This consists of completing the same steps over and over (repeating) until a certain condition is met. The condition might be a certain number of times the task is to be repeated or it might be something that is repeat until something occurs. Examples: Step – repeat 10 times; or Step – repeat until you reach the other side of the room. This structure is also sometimes called a loop because as you repeat the steps involve in the activity, it is like you are temporarily ‘caught in a loop’.

DECISION CONTROL STRUCTURE Also known as selection Used to depict when a decision is to be made in a process There are at least two possible responses to the decision (true/false, yes/no, on/off) – “true-false question”; if there can only be one of 2 responses, it is called a Boolean response Depending on the response to the decision, different steps are completed in the process Keywords used to identify – if-then-else

DECISION CONTROL STRUCTURE Example: If it is raining, use your umbrella, otherwise, wear your sunglasses. This is how we would say it in pseudocode. Decision: “Is it raining?”; Response “yes” – task: use your umbrella; Response “no” – task: wear your sunglasses. Depending upon the response, would complete only one of the two tasks, not both.

CASE SELECTION CONTROL STRUCTURE Used to depict when a decision is to be made in a process that involves more than just two possible responses – “multiple choice question” Depending on the response to the decision, one of several different steps is completed in the process Keywords used to identify – select, case

Test Your Understanding Scenario: If I need to walk across a room in straight line, where there is nothing in my path, which control structure would I use to map out the tasks involved to accomplish this? A – Sequence B – Selection/Decision C – Repetition/Loop D – Both A and C E – I don’t know

Test Your Understanding Scenario: I am driving and I come to a fork in the road. I need to either turn right or left. My directions say to go north at the fork. If I was driving east, which way should I turn? A – Sequence B – Selection/Decision C – Repetition/Loop D – Both A and C E – I don’t know

Test Your Understanding Given the following pseudocode, what is the control structure? Code: Move the bricks from the yard into the building until there are no more bricks in the yard. A – Sequence B – Selection/Decision C – Repetition/Loop D – Both B and C E – I don’t know

Test Your Understanding Given the following pseudocode, what is the control structure? Code: If the peaches are on sale, buy them. Otherwise, buy some apples. A – Sequence B – Selection/Decision C – Repetition/Loop D – Both B and C E – I don’t know

Test Your Understanding Given the following pseudocode, what is the control structure? Code: Do while there is some sandwich left: Take a bite of the sandwich, chew, and swallow. A – Sequence B – Selection/Decision C – Repetition/Loop D – Both A and C E – I don’t know

Test Your Understanding Given the following pseudocode, what is the control structure? Code: Put the key in the keyhole, turn the key clockwise, turn the doorknob clockwise, open the door. A – Sequence B – Selection/Decision C – Repetition/Loop D – Both B and C E – I don’t know

Test Your Understanding Given the following pseudocode, what is the control structure? Code: If your shoes are worn out, buy new ones, otherwise wear the old ones. A – Sequence B – Selection/Decision C – Repetition/Loop D – Both B and C E – I don’t know

Test Your Understanding Given the following pseudocode, what is the control structure? Code: If the glass is empty, fill it. Otherwise, drink your beverage. A – Sequence B – Selection/Decision C – Repetition/Loop D – Both B and C E – I don’t know

Test Your Understanding Given the following pseudocode, what is the control structure? Code: Shampoo your hair, rinse, and repeat 2 times. A – Sequence B – Selection/Decision C – Repetition/Loop D – Both A and C E – I don’t know

Discussion Forum A discussion forum has been created in WebCT to help you apply the concepts in this learning module. Go to the “Discussions” link in WebCT and click on the discussion topic “Problem-Solving and Control Structures” to complete this activity. Follow the discussion instructions carefully.

Self-Assessment You may check your understanding of the concepts presented in this lesson and unit by taking the “Self-Assessment”, which are study guides to help direct you attention to important concepts from this unit. This will open in a separate browser window. You must fill in the name box in order before you click “check your work” for the self-grading to work properly. Click this link to start. Self-Assessment

Summary Hopefully you now have a better grasp of the basic building blocks for developing a computer program and how these same building blocks are used by us everyday to complete all of our activities. In order for us to program a computer to do something for us, first we have to understand all of the steps that are needed to accomplish that task. Then we need to order those steps in such a way that the computer can carry out each step in the defined order so that it actually does what it is supposed to do. The control structures we have discussed help us accomplish this in a structured way that the computer can understand.

QUESTIONS?