Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Lab Session-6 CSIT121 Fall 2004 Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions."— Presentation transcript:

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

2 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 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 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 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 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 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 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 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 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”


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

Similar presentations


Ads by Google