INC 161 , CPE 100 Computer Programming

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
Microsoft® Small Basic
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
The If/Else Statement, Boolean Flags, and Menus Page 180
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
More While Loop Examples CS303E: Elements of Computers and Programming.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
NAME Python Programming Workbook Select a Lesson:
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
This Week Lecture on relational semantics Exercises on logic and relations Labs on using Isabelle to do proofs.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
If statement.  It is made up of three main components:  The keyword itself,  an expression that is tested for its truth value,  and a code suite to.
COMP Loop Statements Yi Hong May 21, 2015.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
26 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Programming
3.1 Fundamentals of algorithms
INC 161 , CPE 100 Computer Programming
Repetition Structures Chapter 9
Chapter 4 MATLAB Programming
Introduction to Programming
Relational Operators A relational operator compares two values. The values can be any built-in C++ data type, such as Character Integer Floating point.
The Selection Structure
3rd prep. – 2nd Term MOE Book Questions.
Selection By Ramin && Taimoor
INC 161 , CPE 100 Computer Programming
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Introduction to Programming
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
SELECTION STATEMENTS (2)
Programming Funamental slides
Control Structures: Selection Statement
Chapter (3) - Looping Questions.
INC 161 , CPE 100 Computer Programming
Introduction to Programming
INC 161 , CPE 100 Computer Programming
Self study.
Conditionals.
Chapter 5: Control Structure
SELECTIONS STATEMENTS
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
CS2011 Introduction to Programming I Selections (I)
Control Structures: Selection Statement
Introduction to Programming
Programming Fundamentals Lecture #4 Overview of Computer Programming
Chapter 3: Selection Structures: Making Decisions
Switch Case Structures
Presentation transcript:

INC 161 , CPE 100 Computer Programming Lab 3

Flowcharts When commands are not executed in order, flowcharts is useful to keep track of the program execution. Often, programmers use flowcharts to organize the order in which actions are to be performed. Common flowchart symbols are shown on the next slide.

Flowchart Example Procedure to find John.

Common Flowchart Symbols

Traverse Flowchart 1. Start 2. Check time: 3pm 3. At School 5. At Playground 6. Check time: 6pm 7. At Playground 8. Check time: 8pm 9. At Home 10. Stop Find John.

Flowchart for an if-Statement The syntax for an if-statement is as follows: if(expression) statement

Task 1 Write a program that calculate an absolute value of a number and print the result on screen. Receive 1 integer from the keyboard Calculate the absolute value Show the result on screen

Flowchart Calculate Absolute

If-else Statements The syntax for an if-else statement is as follows: if(expression) statement1 else statement2 The statement1 is executed if the expression compared is unequal to 0, else statement2 is executed.

Note: Use { } will be more clear if (i == 5) { //commands if i equal 5 } else //commands if i not equal 5 Note: Use { } will be more clear

Flowchart of an if-else Statement The syntax for an if-else statement is as follows: if(expression) statement1 else statement2

Task 2 Write a flowchart/program that tells whether the received number is odd or even. Receive 1 integer from the keyboard Calculate modulo 2 Print odd or even on the screen Hint: Use modulo 2 to differentiate odd/even

Multiple Else-if Statements - The syntax for the else-if statement is as follows: if(expression1) statement1 else if(expression2) statement2 else if(expression3) statement3 else statement4 - Semantically, the syntax of the else-if statement is an extension of the previous if-else statement.

Flowchart of an else-if Statement The syntax for an else-if statement is as follows: if(expression1) statement1 else if(expression2) statement2 else if(expression3) statement3 else statement4

Task 3 Write a program that print grade from the score entered. Receive a score from the keyboard Print grade A,B,C,D,F according to this range A 100-80 B 70-79 C 60-69 D 50-59 F 0-49