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

Slides:



Advertisements
Similar presentations
1 Session-17 CSIT 121 Spring 2006 Loops: Conditional and Count Controlled Loops: Conditional and Count Controlled LCV: Initialize; Test and Update LCV:
Advertisements

1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
1 Lab Session-1 CSIT221 Spring 2003 b Group Programming Challenge b Individual Lab Exercise (Demo Required)
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.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
1 Lab Session-6 CSIT121 Fall 2003 Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions.
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.
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-VI CS121 Fall 2000 l HW#2 Assigned l Multiple Choice Selectors l The While Loop l Switch-Case-Break Exercise l The Counter Controlled Loops.
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.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
1 Session-13 CSIT 121 Spring 2006 Test-1 is on March 9 th ; Demo-5 due date extended to March 7 Test-1 is on March 9 th ; Demo-5 due date extended to.
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.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
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.
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.
CPS120: Introduction to Computer Science Operations Lecture 9.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
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.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.
ICS102 Lecture 8 : Boolean Expressions King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
An Introduction to Programming with C++1 The Selection Structure Tutorial 6.
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
ITEC113 Algorithms and Programming Techniques
Data Types, Identifiers, and Expressions
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Multiple variables can be created in one declaration
Chapter 4: Making Decisions.
Variables, Printing and if-statements
Inequalities and Graphs (3-1)
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
Computer Science 210 Computer Organization
Expressions.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
The Data Element.
Chapter 3: Selection Structures: Making Decisions
The Data Element.
CSS161: Fundamentals of Computing
Boolean Expressions September 1, 2019 ICS102: The course.
Presentation transcript:

1 Lab Session-6 CSIT121 Fall 2004 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 12 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. Other 4-digit model numbers are ok. Develop a program that reads the model number of user’s PC from a data file and displays the type of problem in the machine. The program should check all the model numbers stored in the file and must also inform the user if the PC is found free from defects.

10 Optional Practice Questions (Demo not required) Q14,15 page 243 Textbook Q1 page 245 Textbook (Preferably use data files and test the program with the following sentence recorded in a file: “I am landing now”