ICT
ICT
Int Types:
Naming Styles
Normal : varName -= varName - value;
Shortcut: varName -= value;
● Flat Case - all lower case but connected
directly ● Multiplication (*)
● Camel Case - uncapitalized first letter,
capitalized proceeding words and
connected directly
● Pascal Case - capitalized and
connected directly
● Snake Case - all words in lowercase
and connected by an underscore ( _ ).
● Macro Case - all words are in upper
case and connected by an underscore
( _ ).
Normal : varName *= varName * value;
Shortcut: varName *= value;
● Division (/)
Operator
- A symbol that tells the compiler to
perform specific mathematical or logical
manipulators
▪ (42 > 17) is true ▪ The basic syntax is: (expression operator
expression)
▪ (17 == 42) is false
▪ Expression can be a simple or complex
▪ (42 != 17) is true logical expression
▪ ((17 + 10) > (42 – 2)) is false ▪ The C++ logical operators are:
▪ (exp1 && exp2) will be true if both exp are ▪ Logically “not true” is same as “false”
true
▪ Logically “not false” is same as “true”
▪ (exp1 && exp2 && exp3) will be true if all
exp are true ▪ The C++ syntax for the not operator
is: !expression
▪ (exp1 || exp2 || exp3) will be true if any exp
is true ▪ This is a “unary” operator since there is
just one expression to the right of the not
▪ C++ has a feature called “conditional operator
evaluation” that will stop the evaluation
early in some cases ▪ Examples with integer variables a = 7
and b = 3
▪ (exp1 && exp2) will be false if exp1 is false
▪ (a > b) is true !(a > b) is false
▪ (exp1 || exp2) will be true if exp1 is true
▪ (a <= b) is false !(a <= b) is true
▪ In both cases, we do not need to evaluate
exp2 ▪ (a == b) is false !(a == b) is true
▪ ((17 < 42) && (42 < 17)) is false, because ▪ We can often “move the not operation
second half is false inside” a simple logical expression
▪ ((17 <= 42) || (42 <= 17)) is true, because ▪ To do this simplification, we need to
first half is true remove the ! operator and reverse the logic
of the relational operator
▪ When float variables x = 3.14 and y =
7.89 ▪ !(a < b) same as (a >= b)
▪ ((x < 4) && (y < 8)) is true, because both ▪ !(a <= b) same as (a > b)
halves are true
▪ !(a > b) same as (a <= b)
▪ ((x > 3) && (y > 8)) is false, because
second half is false ▪ !(a >= b) same as (a < b)
▪ ((x < 4) || (y > 8)) is true, because first half ▪ !(a == b) same as (a != b)
is true
▪ !(a != b) same as (a == b)
▪ ((x < 3) || (y < 8)) is true, because second
half is true ▪ We can extend truth tables to illustrate
the not operator
▪ ((x > 4) || (y > 8)) is false, because both
halves are false ▪ Add new columns showing !A and !B and
their use in complex logical expressions
THE NOT OPERATOR
▪ Examples with float variables x = 4.3 and
y = 9.2
IF-ELSE STATEMENT
● Sometimes we need to handle two
alternatives in our code
● The C++ syntax of the if-else statement
is:
● If the logical expression is true, we take
if ( logical expression )
one path through the diagram
{ (executing one block of code)
● This code is nice and short but it is hard ● We have also seen how flow chart
to read diagrams can be used to visualize
============================== different execution paths in a program
// Calculate grade
if (Score >= 90)
Grade = 'A';
else if (Score >= 80)
Grade = 'B';
else if (Score >= 70)
Grade = 'C';
else if (Score >= 60)
Grade = 'D';
else