Professional Documents
Culture Documents
CHAPTER 3
ASSIGNMENT, FORMATTING, & INTERACTIVE
INPUT
USCS20/Aizat
Objectives
2
Assignment Operations
Formatting Numbers for Program Output
Using Mathematical Library Functions
Program Input Using the cin Object
Symbolic Constants
USCS20/Aizat
Assignment Operations
3
Assignment statement =
Shortcuts +=, -=, *=, /=, %=
Coercion
Accumulative statement
Counting statement
Increment (++) prefix, postfix
Decrement (--) prefix, postfix
USCS20/Aizat
Assignment Operations (continued)
4
USCS20/Aizat
Assignment Operations (continued)
5
25 25 25
a b c
USCS20/Aizat
Assignment Operations:
Short cuts
7
USCS20/Aizat
Assignment Operations:
Coercion
8
USCS20/Aizat
Assignment Operations:
Accumulative Statement
9
USCS20/Aizat
Output?
10
USCS20/Aizat
Assignment Operations:
Counting Statement
11
USCS20/Aizat
Assignment Operations:
Counting Statement (cont.)
12
USCS20/Aizat
Assignment Operations:
Counting Statement (cont.)
13
USCS20/Aizat
Objectives
14
Assignment Operations
Formatting Numbers for Program Output
Using Mathematical Library Functions
Program Input Using the cin Object
Symbolic Constants
USCS20/Aizat
Formatting Numbers for
Program Output
15
USCS20/Aizat
16
USCS20/Aizat
Formatting Numbers for
Program Output (cont.)
17
USCS20/Aizat
Formatting Numbers for
Program Output (cont.)
18
USCS20/Aizat
Objectives
19
Assignment Operations
Formatting Numbers for Program Output
Using Mathematical Library Functions
Program Input Using the cin Object
Symbolic Constants
USCS20/Aizat
Using Mathematical Library Functions
20
USCS20/Aizat
Using Mathematical Library Functions (cont.)
21
USCS20/Aizat
Using Mathematical Library Functions (cont.)
22
To use a math function, give its name and pass the
input arguments within parentheses
Expressions that can be evaluated to a value can be
passed as arguments
pow ( num1, num2);
pow(5,2); 25
USCS20/Aizat
Objectives
23
Assignment Operations
Formatting Numbers for Program Output
Using Mathematical Library Functions
Program Input Using the cin Object
Symbolic Constants
USCS20/Aizat
Program Input Using the cin Object
24
USCS20/Aizat
Program Input Using the cin Object (cont.)
25
#include <iostream.h>
return 0;
}
USCS20/Aizat
Program Input Using the cin Object (cont.)
26
USCS20/Aizat
27
#include <iostream.h>
int main()
{
double length, height, area;
cout<<“Please enter length and height: “;
cin>> length>> height;
USCS20/Aizat
Objectives
28
Assignment Operations
Formatting Numbers for Program Output
Using Mathematical Library Functions
Program Input Using the cin Object
Symbolic Constants
USCS20/Aizat
Symbolic Constant
29
USCS20/Aizat
Symbolic Constant (cont.)
30
USCS20/Aizat