Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction to Programming
Chapter 1:
Introduction to computers and C++
Programming
Zakaria Al-Qudah, PhD.
Yarmouk University
Computer Engineering Dept.
1.1
What is a Computer?
Computer
Device capable of performing computations and making
logical decisions
Computer programs
Sets of instructions that control computers processing of
data
Hardware
Various devices comprising computer
Keyboard, screen, mouse, disks, memory, CD-ROM,
processing units,
Software
Programs that run on computer
2003 Prentice Hall, Inc. All rights reserved.
Editor
Preprocessor
Compiler
Linker
3. Compile
Disk
Program is created in
the editor and stored
on disk.
Disk
Preprocessor program
processes the code.
Disk
Compiler creates
object code and stores
it on disk.
Disk
Primary
Memory
4. Link
Loader
5. Load
Disk
6. Execute
Primary
Memory
CPU
..
..
..
Document programs
Improve program readability
Ignored by compiler
Single-line comment
Begin with //
Preprocessor directives
Processed by preprocessor before compiling
Begin with #
1
2
3
4
5
6
7
8
9
10
11
12
Outline
fig01_02.cpp
(1 of 1)
fig01_02.cpp
output (1 of 1)
Welcome to C++!
Namespace
std:: specifies using name that belongs to namespace
std
std:: removed through use of using statements
Escape characters
\
Indicates special character output
2003 Prentice Hall, Inc. All rights reserved.
10
Description
\n
\t
\r
\a
\\
\"
1
2
3
4
5
6
7
8
9
10
11
12
13
11
Outline
fig01_04.cpp
(1 of 1)
fig01_04.cpp
output (1 of 1)
Welcome to C++!
using statements
Eliminate use of std:: prefix
1
2
3
4
5
6
7
8
9
10
11
12
12
Outline
fig01_05.cpp
(1 of 1)
fig01_05.cpp
output (1 of 1)
Welcome
to
C++!
13
14
15
= (assignment operator)
Assigns value to variable
Binary operator (two operands)
Example:
sum = variable1 + variable2;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
16
Outline
fig01_06.cpp
(1 of 1)
// prompt
// read an integer
std::cout << "Sum is " << sum << std::endl; // print sum
return 0;
17
Outline
fig01_06.cpp
output (1 of 1)
18
19
integer1
45
integer1
45
integer2
72
integer1
45
integer2
72
sum
117
20
1.15
Arithmetic
Arithmetic calculations
*
Multiplication
/
Division
Integer division truncates remainder
7 / 5 evaluates to 1
%
Modulus operator returns remainder
7 % 5 evaluates to 2
21
1.15
Arithmetic
*, /, or %
+ or -
Operation(s)
Operators
applied fromOrder
leftoftoevaluation
right (precedence)
Parentheses