Chapter 01
Chapter 01
– High-level languages
• Similar to everyday English, use mathematical notations
(translated via compilers)
• Example:
grossPay = basePay + overTimePay
Primary
4. Link Loader
Memory
6. Execute ..
Primary
Memory
CPU CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
.. executes.
..
..
6 { 3. main
preprocessor directive
7 std::cout << "Welcome to C++!\n";
Message to the C++ preprocessor.3.1 Print "Welcome to
8 C++\n"directives.
Lines beginning with # are preprocessor
9 return 0; // indicate that program ended successfully
#include <iostream> tells3.2 theexit
preprocessor
(return to0)
10 } include
C++ the contents
programs containofone
the or
filemore
<iostream>,
functions, onewhich
of
includes input/output
which must be main operations (such as printing to
the screen). Program Output
Welcome to C++! Parenthesis are used to indicate a function
int means
Prints the string of characters that main
contained "returns"
between the an integer value.
quotation marks. More in Chapter 3.
return is a way to exit a function
from a function. A left brace { begins
The entire line, including std::cout, the the
<< body of every function
return 0, in this case, means the
operator, and a right to
thatstring "Welcome braceC++!\n"
} ends it.and
the program terminatedthe
normally.
semicolon (;), is called a statement.
Program Output
Welcome to C++!
integer1 45
35 cout << num1 << " is greater than or equal to " Outline
36 << num2 << endl;
37
2.3 exit (return 0)
38 return 0; // indicate that program ended successfully
39 }
• Object orientation
– Natural way to think about the world and to write computer
programs
– Attributes - properties of objects
• Size, shape, color, weight, etc.
– Behaviors - actions
• A ball rolls, bounces, inflates and deflates
• Objects can perform actions as well
– Inheritance
• New classes of objects absorb characteristics from existing classes
– Information hiding
• Objects usually do not know how other objects are implemented