Download presentation
Presentation is loading. Please wait.
Published byWilfred Anderson Modified over 8 years ago
2
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
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 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
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.
12
11 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?
13
12 Lab Exercises This exercise requires a demo today before the end of the lab Design a program that accepts seven integers from the user. The program then tests each number and reports how many are zeros, positive and negative. It also reports if the first and last value entered are equal to each other.
14
13 Additional Practice Questions (Demo Not Required) 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. 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.