Structured Program Development

Slides:



Advertisements
Similar presentations
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
Advertisements

Chapter 3 - Structured Program Development
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Program Control Dilshad M. Shahid New York
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Structured Program Development in C
Lecture 3 Structured Program Development in C
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
 2003 Prentice Hall, Inc. All rights reserved.  2004 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
C Lecture Notes 1 Structured Program Development.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
AEEE 195 – Repetition Structures: Part B Spring semester 2011.
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Control Structures: Part 1.
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.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
1 Lecture 3 Control Structures else/if and while.
Chapter 3 Structured Program Development Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
ECE122 Feb 10, Unary Operator An operator that takes only a single operand Plus: + Minus: – Cast: (type). E.g. (double)
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.
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
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.
Chapter 7 JavaScript: Control Statements, Part 1
while Repetition Structure
- Standard C Statements
Control Statements: Part 1
JavaScript: Control Statements I
TMF1414 Introduction to Programming
Chapter 8 - JavaScript: Control Statements I
Week 4 – Repetition Structures / Loops
Programming Fundamentals
Lecturer CS & IT Department UOS MBDIN
JavaScript: Control Statements.
JavaScript: Control Statements I
The while Looping Structure
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Structured Program
Exam 1 Date: Feb. 2nd, 2015 during class time (50 minutes) Coverage
Chapter 3 - Structured Program Development
The University of Texas – Pan American
3 Control Statements:.
The while Looping Structure
Chapter 3 - Structured Program Development
2.6 The if/else Selection Structure
EPSII 59:006 Spring 2004.
Control Statements Paritosh Srivastava.
Dale Roberts, Lecturer IUPUI
The while Looping Structure
Control Statements:.
Presentation transcript:

Structured Program Development Dilshad M. Shahid New York University @1998

Today If/else, if/else, if/else While repetition structure Casting Assignment Operators (Shortcuts)

Sidetrack Conditional operator (?:) Only ternary operator (takes 3 operands) in C Example printf(“%s\n”, grade >= 60 ? “Passed” : “Failed”);

If/else, if/else, if/else Nested if/else structures test for multiple cases by placing if/else structures inside if/else structures Example

If/else, if/else, if/else Pseudocode If customer buys more than 20 oranges Print “the price is 40 cents each” else if customer buys more than 10 oranges Print “the price is 50 cents each” Print “the price is 75 cents each”

If/else, if/else, if/else In C: int num_orange; printf(“How many oranges would you like?\n”); scanf(“%d”, &num_orange); if (num_orange > 20) printf(“The price is 40 cents each\n”); else if (num_orange > 10) printf(“The price is 50 cents each\n”); printf(“The price is 75 cents each\n”);

If/else, if/else, if/else In C, indentations are not necessary. Can also write: if (num_orange > 20) printf(“The price is 40 cents each\n”); else if (num_orange > 10) printf(“The price is 50 cents each\n”); else printf(“The price is 75 cents each\n”); Look at pg 63-64 for another good if/else, if/else example.

If/else, if/else, if/else Compound statement - a set of several statements contained within a pair of curly brackets (braces) To include a compound statement in the body of an if, you would write, for example: if (num_orange > 20) printf(“The price is 40 cents each\n”); else { printf(“The price is 75 cents each\n”); printf(“Not a great deal if you ask me\n”); }

Repetition structure Allows programmer to specify that an action is to be repeated while some condition remains true The While Structure (or Loop)

While loop Tests for a given condition at the beginning of the loop before executing the other statements in the loop If condition is false, the statements in the loop are skipped Will continue execution until condition becomes false

Example In pseudocode: While sum is less than 20 Add 2 to sum While loop Example In pseudocode: While sum is less than 20 Add 2 to sum

While loop Example In C: int sum; sum = 15; /*initialization step */ while(sum < 20){ /* your condition here */ sum = sum + 2; /* changing the value */ printf(“Not there yet\n”); } printf(“You made it\n”);

While loop Counter controlled repetition Can use this to control how many times the while loop is executed example in C

While loop #include <stdio.h> main() { int counter, grade, total, average; total = 0; /* initialization phase */ counter = 1; while (counter <= 5) { /* processing phase */ printf(“Enter grade: “); scanf(“%d”, &grade); total = total + grade; counter = counter + 1; } average = total/5; printf(“Class average is %d\n”, average”);

While loop Sentinel controlled loop Can use this to determine when to stop executing the while loop example in C in Borland

Casting Dividing one integer by another integer can sometimes result in the loss of the fractional part C provides the unary cast operator to create temporary values that will hold the data Cast operators are available for any type

Assignment Operators Used to abbreviate assignment expressions Example: c = c + 3 can be written as c =+3 See pg 77

Assignment Operators Increment and Decrement Operators Example: c = c + 1 can be written as c ++ Table on pg 80 for all variations Table on pg 82 for precedence of operators

While loop Example In C: int sum; sum = 15; /*initialization step */ while(sum < 20){ /* your condition here */ sum = sum + 2; /* changing the value */ printf(“Not there yet\n”); }