Lecture 3
Lecture 3
Lecture #3
Reading assignment
– Chapter 2 of the textbook
– Section 3.1 from Chapter 3 of the textbook
2
Introduction to C++ ASTU
3
Introduction to C++ ASTU
4
Introduction to C++ ASTU
5
Introduction to C++ ASTU
6
Introduction to C++ ASTU
7
Introduction to C++ ASTU
• Function names
– Require a set of parentheses at the end
– Can use mixed upper and lower case
– Should be meaningful, or be a mnemonic
• Examples of function names:
easy() c3po() r2d2()
theForce()
• Note that C++ is a case-sensitive
language!
8
The main() Function ASTU
• Overall structure of a
C++ program contains
one function named
main(), called the
driver function
• All other functions are
invoked from main()
9
The main() Function ASTU
10
The main() Function ASTU
11
The main() Function ASTU
12
The cout Object ASTU
13
The cout Object ASTU
14
The cout Object ASTU
16
The cout Object ASTU
17
Comments ASTU
18
Comments ASTU
19
Data Types ASTU
20
Data Types ASTU
21
Integer Data type ASTU
22
Integer Data type ASTU
23
Integer Data type ASTU
24
Integer Data type ASTU
25
Bool Data Type ASTU
26
Signed and Unsigned Data Types ASTU
27
Floating-Point Types ASTU
28
Floating-Point literal ASTU
29
Arithmetic Operations ASTU
30
Arithmetic Operations ASTU
Operation Operator
Addition +
Subtraction -
Multiplication *
Division /
Modulus division %
31
Arithmetic Operations ASTU
32
Expression Types ASTU
34
Operator Precedence ASTU
35
Variables and Declaration Statements ASTU
36
Variables and Declaration Statements ASTU
37
Variables and Declaration Statements ASTU
38
Variables and Declaration Statements ASTU
39
Variables and Declaration Statements ASTU
40
Variables and Declaration Statements ASTU
41
Assignment Operations ASTU
43
Assignment Operations ASTU
44
Assignment Operations ASTU
45
Assignment Operations ASTU
46
Assignment Operations ASTU
47
Assignment Operations ASTU
48
Assignment Operations ASTU
n = n + 1; //increment n first
k = n; //assign n’s value to k
• Example: k = n++; //postfix increment
is equivalent to
49
Assignment Operations ASTU
50
Case Study: Radar Speed Trap ASTU
51
Case Study: Radar Speed Trap ASTU
52
ASTU
53
ASTU
54
Case Study: Radar Speed Trap ASTU
55
Case Study: Radar Speed Trap ASTU
56
Case Study: Radar Speed Trap ASTU
57
Case Study: Radar Speed Trap ASTU
58