Programming Fundamentals Lecture 5. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.

Slides:



Advertisements
Similar presentations
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,
Advertisements

Revision.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Topic 8 :PROGRAMMING 8.4 Use of control structure Learning Outcome : Write a program segment by using appropriate control structure.
Flow Control if, while, do-while Juan Marquez (03_flow_control.ppt)
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
Flow Chart.
Introduction to Programming Lecture 5. In the Previous Lecture Basic structure of C program Basic structure of C program Variables and Data types Variables.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
If Statements & Relational Operators Programming.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Friday, December 15, 2006 “When you come to a fork in the road, take it.” - Yogi Berra.
CS 1400 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
CS 1400 Jan 2007 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
If Statements & Relational Operators, Part 2 Programming.
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Computer Science Department Relational Operators And Decisions.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
CPS120: Introduction to Computer Science Decision Making in Programs.
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Chapter 4 Selection Structures: Making Decisions.
Basic Of Computer Science
1 CSC103: Introduction to Computer and Programming Lecture No 7.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
Programming Fundamentals Lecture 4. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
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.
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
1 Chapter 4: Basic Control Flow ► Chapter Goals  To be able to implement decisions using if statements  To understand statement blocks  To learn how.
Agenda Basic Logic Purpose if statement if / else statement
1 Chapter 4, Part 1 If Control Construct A mechanism for deciding whether an action should be taken JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II The Hashemite University Computer Engineering Department.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
If Statements Programming. COMP104 Lecture 7 / Slide 2 Review: Rules for Division l C++ treats integers different than doubles. 100 is an int. l 100.0,
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Lecture 2 Control Structures: Part 1 Selection: else / if and switch.
Unary Not operator !  !true = false  !false = true.
CPS120: Introduction to Computer Science Decision Making in Programs.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Learning Objective To be able to… Understand flow chart symbols Complete and correct flow chart algorithms Create a program based on a flow chart.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Lecture #8 SWITCH STATEMENT By Shahid Naseem (Lecturer)
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
The Ohio State University
Relational Operators A relational operator compares two values. The values can be any built-in C++ data type, such as Character Integer Floating point.
Chapter 2.1 Control Structures (Selection)
CSC113: Computer Programming (Theory = 03, Lab = 01)
Numbering System TODAY AND TOMORROW 11th Edition
Programming Fundamentals
Control Structure Senior Lecturer
Lecture 2: Logical Problems with Choices
Conditional Construct
ME 142 Engineering Computation I
Visual Basic – Decision Statements
Summary Two basic concepts: variables and assignments Basic types:
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Programming Fundamental-1
Presentation transcript:

Programming Fundamentals Lecture 5

In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output and input Braces

Decision

If Statement If condition is true statements If Ali’s height is greater then 6 feet Then Ali can become a member of the Basket Ball team

If Statement in C If (condition) statement ;

If Statement in C If ( condition ) { statement1 ; statement2 ; : }

If statement in C

Relational Operators

a != b; X = 0; X == 0;

Example #include main ( ) { int AmirAge, AmaraAge; AmirAge = 0; AmaraAge = 0; cout<<“Please enter Amir’s age”; cin >> AmirAge; cout<<“Please enter Amara’s age”; cin >> AmaraAge; if AmirAge > AmaraAge) { cout << “\n”<< “Amir’s age is greater then Amara’s age” ; }

Flow Charting There are different techniques that are used to analyse and design a program. We will use the flow chart technique. A flow chart is a pictorial representation of a program. There are labelled geometrical symbols, together with the arrows connecting one symbol with other.

Flow Chart Symbols Start or stop Process Flow line Continuation mark Decision

Example If the student age is greater than 18 or his height is greater than five feet then put him on the foot balll team Else Put him on the chess team

Logical Operators AND&& OR||

Logical Operators If a is greater than b AND c is greater than d In C if(a > b && c> d) if(age > 18 || height > 5)

if-else if (condition) { statement ; - } else { statement ; - }

Example Code if (AmirAge > AmaraAge) { cout<< “Amir is older than Amara” ; } if (AmirAge < AmaraAge) { cout<< “Amir is younger than Amara” ; }

Example Code if AmirAge > AmaraAge) { cout<< “Amir is older than Amara” ; } else { cout<<“Amir is younger than or of the same age as Amara” ; }

Example If (AmirAge != AmaraAge) cout << “Amir and Amara’s Ages are not equal”;

Unary Not operator !  !true = false  !false = true

Example if ((interMarks > 45) && (testMarks >= passMarks)) { cout << “ Welcome to Lahore University”; }

Nested if If (age > 18) { If(height > 5) { : } Make a flowchart of this nested if structure…