Ch03 - Input Output
Ch03 - Input Output
EEE3173/EGC3113/EGC1113
Chapter 3
Input/Output
1
Objectives
In this chapter, you will learn about:
Assignment operations
Formatting numbers for program output
Using mathematical library functions
Program input using the cin object
Symbolic constants
Common programming errors
Assignment Operations
Assignment Statement: Assigns the value of the
expression on the right side of the = to the variable
on the left side of the =
Another assignment statement using the same
variable will overwrite the previous value with the
new value
Examples:
slope = 3.7;
slope = 6.28;
Syntax:
variable = variable + newValue;
10
11
12
13
14
16
17
21
22
23
24
25
26
sqrt(sin(abs(theta)))
27
28
29
30
31
32
Symbolic Constants
Symbolic constant: Constant value that is
declared with an identifier using the const
keyword.
A constants value may not be changed.
Example:
33
35
36
37
38
Summary
Expression: A sequence of one or more operands
separated by operators.
Expressions are evaluated based on precedence
and associativity.
Assignment operator: =
Increment operator: ++
Decrement operator: --
39
Summary (continued)
Use #include <cmath> for math functions
Arguments to a function must be passed in the
proper number, type, and order
Functions may be included within larger
expressions
cin object provides data input from a keyboard;
program is suspended until the input arrives
40
Summary (continued)
Use a prompt to alert the user to provide input.
Constants are named values that do not change.
41