Академический Документы
Профессиональный Документы
Культура Документы
Fundamentals
Prepared by
Frans Panduwinata, S.Kom, M.T
Algorithm
• Terminator
An oval flow chart shape indicating the start or end of the process.
• Process
A rectangular flow chart shape indicating a normal process flow step.
• Decision
A diamond flow chart shape indication a branch in the process flow.
Common Flow Chart Symbols (cont)
• Connector
A small, labeled, circular flow chart shape used to indicate a jump in
the process flow. (Shown as the circle with the letter “A”, below.)
• Data
A parallelogram that indicates data input or output (I/O) for a process.
• Document
Used to indicate a document or report.
Common Flow Chart Symbols (cont)
Example:
Characteristics of C++
• This means that you have all the features that are available
in C:
– Universally usable modular programs
– Efficient, close to the machine programming
– Portable programs for various platforms.
• A CLASS defines
a certain object type by defining both the properties and
the capacities of the objects of that type.
• Objects Communicate by
sending each other “messages,” which in turn activate
another object’s capacities.
Object-oriented Concept
Advantages of OOP
• Easy re-use:
objects maintain themselves and can therefore be used as building
blocks for other programs
EXERCISE 1
Write a C++ program that outputs the following text on
screen:
Oh what
a happy day!
Oh yes,
what a happy day!
EXERCISE 2
The following program contains several errors:
Resolve the errors and run the program to test your changes.
Data Type Overview
For EXAMPLE,
sizeof(int) represents a value of 2 or 4 depending on the machine. In
contrast, sizeof(float) will always equal 4.
Constants Types
• Boolean Constants
A boolean expression can have two values that are identified by the
keywords true and false.
Both constants are of the bool type.
For example, to set flags representing just two states.
Constants Types (cont)
• Integral Constants
Integral numerical constants can be represented as simple decimal
numbers, octals, or hexadecimals :
a decimal constant (base 10) begins with a decimal number other than
zero, such as 109 or 987650
a hexadecimal constant (base 16) begins with the character pair 0x or 0X,
for example 0x2A0 or 0X4b1C. Hexadecimal numbers can be capitalized
or noncapitalized.
Integral Constants
Integral Constants (cont)
Floating-point Constants
• EXAMPLES:
27.1 1.8E–2 // Type: double
1.8E–2 represents a value of 1.8*10–2.
A character constant
is a character
enclosed in single
quotes.
EXAMPLE:
'A' // Type: char
The numerical value is the character code representing the character.
The constant 'A‘ thus has a value of 65 in ASCII code.
String Constants
• SYNTAX:
typ name1 [name2 ... ];
• EXAMPLES:
char c;
int i, counter;
double x, y, size;
Defining Variables (cont)
NOTES:
Local variables can be defined wherever a statement is permitted. This means
that variables can be defined immediately before they are used by the
program.
Initialization
EXAMPLES:
char c = 'a';
float x(1.875);
Initialization (cont)
• In contrast, the initial value for any local variables that you
fail to initialize will have an undefined initial value.
Sample Program
Binary Number Representation
The bit pattern 1111 0110 of –10, for example, corresponds to the
unsigned char value
246 = 0*20 + 1*21 + 1*22 + 0*23 + 1*24 + 1*25 + 1*26 + 1*27
Explicit Type Conversion
Even a statement such as the following will merely result in an error message:
pi = pi + 2.0; // invalid
Volatile Objects
EXERCISE 1
Which of the variable definitions shown below is invalid or
does not make sense?
1. int a(2.5); 6. const long large;
2. int b = '?'; 7. char c('\'');
3. char z(500); 8. unsigned char ch = '\201';
4. int big = 40000; 9. unsigned size(40000);
5. double he's(1.2E+5);
10. float val = 12345.12345;
Exercises (cont)
EXERCISE 2
Write a C++ program that two defines variables for floating-
point numbers and initializes them with the values
EXERCISE 3
How often is the following loop executed?