PoP Lecture 3
PoP Lecture 3
•Consider the fee for the academic year. This data item
should be given a variable name because the fees do
change each year.
ICT172: Principles to Programming
Lecture Notes 4
Rules for naming constants & variables
1. Variables should be well-defined. That is, name a variable
according to what it represents.
2. Do not use spaces in a variable name.
3. Start a variable name with a letter. It is wrong to start variable name
with a digit or another character (except the underscore, _).
4. Do not use a dash (or any other symbol that is used as a
mathematical operator) in a variable name.
5. Be consistent when using upper- and lower-case characters. In C++
HOURS is a different variable name than Hours.
6. As a common naming convention, use upper case for the first
character in each of the words in the name, with no spaces
between words in the name.
7. Named constants be specified in all UPPER-CASE CHARACTERS.
ICT172: Principles to Programming
Lecture Notes 5
Some Invalid Variable Names
Data Item Incorrect Variable Name Problem Corrected Variable
Name
Hours worked Hours Worked Space between words HoursWorked
Name of client CN Does not define data ClientName
item
Rate of pay Pay-Rate Uses a mathematical PayRate
operator
Quantity per Quantity/customer Uses a mathematical QuantityPerCustom
customer operator er
6% salestax 6%_sales_tax Starts with a number SixPercentSalesTax
Or SalesTax
Client address Client_address_for_client_ Too long ClientAddress
of_XYZ_corporation
ICT172: Principles to Programming
Lecture Notes 6
Data Type
•The computer needs data to process a solution.
•Data are unorganized facts. They go into the computer
as input and are processed by the program.
•What is returned to the user is output or information.
•The data the computer uses are of many different
types.
•Computers must be told the data type of each variable
or constant.
•Examples: 0, 7, -42.
Mathematical Computer
Operation Result
Operator Symbol
Addition + 3.0+5.2 8.2
Subtraction - 7.5-4.0 3.5
Multiplication * 8.0*5.0 40.0
Division / 9.0/4.0 2.25
Integer Division / 9/4 2
Modulo Division % 9%4 1
Operation Resultant
1. 6*12 72
2. 72/16.0 4.5
3. 4.5+222 226.5
Operation Resultant
1.
2.
3.
4.
5.
6.
ICT172: Principles to Programming
Lecture Notes 30
Evaluating Relational Operators
•Assume the programmer has written the expression
𝐴−2>𝐵
•Evaluate the expression given that: A = 6 and B = 8
Operation Resultant
1. A- 2 4
2. 4 > 8 False
Operation Resultant
1. A AND B False
2. C AND A True
3. False OR True True
Operation Resultant
1. A<B False
2. C OR A True
3. NOT False True
4. True AND True True
End of Lecture 3