Chapter 1 Add 1
Chapter 1 Add 1
and
Programming
Definition of a Computer
A machine that given instructions and can
manipulate data by itself.
Basic Computer Needs :
o Need to perform calculations faster and more
accurately
o Need to control processes consistently
o Need to handle larger and larger amounts of
data
Computer System
A computer system contains two parts
hardware: actual pieces of equipment
keyboards, screens, components inside the boxes,
printers, modems, etc.
software: instructions that direct hardware
operating systems, compilers, applications
Hardware
Access to data
Read: fetching information from somewhere
Write: putting information somewhere
Common hardware components
Central Processing Unit (CPU)
Main Memory
Secondary Storage
Input & Output (I/O)
CPU
CPU is the heart of any computer
Three functions
control: CPU takes on instruction at a time and
follows it to direct the rest of the system
arithmetic operations: addition, subtraction,
multiplication, division
logical operations: comparisons
Main Memory
Main memory is a temporary, working
storage area
Stores two types of things
current set of instructions the CPU is following
data these instructions manipulate
Made up locations with unique addresses
Addresses allow random access of data
Very fast, but expensive and volatile
Secondary Storage
Permanent storage device
Disks, hard and floppy, are common examples
Relatively cheap, but slow (can be hundreds
of times slower than Main Memory)
Accessed in blocks (many characters at a
time)
I/O Devices
Provide a way for humans to communicate
with computers
Common input devices
Keyboard, mouse, scanner, etc.
Common output devices
Monitor, printer
Software
Legal definition of computer software as used
in the U.S Copyright Act of 1980
“a set of statements or instructions to be used
directly or indirectly in a computer in order to
bring about a certain result.”
A set of instructions is commonly called a
program
Software Categories
Software
Software
System
System Application
Application
Software
Software Software
Software
Object
Object
Compile
Compile File
File
Errors
Executable
Executable
Link
Link File
File
Errors
Test
Test
Errors
Modular Design
Large projects can be very difficult to
envision and implement
Breaking these into smaller tasks is called
modular design
Start with a single broad statement and work
in layers towards detailed descriptions of
small parts of the problem
This process is called top-down design
Modular Design
Student
Student
Portal
Portal
Finance
FinanceServices
Services eLibrary
eLibrary E-mail
E-mail LMS
LMS Examination
Examination
CIW306
CIW306 CKM313
CKM313 CCP203
CCP203
Modular Design Advantages
Separate tasks means that different people
(or computers) can work at the same time.
Modules are often reusable.
It is often easier to maintain many small
modules than one large product.
Terminologies
Program – set of instructions.
Programming – process of writing
instructions in understandable language by
computer and programmers.
Programming Language – set of
instructions that can be used to construct a
program.
Programming Language
FORTRAN, BASIC, COBOL, PASCAL, C,
etc
So many? – there are vast differences in
types of input data, calculations needed,
and output required by applications.
Indicates an input or
Input Input/Output output operation
three
values
Indicates computation or
Process data manipulation
End
Program Translation
Coding an algorithm
Translate the
Select an algorithm algorithm into C
Requirements
(step-by-step language
procedure) (coding)
C language Machine
source Translation language
program program program
Programming Process
Writing a program that performs the given
task is not always enough.
Good programmers should keep in mind
several objectives when writing code.
Often programmers have to make sacrifices
in one objective to reach acceptable levels in
another.
Programming Objectives
Execution efficiency
Will the program execute in a reasonable time?
Programming efficiency
How long will you spend creating the program?
Maintainability
How easy is it to change the program later?
Reusability
Can the code be used elsewhere easily?
Introduction
The ideal in programming – to efficiently
produce readable, error-free programs that
work correctly and can be modified or
changed with minimum testing required for
reverification.
Compile-Time and Run-Time Errors
Detection of errors:
1. Before a program is compiled
2. While the program is being compiled
3. While it is being run
4. After the program has been executed and the
output is being examined
5. Not at all
Compile-Time and Run-Time Errors
Compile-time Errors :- Errors detected by
compiler.
Run-time Errors :– Errors occur while
program is running.
Desk checking :– Method for detecting
errors before a program is compiled.
Program Verification and Testing :–
Method for detecting errors after a program
has been executed.
Syntax and Logic Errors
A syntax error – an error in the structure or
spelling of a statement.
Logic errors – erroneous, unexpected, or
unintentional errors resulting from a flaw in
the program’s logic.
Logic errors more difficult to detect
compared to syntax errors.
Syntax and Logic Errors
Generally, logic errors are include:
No output – caused of omission printf()
statement, or a sequence of statements that
inadvertently bypasses a printf() function call
Unappealing or misaligned output – caused
of printf() statements.
Incorrect numerical results – caused of
incorrect values being assigned, incorrect
arithmetic operations, omission of statements,
improper sequence of statements, or a roundoff
error.
Testing and Debugging
In theory, a comprehensive set of test runs
will reveal all logic errors and ensure that a
program will work correctly for any and all
combinations of input and computed data.
In practice, this requires checking all
possible combinations of statements
execution (for a simple program).
Testing and Debugging
Remember in testing phase:
Although a single test can reveal the presence
of an error, it does not verify the absence of
one.
The fact that one test reveals no errors does
not indicate that there are no errors.
Testing and Debugging
Debugging – the process of isolating,
correcting, and verifying the correction of
a program.
Techniques of debugging;
Desk checking before write and compile
programs – check pseudocode/flowchart
Program tracing
Diagnostic using printf() function calls to
display selected variables or all input data.
Using debugger
Use your ability to debug the errors