Lec1 - Introduction To Computers, Programs, and C++
Lec1 - Introduction To Computers, Programs, and C++
Fundamentals of Programming – 1 2
Definitions
• program: A set of instructions that are to be carried
out by a computer.
Fundamentals of Programming – 1 3
High Level Languages
• Computers are fast
• Intel® Core™ i7-8086K Processor on
the order of 2 billion transistors
(a switch that is on or off)
• performs tens of billions of operations
per second
• Computers are simple
• They can only carry out a very limited set of
instructions
• on the order of 100 or so depending on
the computer's processor
• machine language instructions, aka
instruction set architecture (ISA)
• Add, Branch, Jump, Get Data, Get
Instruction, Store, (CS429)
Fundamentals of Programming – 1 4
Machine Code
Fundamentals of Programming – 1 5
Say What?
BRn x3008
ADD R3, R3, R4
ADD R1, R1, #1
LD R4, R1
BRnzp x3003
Fundamentals of Programming – 1 6
High Level Languages
int sum = 0;
int count = 0;
while (list[count] != -1) {
sum += list[count];
count = count + 1;
}
Fundamentals of Programming – 1 7
Computer
• What is?
‒ A computer is an electronic device that stores and processes data
• Computer Consists of
‒ Hardware
‒ Software
Fundamentals of Programming – 1 8
Hardware Components
• Central processing unit
• Memory
• Storage devices
• Input devices
• Output devices
• Communication devices
Fundamentals of Programming – 1 9
Central Processing Unit
• Retrieves instructions from memory and executes them
• Two components
‒ Control unit
‒ Arithmetic / Logic unit
• Built from millions of transistors
• Internal Clock
‒ Used to control and synchronize the pace of operations
‒ Clock Speed Unit (hertz)
• Number of Cores
Fundamentals of Programming – 1 10
Central Processing Unit
Fundamentals of Programming – 1 11
Storage Devices
• RAM is volatile
‒ Data is lost when power is off
• Permanent storage elements?
‒ Hard disk
‒ CD / DVD
‒ Flash drive
• Programs and Data are store in permanent storage
‒ Moved to memory for processing
Fundamentals of Programming – 1 12
An Important Realization
• Computers are stupid.
Fundamentals of Programming – 1 1
A Simple C++ Program
• Preprocess directives
are not statements
(no semi-colon ;)
• Case Sensitive
‒ Main vs main
Fundamentals of Programming – 1 14
Listing 1.2
• Output?
Fundamentals of Programming – 1 15
Listing 1.3
• Output?
Fundamentals of Programming – 1 16
Output?
Fundamentals of Programming – 1 17
C++ Program
Development Cycle
Fundamentals of Programming – 1 18
Programming Style and Documentation
• Appropriate Comments
• Comment Styles
• Proper Indentation and Spacing
Fundamentals of Programming – 1 19
Errors?
Fundamentals of Programming – 1 20
Programming Errors
• Syntax Errors
• Runtime Errors
• Logic Errors
Fundamentals of Programming – 1 21
Programming Errors
• Syntax Errors
Fundamentals of Programming – 1 22
Programming Errors
• Syntax Errors
• Runtime Errors
Fundamentals of Programming – 1 23
Programming Errors
• Syntax Errors
• Runtime Errors
• Logic Errors
Fundamentals of Programming – 1 24
Common Errors
Fundamentals of Programming – 1 26