BIL101E: Introduction to Computers and Information systems Lecture 8

Similar documents
Introduction to Programming

Chapter 3 Structured Program Development

Structured Program Development

Structured Program Development in C

بسم اهلل الرمحن الرحيم

Chapter 2 - Control Structures

Chapter 2 - Control Structures

Introduction to C Programming

Chapter 2 - Control Structures

CS 199 Computer Programming. Spring 2018 Lecture 5 Control Statements

IS 0020 Program Design and Software Tools

Computer System and programming in C

Theory of control structures

Fundamentals of Programming. Lecture 6: Structured Development (part one)

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

An Introduction to Programming with C++ Sixth Edition. Chapter 2 Beginning the Problem-Solving Process

Computational Expression

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Class 8 ALGORITHMS AND FLOWCHARTS. The City School

LECTURE 5 Control Structures Part 2

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Method & Tools for Program Analysis & Design

JavaScript: Control Statements I

C++ PROGRAMMING SKILLS Part 2 Programming Structures

Introduction. C provides two styles of flow control:

ALGORITHMS AND FLOWCHARTS

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

PSEUDOCODE AND FLOWCHARTS. Introduction to Programming

Computers and FORTRAN Language Fortran 95/2003. Dr. Isaac Gang Tuesday March 1, 2011 Lecture 3 notes. Topics:

Fundamental of Programming (C)

Chapter 1: Problem Solving Skills Introduction to Programming GENG 200

Fundamentals of Programming

In this chapter you will learn:

ENT 189: COMPUTER PROGRAMMING. H/P: Home page:

MEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1. March 28-30, 2007

IDENTIFY WAYS OF REPRESENTING ALGORITHMS.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

5. Selection: If and Switch Controls

Chapter 1 INTRODUCTION TO COMPUTER AND PROGRAMMING

Outline. Program development cycle. Algorithms development and representation. Examples.

JavaScript: Control Statements I Pearson Education, Inc. All rights reserved.

Programming for Engineers Iteration

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving FLOWCHART. by Noor Azida Binti Sahabudin Faculty of Computer Systems & Software Engineering

Repetition Algorithms

Lecture 5 Tao Wang 1

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Chapter 4 C Program Control

Microsoft Visual Basic 2005: Reloaded

1 EEE1008 C Programming

FLOW CHART AND PSEUDO CODE

REPETITION CONTROL STRUCTURE LOGO

Chapter 2 - Control Structures

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

Control Statements. Musa M. Ameen Computer Engineering Dept.

Fundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017

LECTURE 04 MAKING DECISIONS

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042

Lecture 7 Tao Wang 1

Chapter 1 Program Design

Chapter 4 C Program Control

Chapter 2: Understanding Structure. Programming Logic and Design, 4 th Edition Introductory

Fundamentals of Programming Session 9

Problem Solving Footer Text 10/30/2015 1

OER on Loops in C Programming

Chapter 5: Control Structures

Visual Basic 2010 How to Program by Pearson Education, Inc. All Rights Reserved.

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17)

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Fourth Edition

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

1.4 Control Structures: Selection. Department of CSE

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure

Information Science 1

Introduction to Flowcharting

Information Science 1

Selection Structures II

Lecture 11: Logical Functions & Selection Structures CMPSC 200 Programming for Engineers with MATLAB

Chapter 7: Javascript: Control Statements. Background and Terminology. Background and Terminology. Background and Terminology

2/5/2018. Learn Four More Kinds of C Statements. ECE 220: Computer Systems & Programming. C s if Statement Enables Conditional Execution

2.11 Assignment Operators. Assignment expression abbreviations c = c + 3; can be abbreviated as c += 3; using the addition assignment operator

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Chapter 2. The Algorithmic Foundations of. Computer Science INVITATION TO. Computer Science. Tuesday, September 10, 13

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving

COP 1220 Introduction to Programming in C++ Course Justification

Pseudo Code and Flow Charts. Chapter 1 Lesson 2

Algorithms (continued)

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

LAB 2 INTRODUCTION TO PROGRAMMING

