Examples from “c++ how to program” book. SELECTIONS WITH IF-ELSE Example: if ( grade >= 60) cout << “Passed”; Example: if ( grade >= 60) cout << “Passed”;

Slides:



Advertisements
Similar presentations
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Advertisements

 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Sequential execution –Statements executed in order Transfer of control –Next statement executed not next.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
Structured Program Development in C
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1: Selection statements: if, if…else, switch.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
Nested Control Structures * Conditional Operator (?:) * Preincrement and Postincrement * Predecrement and Postdecrement * Counter-Controlled Repetition.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Selection. Flow Chart If selection If/else selection Compound statement Switch.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
PROGRAM FLOW CHAPTER3 PART1. Objectives By the end of this section you should be able to: Differentiate between sequence, selection, and repetition structure.
 2003 Prentice Hall, Inc. All rights reserved. 1 Control Structures Outline -Introduction -Algorithms -Pseudocode -Control Structures -if Selection Structure.
C Programming 2002 Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
Fundamental Programming Fundamental Programming for Loops.
1 Lecture 3 Control Structures else/if and while.
Overview Go over parts of quiz? Another iteration structure for loop.
Chapter 3 Structured Program Development Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
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.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
C++ Programming Lecture 5 Control Structure I (Selection) – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C 1 A.AlOsaimi King Saud University College of Applied studies and Community Service Csc 1101.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
 2006 Pearson Education, Inc. All rights reserved if…else Double-Selection Statement if – Performs action if condition true if…else – Performs.
משפטי תנאי ( לוגיקה ) קרן כליף. 2 © Keren Kalif ביחידה זו נלמד :  משפטי תנאי  משפט switch  משפט if מקוצר.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Branching statements.
Control Structures Sequential execution Transfer of control
- Standard C Statements
C++ Programming: CS150 For.
Chapter 2.1 Control Structures (Selection)
CSC113: Computer Programming (Theory = 03, Lab = 01)
Lecturer CS & IT Department UOS MBDIN
Control Statements Kingdom of Saudi Arabia
الحلقات التكرارية وجمل الدوران (loops)
Repetition Statements
For & do/while Loops.
مبانی برنامه‌سازی با C++ جلسه دوم
Introduction to Programming
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Structured Program
Chapter 3 - Structured Program Development
3 Control Statements:.
Chapter 3 - Structured Program Development
2.6 The if/else Selection Structure
Control Statements Paritosh Srivastava.
Dale Roberts, Lecturer IUPUI
HNDIT11034 More Operators.
Structural Program Development: If, If-Else
Programming Fundamental-1
Presentation transcript:

Examples from “c++ how to program” book

SELECTIONS WITH IF-ELSE Example: if ( grade >= 60) cout << “Passed”; Example: if ( grade >= 60) cout << “Passed”; else cout << “Failed”;

SELECTIONS WITH IF-ELSE Example: if ( studentGrade >= 90 ) cout = 80 ) cout = 70 ) cout = 60 ) cout << "D"; else cout << "F";

SELECTIONS WITH IF-ELSE  Example:  if ( studentGrade >= 60 ) cout << "Passed.\n"; else { cout << "Failed.\n"; cout << "You must take this course again.\n"; }

THE FOR STATEMENT Example: for ( int counter=1; counter<=10; counter++) cout << “counter = ” << counter << endl;

THE FOR STATEMENT Vary control variable from 1 to 5 in increments of 1 ▫ for ( int i = 1; i <= 5; i++ ) Vary control variable from 5 to 1 in increments of -1 ▫ for ( int i = 5; i >= 1; i-- ) Vary control variable from 7 to 77 in steps of 7 ▫ for ( int i = 7; i <= 77; i += 7 ) Vary control variable from 20 to 2 in steps of -2 ▫ for ( int i = 20; i >= 2; i -= 2 ) Vary control variable over the sequence: 2, 5, 8, 11, 14, 17, 20 ▫ for ( int i = 2; i <= 20; i += 3 ) Vary control variable over the sequence: 99, 88, 77, 66, 55, 44, 33, 22, 11, 0 ▫ for ( int i = 99; i >= 0; i -= 11 )

THE DO-WHILE STATEMENT Example int counter = 1; do { cout << counter << “ “; counter++; }while ( counter < 10 );