Chapter One
Chapter One
Introduction to
Programming
Chapter 1:
Introduction to computers and C+
+ Programming
Tasneem Dawahdeh
Yarmouk University
Computer Engineering Department
What is a Computer?
• Computer
– Device capable of performing computations and making
logical decisions
• Computer programs
– Sets of instructions that control computer’s processing of
data
• Hardware
– Various devices comprising computer
• Keyboard, screen, mouse, disks, memory, CD-ROM,
processing units, …
• Software
– Programs that run on computer
Preprocessor program
1. Edit
Preprocessor Disk
processes the code.
Compiler creates
2. Preprocess
Compiler Disk object code and stores
it on disk.
Linker links the object
3. Compile
Linker Disk code with the libraries,
creates a.out and
Primary stores it on disk
4. Link
Memory
Loader
..
6. Execute Primary
Memory
CPU
CPU takes each
instruction and
executes it, possibly
storing new data
..
.. values as the program
..
executes.
2003 Prentice Hall, Inc. All rights reserved.
7
A Simple Program: Printing a Line of
Text
• Comments
– Document programs
– Improve program readability
– Ignored by compiler
– Single-line comment
• Begin with //
• Preprocessor directives
– Processed by preprocessor before compiling
– Begin with #
Welcome to C++!
using statements
Eliminate use of std:: prefix
Write cout instead of std::cout
Welcome
to
C++!
Memory Concepts
• Variable names
– Correspond to actual locations in computer's memory
– Every variable has name, type, size and value
– When new value placed into variable, overwrites previous
value
– Reading variables from memory nondestructive
Memory Concepts
Arithmetic
• Arithmetic calculations
– *
• Multiplication
– /
• Division
• Integer division truncates remainder
– 7 / 5 evaluates to 1
– %
• Modulus operator returns remainder
– 7 % 5 evaluates to 2
Arithmetic