Download presentation
Presentation is loading. Please wait.
2
1 Lab Session-6 CSIT121 Fall 2003 Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions
3
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
4
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
5
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 ({ | } ~)
6
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
7
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
8
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.
9
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?
10
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.
11
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.