Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lab Session-V CSIT121 Fall 2000 Revision: Top Down Design Selection: Operator Precedence Some Q’s and A’s Lab Exercises.

Similar presentations


Presentation on theme: "1 Lab Session-V CSIT121 Fall 2000 Revision: Top Down Design Selection: Operator Precedence Some Q’s and A’s Lab Exercises."— Presentation transcript:

1

2 1 Lab Session-V CSIT121 Fall 2000 Revision: Top Down Design Selection: Operator Precedence Some Q’s and A’s Lab Exercises

3 2 Revisiting Problem Solving with Top Down Design Read the problem statement and underline nouns and verbs Identify data items, their data types, scope and usage. Break the problem into sub-problems Draw a structure chart Design top level algorithm to call lower level functions to do the jobs

4 3 Revisiting Problem Solving with Top Down Design Declare lower level functions that are assigned to do the job Repeat above two steps for every sub- problem so that no sub-problem remains overly complicated

5 4 Revisiting Problem Solving with Top Down Design Do the functions need to be used in the order they are defined? Which function will be called by the OS? What is the interface between functions that may call each other? When will C++ do type-casting? What are pre-conditions and post- conditions?

6 5 Selection Control Structures 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

7 6 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

8 7 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 ({ | } ~)

9 8 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

10 9 Exercises Develop an expression that evaluates to true or false to decide about turning the headlights on. Following are the rules: If the weather is foggy or it is raining or it is snowing or it is night then the drivers should turn their headlights on

11 10 Exercises Develop a logical expression evaluating to true or false to allow kids to have roller coaster ride 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. The child may or may not be accompanied by an adult.

12 11 Lab Exercises Predict the output of following segment –int x; –x=24; –if (x=25) cout<<“What a surprise!!”<<endl; –cout<<“x is “<<x; What do you think?

13 12 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?

14 13 Lab Exercises This exercise requires a demo today before the end of the lab Lazy computer company has left a problem in their floppy driver module on models 124, 112, 134 and 165. Write a program that accepts user’s computer model number and tells if it is defective or ok.


Download ppt "1 Lab Session-V CSIT121 Fall 2000 Revision: Top Down Design Selection: Operator Precedence Some Q’s and A’s Lab Exercises."

Similar presentations


Ads by Google