EE312 - Lecture 5 Announcements•Assignment 1 due today before midnight•Assignment 2 out next week•Topics for today will address:– algorithms– conditionals in decision making statements – Program control statements (Ch. 5 & 6)Program control logic•More complex problems require the ability of a program to contain situational decision logic that provides for alternative paths of execution: 1. Instructions done in sequence (what we have seen so far) can be grouped2. Selection among alternative paths of execution3. Iteration/repetition of a set of instructions•C has several types of statements for implementing these capabilities•But first we need to understand these at the program design level Introduction to Problem Solving and AlgorithmsPrograms are made of Algorithms (implemented as functions in C) and Data Structures(implemented as variables, arrays, etc.)What is an Algorithm?•An algorithmis a procedure (i.e. a sequence of steps/instructions) for solving a given problem. It must be correct, complete, unambiguous, terminating, capable of being “executed”(by the execution agent) and understandable.•A given problem may be solvable by a number of different algorithms. Its importance is crucial in figuring out a solution procedure.•An algorithm may be transformed into a working program if its computable•An algorithm will typically use levels of abstraction to make the solution clearer and implementation easier.•An algorithm may be represented in several ways:–Pseudocode- structured English language used to help design an algorithm (free form; e.g. recipe)–Flowchart- a graphical representation of an algorithm. It shows control and data flow.–Formal languages- outside the scope of this courseHow To Shampoo Your Hair1)Wet your hair2)Apply shampoo3) Lather4) Rinse5) RepeatFollow these simple steps:Found on the back of a shampoo bottle - circa 1965How To Shampoo Your Hair1)Wet your hair2)Apply shampoo3) Lather4) Rinse5) RepeatFollow these simple steps:Steps 1 - 4 depict a sequential flow of instructionsStep 5 introduces the notion of repetition/iteration of instructions
This preview has intentionally blurred sections.
Sign up to view the full version.