Professional Documents
Culture Documents
8
All programs consists of:
1. Sequence of instructions
2. Conditionals
3. Loops
9
Critical Skills
– Analysis
– Critical Thinking
– Attention to Detail
10
Logical Error
“Mr. ABC sleeps thirty hours every day"
11
Design Recipe
To design a program properly, we must:
– Analyze a problem statement, typically
expressed as a word problem
– Express its essence, abstractly and with
examples
– Formulate statements and comments in a
precise language
– Evaluate and revise the activities in light of
checks and tests
12
• Think Reuse
• Think User Interface
• Comments liberally
13
Think Reuse
14
Area of the Ring
Inner Circle
Outer Circle
Area of Outer Circle ____ Area of Inner Circle = Area of the Ring
15
Software Categories
• System software
• Application Software
16
Hardware
Device Driver
Operating System
System software
Application software
System Software
• Control the overall operation of computer
• Interact directly with hardware
• Perform system management and maintenance
• Used to develop or maintain other programs
18
Application Software
• Interact directly with the user
• Perform a certain type of task
• Interact with hardware through system software
19
20
Machine Languages, Assembly Languages,
and High-level Languages
• Three types of computer languages
1. Machine language
• Only language computer directly understands
• “Natural language” of computer
• Defined by hardware design
– Machine-dependent
• Generally consist of strings of numbers
– Ultimately 0s and 1s
• Instruct computers to perform elementary operations
– One at a time
• Cumbersome for humans
• Example:
+1300042774
+1400593419
+1200274027
27
30
• Editor
• Interpreter and Compilers
• Debuggers
It contains
• Editor
• Compilers
• Debugger
• Linkers
• Loaders
6. Execute CPU
Primary
Memory
• Input/output
– cin
• Standard input stream
• Normally keyboard
– cout
• Standard output stream
• Normally computer screen
#include <iostream>
using namespace std;
int main ( )
{
cout << “ Welcome” ;
return 0;
}
Welcome to C++!
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
Variable
Variable X
• 25
name
• 10323 of the
variable
43
2003 Prentice Hall, Inc. All rights reserved.
45
e.g. x= 2;
Variable
In a program a variable has:
1. Name
Valid identifier
– Series of characters (letters, digits, underscores)
– Cannot begin with digit
– Case sensitive
2. Type
– Common data types (int, char, double)
– Can declare several variables of same type in one declaration
– Comma-separated list
int integer1, integer2, sum;
3. Size
4. Value
2003 Prentice Hall, Inc. All rights reserved.
47
Variable
Variable starts with
1. Character
2. Underscore _ (Not Recommended)
Assignment Operator
=
x=2
X
2
2003 Prentice Hall, Inc. All rights reserved.
49
Assignment Operator
L.H.S = R.H.S.
X+ 3 = y + 4 Wrong
Z = x +4
x +4 = Z Wrong
X = 10 ; X 10
X = 30 ;
30
X = X + 1;
10 + 1
= 11
X
2003 Prentice Hall, Inc. All rights reserved.
Data type
• int i ; ->
Declaration line
i
52
2003 Prentice Hall, Inc. All rights reserved.
53
#include <iostream>
main ( )
{
int x ;
int y ;
int z ;
x = 10 ;
y = 20 ;
z=x+y;
int x, y, z ;
int x; int y; int z ;
Memory Concepts
Data Types
1. int
2. short
3. long
4. float
5. double
6. char
2003 Prentice Hall, Inc. All rights reserved.
57
Arithmetic operators
Plus +
Minus -
Multiply *
Divide /
Modulus %
2003 Prentice Hall, Inc. All rights reserved.
58
Arithmetic operators
i+j
x*y
a/b
a%b
2003 Prentice Hall, Inc. All rights reserved.
59
% = Remainder
5%2=1
2%2=0
4/2=2
5/2=?
Precedence
• Highest: ( )
• Next: *,/,%
• Lowest: +,-