Chapter 2: Basic Elements of Computer Program: Csc128 Fundamentals of Algorithm and Computer Problem Solving
Chapter 2: Basic Elements of Computer Program: Csc128 Fundamentals of Algorithm and Computer Problem Solving
/ Division
% Modulus Division
-- Decrement
++ Increment
Highest
Operators on the same precedence
level are evaluated by the compiler
i. ++ -- from left to right.
ii. - Of course parentheses may be used to
iii.* / % alter the order of evaluation.
Parentheses are treated by C++ in the
iv. + - same way that they are by virtually all
other computer languages: They
force an operation, or set of
Lowest operation to have a higher
precedence level.
+ Addition a+b 9
* Multiplication a*b 14
/ Division a/b 3 (remainder is
discarded)
% Modulus a%b 1 (produces
Division remainder)
Evaluate the numeric expression below where a=2, b=3 and c=4. All is the integer data type.
a. (a*b)+c
b. a+b*c
c. (c-a) % b
d. (a*a+b*b+c*c)/2
identifier = expression
i. quantity = 20;
ii. price = 5.50;
iii. amount = basic_pay + overtime_hours *
overtime_rate;
iv. deductions = socso + insurance_premium +
car_loan;
v. net_pay = gross_pay - deduction;
vi. current_counter = current_counter
CSC126 FUNDAMENTALS OF ALGORITHM ++;
AND COMPUTER PROBLEM SOLVING 9
ASSIGNMENT
2. Assignment Statement
string name;
To assign a value to string data type
name=“Hambali”
NAME DESCRIPTION
pow (x,y) Return x raised to the power of y
sqrt (x) Square root of x
abs (x) Absolute value |x|