A Beginner s Guide to Programming Logic, Introductory

Unit 7. 'while' Loops

1. The first step that programmers follow when they solve problems is to plan the algorithm.

Chapter 4: Making Decisions

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Transcription:

BIL101E: Introduction to Computers and Information systems Lecture 8 8.1 Algorithms 8.2 Pseudocode 8.3 Control Structures 8.4 Decision Making: Equality and Relational Operators 8.5 The if Selection Structure 8.6 The if/else Selection Structure 8.7 Nested control structures Lecture 3, Page 1

3.1 Introduction Before writing a program: Have a thorough understanding of the problem Carefully plan an approach for solving it While writing a program: Know what building blocks are available Use good programming principles Lecture 3, Page 2

Computing problems 3.2 Algorithms All can be solved by executing a series of actions in a specific order Algorithm: procedure in terms of Actions to be executed The order in which these actions are to be executed Program control Specify order in which statements are to executed Lecture 3, Page 3

Pseudocode 3.3 Pseudocode Artificial, informal language that helps us develop algorithms Similar to everyday English Not actually executed on computers Helps us think out a program before writing it Easy to convert into a corresponding C program Consists only of executable statements Lecture 3, Page 4

3.4 Control Structures Sequential execution Statements executed one after the other in the order written Transfer of control When the next statement executed is not the next one in sequence Bohm and Jacopini All programs written in terms of 3 control structures Sequence structures: Programs executed sequentially by default Selection structures: C has three types: if, if/else Repetition structures: C has three types: while, do/while and for Lecture 3, Page 5

Flowchart 3.4 Control Structures Graphical representation of an algorithm Drawn using certain special-purpose symbols connected by arrows called flowlines Rectangle symbol (action symbol): Indicates any type of action Oval symbol: Indicates the beginning or end of a program or a section of code Single-entry/single-exit control structures Connect exit point of one control structure to entry point of the next (control-structure stacking) Makes programs easy to build Lecture 3, Page 6

3.5 Decision Making: Equality and Relational Operators Executable statements Perform actions (calculations, input/output of data) Perform decisions May want to print "pass" or "fail" given the value of a test grade if control structure If a condition is true, then the body of the if statement executed 0 is false, non-zero is true Control always resumes after the if structure Lecture 3, Page 7

3.5 Decision Making: Equality and Relational Operators Standard algebraic equality operator or relational operator C equality or relational operator Example of C condition Meaning of C condition Equality Operators = == x == y x is equal to y not =!= x!= y x is not equal to y Relational Operators > > x > y x is greater than y < < x < y x is less than y >= >= x >= y x is greater than or equal to y <= <= x <= y x is less than or equal to y Lecture 3, Page 8

3.6 The if Selection Structure Selection structure: Used to choose among alternative courses of action Pseudocode: If student s grade is greater than or equal to 60 Print Passed If condition true Print statement executed and program goes on to next statement If false, print statement is ignored and the program goes onto the next statement Lecture 3, Page 9

3.6 The if Selection Structure if structure is a single-entry/single-exit structure A decision can be made on any expression. grade >= 60 true print Passed zero - false nonzero - true Example: false 3-4 is true Lecture 3, Page 10

if 3.7 The if/else Selection Structure Only performs an action if the condition is true if/else Specifies an action to be performed both when the condition is true and when it is false Psuedocode: If student s grade is greater than or equal to 60 Print Passed else Print Failed Note spacing/indentation conventions Lecture 3, Page 11

3.7 The if/else Selection Structure Flow chart of the if/else selection structure false grade >= 60 true print Failed print Passed Nested if/else structures Test for multiple cases by placing if/else selection structures inside if/else selection structures Once condition is met, rest of statements skipped Lecture 3, Page 12

3.7 The if/else Selection Structure Pseudocode for a nested if/else structure If student s grade is greater than or equal to 90 Print A else If student s grade is greater than or equal to 80 Print B else If student s grade is greater than or equal to 70 Print C else If student s grade is greater than or equal to 60 Print D else Print F Lecture 3, Page 13