CPS120: Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Introduction to Flowcharting
Advertisements

Understanding the Three Basic Structures
Introduction to Programming
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
CS0004: Introduction to Programming Repetition – Do Loops.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 C++ Control Statements ~ Selection and Iteration.
1 What is a loop? A loop is a repetition control structure that causes a single statement or block to be executed repeatedly Loops.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120 Introduction to Computer Science Iteration (Looping)
CPS120 Introduction to Computer Programming The Programming Process.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
CPS120: Introduction to Computer Science Lecture 14 Functions.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Control Structures RepetitionorIterationorLooping Part I.
CPS120 Introduction to Computer Science Iteration (Looping)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
Loops and Files. 5.1 The Increment and Decrement Operators.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Looping Increment/Decrement Switch. Flow of Control Iteration/Switch Statements.
CPS120: Introduction to Computer Science Session 5.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Sensor Information: while loops and Boolean Logic.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
REPETITION CONTROL STRUCTURE
PROGRAM CONTROL STRUCTURE
Chapter 5: Loops and Files.
Chapter 2.2 Control Structures (Iteration)
Iterations Programming Condition Controlled Loops (WHILE Loop)
CPS120: Introduction to Computer Science
Loops A loop is a repetition control structure.
Understanding the Three Basic Structures
Iteration: Beyond the Basic PERFORM
Repetition Control Structure
CPS120: Introduction to Computer Science
Computer Science Core Concepts
Control Structures Part 1
ICT Programming Lesson 3:
CHAPTER 6: Control Flow Tools (for and while loops)
Flow of Control.
Decisions, decisions, decisions
REPETITION Why Repetition?
Presentation transcript:

CPS120: Introduction to Computer Science File Processing: Basic Structure

Control Structures Control structure: an instruction that determines the order in which other instructions in a program are executed Structured programming each logical unit of a program should have just one entry and one exit These constructs are selection statements, looping statements, and subprogram statements Statements are executed in sequence until an instruction is encountered that changes this sequencing

Sequence Statements that are simply statements that naturally follow one another from the top of the program to the bottom

Sequence Control Structures Sequence control structures direct the order of program instructions. The fact that one instruction follows another—in sequence—establishes the control and order of operations.

Calculate Add 1 to Counter A program can instruct a computer to perform mathematical operations. Add 1 to Counter

Store A program will often instruct a computer to store intermediate results. Place 1 in Counter

Compare and Branch A program can instruct a computer to compare two items and do something based on a match or mismatch which, in turn, redirect the sequence of programming instructions. There are two forms: IF-THEN IF-THEN-ELSE

Selection Statements that include if statements and switch statements Selection statements are sometimes called conditional or decision statements. if (score >= 60) { cout << "I passed" << endl; } else { cout << "I'll do better next time!" << endl; }

IF-THEN false true Entry Exit True statement a Test condition p

IF-THEN-ELSE Entry Exit Test condition p “true” statement a false true Entry Exit Test condition p “true” statement a “false” statement a

Iteration Statements that allow the compiler to return to a point higher in the program in order to continuously repeat one or more statements All loops including while, do/while, and for loops are prime examples of iteration statements while (num < 10) { cout << "hello world" << endl; num = num + 1; }

Iterate A program loop is a form of iteration. A computer can be instructed to repeat instructions under certain conditions.

Iteration Control Structures Iteration control structures are looping mechanisms. Loops repeat an activity until stopped. The location of the stopping mechanism determines how the loop will work: Leading decisions Trailing decisions

Leading Decisions If the stop is at the beginning of the iteration, then the control is called a leading decision. The command DO WHILE performs the iteration and places the stop at the beginning.

DO WHILE Loop No Yes Entry Exit Test condition p Loop statement a

Trailing Decisions If the stop is at the end of the iteration, the control mechanism is called a trailing decision. The command DO UNTIL performs the iteration and puts the stop at the end of the loop.

DO UNTIL Loop No Yes Entry Test condition p Exit Loop statement a

Invocation Statements that allow you to place a block of statements that you wish to use several times during a program in one section You then have the ability to "call" those statements whenever you wish to execute them without having to retype the block of statements over and over again within the program In C++, we use "function calls" as invocation statements displayHelloWorld( ); will call (i.e. invoke) the function below void displayHelloWorld() { cout << "hello world" << endl; }

Structural Review: Types of Statements sequence selection (if and switch structures) iteration (for and while loops) invocation (functions)