









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










CS150 Introduction to Computer Science 1
Arithmetic Operators & Expressions o sections 2.15 & 3. o Computation o Precedence 9/15/ o Algebra vs C++ o Exponents CS150 Introduction to Computer Science 1
What is the output here? int intVariable; double doubleVariable 78.9; intVariable = doubleVariable; 9/15/ cout << intVariable; CS150 Introduction to Computer Science 1
Operators allow us to manipulate data o Unary: operator operand o Binary: operand operator operand Operator Meaning Type Example
Negation Unary - 5 (left hand side) (right hand side) 9/15/
Negation Unary - 5 = Assignment Binary rate = 0.
Multiplication Binary **cost
rate** / Division Binary cost / 2 % Modulus Binary cost % 2
Addition Binary **cost
Subtraction Binary **total
tax** CS150 Introduction to Computer Science 1
grade
grade is 2 o If both operands of the division operator are integers, then integer division is performed. the data type of grade is not considered, why? o We say the integer is truncated. Everything 9/15/ o We say the integer is truncated. Everything after the decimal point is dropped. No rounding.
grade
o grade is 2. o What data type should grade be declared as? CS150 Introduction to Computer Science 1
Modulus is the remainder after integerdivision
grade
o grade =? 9/15/
grade
o grade =?
rem = x
n; o What are the possible values for rem ? 9/14/ CS150 Introduction to Computer Science 1
Complex mathematical expressions arecreated by using multiple operators andgrouping symbols o expression: programming statement that has value 9/15/ value o sum = 21 + 3; o number = 3; CS150 Introduction to Computer Science 1 expression In these two examples,we assign the value ofan expression to a variable
result
x;
result
+ result;
result
result
number; 9/15/
result
number;
result
**a
c;
result
**a
d
c
- q
cout << “The value: “ << (sum / 2) << endl; CS150 Introduction to Computer Science 1
Precedence of Arithmetic Operators(Highest to Lowest) (unary negation) - 9/15/
/ %
b.
c.
d.
9/15/ d.
e.
CS150 Introduction to Computer Science 1