Lecture 3 Problem Solving concepts Overview Learning Objectives
Lecture 3 Problem Solving concepts
Overview • • • Learning Objectives Learning Outcomes Data types Operators Summary
Learning Objectives • To differentiate between variables and constants. • To differentiate between character, numeric, and logical data types. • To identify use of different operators
Learning Outcomes • The Students are able to: • Use the variables and constants. • Differentiate between character, numeric, and logical data. • Use different operators to represent mathematical expressions
Revision • Constants: the value cannot be changed Example: 2222, 12. 12, ‘A’, “AAA” • Variables: Also called as identifiers i. e the value can be changed. • Example age, avg, name etc
Naming Convention of Variable 1. Name a variable according to what it represents. 2. Do not use spaces. 3. Start a variable name with a letter. 4. Do not use a dash or any other symbol Consistent usage of variable name. 5. Consistent use of upper, lowercase letter in variable names 6. Use naming convention specified by your company
Naming Convention of Variable
Individual Activity I. What is wrong with these variable names? Can you correct them? a. City Name referencing the name of a city. b. Client-name referencing a client name. c. City/State referencing a city and state. d. LN referencing a last name.
Processing Data—How a Computer Balances a Checkbook
Data Types
Examples of Data Types
Examples of Data Types
Rules of Data Type • three data types: numeric, character (including character string), or logical. • The programmer designates the data type during the programming process. • Data types cannot be mixed. • The numeric data uses the set of all base 10 numbers • Any numeric item that must be used in calculations resulting in a numeric result must be designated as numeric data type.
Operators • Operators are the data connectors within expressions and equations • Three types of operators: 1. Mathematical/Arithmetic Operators 2. Relational Operators 3. Logical Operators
Arithmetic Operators
Relational Operators
Logical Operators
Logical Operators
Logical Operators
Example • Find all possible value of the given expression: • A OR B AND (A AND NOTB) • A OR B AND C • Find the final value if A=True, B=False, C=True and D=True • A OR (NOT D) AND ( B AND C AND (A OR B)) • A OR (A AND B AND C AND D)
Summary • Use the variables and constants. • Use of character, numeric, and logical data types. • Use operators
Home Assignment • Solve any three mathematical equations using arithmetic operators
Important Questions Find all possible value of the given expression: • A OR B AND (A AND NOTB) • A OR B AND C Find the final value if A=True, B=False, C=True and D=True • A OR (NOT D) AND ( B AND C AND (A OR B)) • A OR (A AND B AND C AND D) Define operator. Explain operator hierarchy. Explain the rules for variable name.
Important Questions I. What is wrong with these variable names? Can you correct them? a. City Name referencing the name of a city. b. Client-name referencing a client name. c. City/State referencing a city and state. d. LN referencing a last name.
References 1. “Problem Solving and Programming Concepts “, Maureen Sprankle , Pearson Publication, Seventh Edition, ISBN 81 -3170711 -3.
Great Thought
- Slides: 26