1 Lab Session-6 CSIT121 Fall 2003 Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions.

Slides:



Advertisements
Similar presentations
An Introduction to Programming with C++ Fifth Edition Chapter 5 The Selection Structure.
Advertisements

1 Session-17 CSIT 121 Spring 2006 Loops: Conditional and Count Controlled Loops: Conditional and Count Controlled LCV: Initialize; Test and Update LCV:
1 Lab Session-6 CSIT121 Fall 2004 Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 Lab Session-V CSIT121 Fall 2000 Revision: Top Down Design Selection: Operator Precedence Some Q’s and A’s Lab Exercises.
1 Session-7 CSIT 121 Spring 2006 Lab Demo of NiMo Lesson 3-2 Exercises 1,2,3,4,5,6 (Arithmetic Operators with Program ‘Convert.cpp’) Q&A about operators.
1 Selection in C. 2 If / else if statement:  The else part of an if statement can be another if statement. if (condition) … else if (condition) … else.
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
1 Lab Session-3 CSIT 121 Fall 2004 Section-3 should finish Lab-1 Exercise first Division rules Operator precedence rules Lab Exercise.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
1 Lab Session-3 CSIT 121 Spring’05 Division rules Operator precedence rules Lab Exercise.
Logical Operators and Conditional statements
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Selection in C.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
True or False Unit 3 Lesson 7 Building Blocks of Decision Making With Additions & Modifications by Mr. Dave Clausen True or False.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
Computer Science 101 Introduction to Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Chapter 3 Decision Making. What is IF? The primary method of changing the flow of a program is by making decisions using the IF verb. The following example.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
Lesson 1.4 Equations and Inequalities Goal: To learn how to solve equations and check solutions of equations and inequalities.
1 Agenda If Statement True/False Logical Operators Nested If / Switch Exercises & Misc.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Logical Operator It is useful to test multiple conditions OperatorANDORNOT Symbol&&||! ConditionBOTHEITHERREVERSE.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Lecture 6 – Selection FTMK, UTeM – Sem /2014.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
 Type Called bool  Bool has only two possible values: True and False.
1 Lab Session-V CSIT121 Spring 2002 Revision: Top Down Design Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
CprE 185: Intro to Problem Solving (using C)
Computer Science 210 Computer Organization
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
ITEC113 Algorithms and Programming Techniques
Data Types, Identifiers, and Expressions
Multiple variables can be created in one declaration
Chapter 4: Making Decisions.
Variables, Printing and if-statements
Chapter 4: Making Decisions.
Data Types, Identifiers, and Expressions
Conditional Statements
If statement.
Computers & Programming Languages
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Relational Operators Operator Meaning < Less than > Greater than
More about Numerical Computation
Expressions.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
The Data Element.
Chapter 5 Decisions.
Chapter 3: Selection Structures: Making Decisions
The Data Element.
CSS161: Fundamentals of Computing
Presentation transcript:

1 Lab Session-6 CSIT121 Fall 2003 Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions

2 Selection Control Structure We need to develop complex expressions for selection control These expressions will contain arithmetic, relational and logical operators We should be careful about the operator precedence rules and ASCII code values

3 Operator Precedence Rules Top priority is for parenthesized expression Unary operators (e.g. negation) Arithmetic operators (/, *, %) Arithmetic operators (+, -) Relational inequality Relational equality Logical and Logical or assignment

4 ASCII Codes in Increasing Numerical Values Special symbols (_, !, “, $, %, etc.) Digits 0 through 9 Special symbols (: ; Uppercase alphabets A through Z Special symbols ([ / ] ^ - ‘) Lowercase alphabets a through z Special symbols ({ | } ~)

5 Some Questions What will be the result? (Note: A=5, B=8, C=7) !(A != (B-3)) Answer: !(5 != 5) ==> !(false) true (A <B) || (C<B) Answer: (5 true ((A<B) && (B<C)) || (!(A != (B-3)) Answer: false || true ==> true

6 Exercises Develop an expression that evaluates to true or false to decide about eating in a restaurant or not If I have enough cash or I have a valid credit card and I am hungry and the restaurant serves my favorite seafood then I should eat in this restaurant

7 Exercises Develop a logical expression evaluating to true or false to allow the kids to ride a roller coaster. If the child is at least 8 years old and measures up to at least 4 ft. then it is ok to ride the roller coaster.

8 Lab Exercises Predict the output –int x; –x=24; –if (x==24); cout<<“You have no clue about what is going to happen!”<<endl; –else cout<<“No good\n”; What do you think?

9 Lab Exercise (Demo required Sec-1 Oct 7 th Sec-2 Oct 9 th ) Lazy Computer Company has caused a new headache for their customers. Their models 1432, 1456 and 1273 have bad floppy drives. On the other hand, models 2432, 1254 and 2476 have bad CD-ROM drives and model 1762 needs a BIOS upgrade. Develop a program that accepts the model number of user’s PC and displays the type of problem in the machine. This program must also inform the user if the PC is found free from defects.

10 Optional Practice Questions (Demo not required) Q6 page 254 (old book page 269) Textbook Q8 page 254 (old book page 269) Textbook Q5 page 251 (old book page 266) Textbook