Académique Documents
Professionnel Documents
Culture Documents
Introduction to
Algorithm and
Programming
Computer Programming
A form of problem solving
Or, more accurately, a way to solve
problems
What we will be studying is How to solve
problems using computers
Whats a Problem?
A question that someone wants an answer to
A problem usually has information that
represents a starting point, initial
assumptions, facts, or data that will be
needed in answering the question
For example, What is my grade point
average?
Four Steps
1.
2.
3.
4.
What is an Algorithm?
A Simple Example
Example Expanded
10
Computer Basics
Hardware and Memory
Programs
Programming Languages
Compilers
11
instructions
Memory
Main
memory (RAM)
Secondary (auxiliary) memory
Disk drives (hard drives)
Diskettes (floppies)
Compact disks (and DVDs)
USB Flash Drives
12
13
14
Programs
A program is simply a set of instructions for a
computer to follow.
A computer executes the instructions in the
program to process the data or information
provided as input in order to produce the results or
output desired.
It is actually the operating system (just another
program) running on the computer that executes
your program.
15
Programming Languages
Java
16
Compilers
Compilers are programs that translate high
level languages into low level languages
Compilers are generally machine dependent
because different machines have different
machine languages
The input to the compiler is called the source
code and the output is called the object
code
17
Syntax
errors
Runtime errors
Logic errors
18
Syntax Errors
A syntax error is a grammatical mistake in a
program.
There are strict grammatical rules for writing
programs including required punctuation
marks.
The compiler will catch syntax errors and give
its best guess as to the problem, but is often
wrong regarding the actual mistake made.
19
Run-Time Errors
Errors caught when the program is run.
The computer will give an error message,
but such messages are often hard to
understand.
You can be sure that there is an error in
your program but it may take some time to
find.
20
Logic Errors
If the program runs successfully to
completion but produces the wrong result,
you have a logic error.
What you have written is a valid program,
but it doesnt do what it is supposed to do.
These are the most difficult errors to find.
21