
Programming exercise three February 14, 2006
1
Laboratory III
Laboratory III –
–Data type
Data type
conversions, expressions, and
conversions, expressions, and
mathematical functions
mathematical functions
Larry Caretto
Computer Science 106
Computing in Engineering and
Science
February 14, 2006
2
Outline
• Review exercise two
• Exercise three goals
• Summarize information on data types
• Review lecture material on expressions,
operator precedence and conversion
• Outline tasks for exercise three
3
Review Exercise Two
• Note that division by zero produces
infinity expressed as 1.#INF
• Zero divided by zero is indefinite 1.#IND
• Integer division truncates
• Cannot enter decimal or E notation
numbers as input for integers
• Learned how to produce spacing in
output
4
Multiple Data Inputs
• Can use space or enter key between
inputs
• Can have one or more input commands
– cin >> x >> y;
– cin >> x; cin >> y;
• For either the single or repeated cin
commands above you can use a space
or enter between data inputs
5
Exercise Three Goals
• Understand how to handle type
conversion in expressions
• Learn how to write expressions to
represent equations correctly
• Be able to define and use symbolic
constants
• Be able to use mathematical functions
from the C++ library
6
Expressions
•<variable>= <expression>;
• Expression is a constant, a variable, or
a collection of variables, constants and
operators
• Mathematical operators, in order of
precedence are [1] unary – (highest), [2]
multiplication (*), division (/), and mod
(%), [3] addition (+) and subtraction(-)