You are on page 1of 12

1

WHAT IS A COMPUTER?

An electronic device operating under the


control of instructions stored in its own
memory that accepts data, processes data
into information and produces and produces
and stores results.
Computer is a programmable machine
designed to follow instructions.

COMPONENTS OF COMPUTER SYSTEMS

Hardware

Software

Peopleware

Dataware

COMPONENTS OF A CPU

Control Unit it acts as a supervisor


that controls and supervises the
operation in the CPU.

Arithmetic Logic Unit (ALU) it


performs the mathematical and logical
operations of the computer system.

MAIN MEMORY

It is a temporary holding place for data


and instructions. Holds both program
instructions and data.

Also called Random Access Memory


(RAM)

Bit

Hardware
The Nuts and Bolts of the Machine

It refers to the physical components of


the computer system.

Smallest piece of memory

Stands for binary digit

Has values 0 (off, false) or 1 (on,


true)

Main Hardware Component Categories


1. Input Devices

2. Central Processing Unit (CPU)


3. Main Memory
4. Secondary Storage
5. Output Devices
INPUT DEVICES

Used to send information to the


computer from outside

Many devices can provide input

keyboard, mouse, scanner, digital


camera, microphone

CENTRAL PROCESSING UNIT (CPU)

The CPU is where most calculations take


place.

It is the brain and heart of the


computer system.

CPU is housed in a single chip called a


microprocessor.

Byte

Is 8 consecutive bits

Bytes have addresses

A byte can hold one character

SECONDARY STORAGE

Refers to the media on which data,


instructions, and information are kept.

Secondary devices can store instructions


and data when they are not being used
by the system unit.

Secondary Storage differs from


memory, that it can hold instructions or
items permanently.

Main Memory, by contrast, holds items


only temporarily while the processor
interprets and executes instructions.

OUPUT DEVICES

Used to send information from the


computer to the outside

Many devices can be used for output

monitor, printer, speaker

Main Hardware Component Categories

Examples: Windows, MS DOS, Linux/Unix,


MAC OS, C++, Visual Basic, Assembly
Language, Dev C++ Compilers, Virus
Scanner, System Restore, Java,
APPLICATION SOFTWARE

Central
Output
Input
Processing
Main
Device Unit Device
Memory
Secondary
Storage
Devices

These are program, which provide a


solution to a specific operation or
application.

It caters the need of the users.

Applications software comprises


programs designed for an end user, such
as word processors, database systems,
and spreadsheet programs.

PEOPLEWARE

Software
Bringing the Machine to Life

Represent the personnel involves in


system analysis, programming,
computer operation, system
maintenance, and the like.

It refers to the instructions or programs


that tell the computer to do a specific
task.

The set of instructions that guides the


hardware through its job.

It consists of people who use the


computers.

Also called a Program.

Ex: Programmer, Encoder, Data Entry,


IT Professionals and End-users

Software Programs That Run on a


Computer

System software

- These are programs, which control and


assist in the computer operation and its
devices.

Application software

Programs that provide services to


the user.

Ex: word processing, games, database


system
SYSTEM SOFTWARE
System Software Classifications:

Operating Systems

Compilers

System Utilities

Programming Language

DATAWARE

It is an input to the computer so that it


can be transformed into information.

These are raw facts which are processed


to produce information.

Ex: text, numbers, sound, images, video

Information data that have been processed


and presented in a form suitable for the user or
human to interpret or understand.

Programs and Programming


Languages

Program - are the directions given to


computers to make it do something.

Programmer - person who writes


instructions (programs) to make
computer perform a task.

Programming Language - enable the


programmers to communicate with
the computer.

Popular languages: C++, Visual


Basic, C, Java, PHP

Types of Programming
Languages

Machine Languages

Assembly Languages

High-level Languages

MACHINE LANGUAGES

Machine language or low level language is


the most basic language of a computer.

A sequence of 0s and 1s.

Machine languages are the only way to


communicate directly with the computer.

Example: 00101 10001 10000

ASSEMBLY LANGUAGES

High-level languages allows the


programmer to use English-like
instructions.

Closer to spoken languages and it make


programming easier.

Compilers - translate high-level


instructions into 0s and 1s or machine
language.

Example: C++, C, Java, PHP, Visual Basic

Processing a High-Level
Language Program

Editing the program

Compiling

Linking

Executing

Programming in machine language are


tedious and error-prone and requires
highly trained programmers.

Assembly languages were developed to


make the programmer's job easier.
It is a low-level programming language
for computers, microprocessors,
microcontrollers, and other
programmable devices.
In assembly language, an instruction is
an easy-to-remember form called
mnemonics.
Assembler - a program which translates
the mnemonic language understood
by the programmer into a binary form
understood by the computer.
Example: Bx, Ax (registers)

HIGH-LEVEL LANGUAGES

EDITING

You write a program with words or


symbols that are understandable to
human beings.

You type the program directly into a


window or screen and save the resulting
text as a separate file source file.

The text of a C++ program is stored in a


file with extension of .cpp for C++
programming language.

COMPILING

You cannot directly execute the source


file.

To run on any computer system, the


source file must be translated into binary
numbers.

Test the program

This process produces an intermediate


object file with extension of .obj for C++
programming language.

Put the program into production

1. Understand the Problem

LINKING

Before writing the program the


programmer must first understand the
problem.

The linker connect hardware-specific


code (eg. input/output functions) to
machine instructions, producing the file
extension .exe which are executable file.

Satisfy the users need

EXECUTABLE FILES

One of the most difficult task since


description of what is needed may be
vague, or worse yet, the user may not
even know what he/she wants.

The text editor produces .cpp source


files, which go to the compiler, which
produces .obj object files, which go to
the linker, which produces .exe
executable files.

A good programmer is part counselor,


and part detective.

Steps 2-4 are often performed by a


single command or button click.

2. Plan the Logic

Errors detected at any step will prevent


execution of the following steps.

The process of planning for the solution of


the problem.
They are referred to as
ALGORITHMS

Algorithm and
Flowcharting
COMPUTER PROGRAM
A set of detailed, step-by-step
instructions that directs the computer
what you want it to do.
Programs are written in a programming
language - which is a set of rules that
provides a way of telling the computer
what operations to perform.
The person who creates computer
program is called computer programmer.

STEPS IN PROGRAMMING
Understand the problem
Plan the logic
Code the program
Compile the program into machine
language

Involves writing down steps (in English).


The programmer doesnt worry about
syntax at this point, just the sequence of
events that will lead from available input
to the desired output.

3. Code the Program


There are over 400 programming
languages that exist.

Most programming languages


have translators also known as compiler
and interpreters.

Pascal, C, C++, Visual Basic,


Cobol, etc.

The part in which the programmer worry


about the correct syntax; command,
punctuation, spelling, etc.
The actual construction of the source
code.

4. Compile the program into


Machine Language
Machine language - the only language
a computer knows.

Its consists of 0s and 1s.


Compiler is a special program that
translates high-level language
instructions into machine language.
Compiler catches all syntax errors.

The organization can now use the


program.
Training personnel to use the program.
Running the program using the actual
data.
Test for users approval.

ALGORITHM
A sequence of well-understood steps for
a person to follow in order to accomplish
a certain task or to solve a particular
problem.
It is a finite set of instructions that
specify a sequence of operations to be
carried out in order to solve a specific
problem or class of problems.
Examples:
directions for going to a certain place
baking a chocolate cake
computing income tax
searching for a name in a telephone directory

CHARACTERISTICS OF ALGORITHMS
Specify each step or instruction
exactly.
The instructions must be clear.

5. Test the Program

There must be a finite number of


steps.

To execute and then run the program.

The algorithm must terminate.

The program upon execution is being


subjected to different kinds of test data
to anticipate and correct errors that
might occur before releasing the
program to the users.

There must be a stopping point.

6. Put the Program into Production

There must be an output.


-

The algorithm must


produce the correct result

Common Tools of Algorithm


FLOWCHARTS

6
PSEUDOCODE

be passed from the memory to an output


device.
Process (RECTANGLE)

FLOWCHARTS
A graphical representation of the logical
steps that solves a problem.
A diagram representing the logical
sequence in which a combination of
steps or operation is to be performed. It
is a blueprint of the program.
Programmers use flowcharts to
understand the logic processing of data.
Although time consuming, its the best
tool for beginners.
BASIC FLOWCHARTING SYMBOLS

Termi
Proce
nal
Input/
ss
block
Decis
Outp
symb
ion
ut
ol
symb
block
ol

OnOffpage
Initiali
page
Conn
Flow
zatio
Conn
ector
lines
n
ector
symb
ol

- performs any calculations that are to be


done.
Decision (DIAMOND)
- signifies any decisions that are to be
done. Two alternative execution paths are
possible. The path to be followed is
selected during the execution by testing
whether or not the condition specified
within the outline is fulfilled.
On-page Connector (SMALL CIRCLE)
- show the entry or exit point of the
flowchart. A non-processing symbol used to
connect one part of a flowchart to another
without drawing a flowlines.
Off-page Connector (PENTAGON)
- Sometimes a flowchart will not fit on one
page.
- Designates entry or to exit from one page
when a flowchart requires more than one
page.
Flowlines

Terminal (OVAL)
- used to signify the beginning and end of
flowchart
Initialization (HEXAGON)
- signifies the initialization or preparation of
data.
-

used to represent instructions or group


of instructions that will alter or modify a
programs course of execution.

Input/Output (PARALLELOGRAM)
- shows input and output.
Data are to be read into the computer
memory from an input device or data are to

- signifies the process that is to be


executed next

A variable is a temporary container to


store information, it is a named location in
computer memory where varying data like
numbers and characters can be stored and
manipulated during the execution of the
program.
A constant is a value that never changes
during the execution of the program.

Rules in Naming Variables


Names may contain letters,
numbers, and underscores.
Names must start with a letter.

7
Names cannot contain spaces.

Close to a natural language

Names cannot contain special


characters

The control structures impose the


logic

Relational Operators an operators that


compares two values and determines the
relationship between them.

May become a part of the program


documentation

Four Flowchart Structures


Sequence ,Decision ,Repetition,
Case

SEQUENCE STRUCTURE
Directs the computer to process the
program instructions, one after another,
in the order listed in the program.
Series of actions are performed in
sequence

Where did C++ come from?


Derived from the C language
C was derived from the B
language
B was derived from the BCPL
language
BCPL - Basic Combined
Programming Language

DECISION STRUCTURE
Makes a decision and then takes an
appropriate action based on that
decision
Example: waiting or crossing at railroad
tracks depending on signal lights

REPETITION STRUCTURE
A repetition structure represents part of
the program that repeats. This type of
structure is commonly known as a loop.

CASE STRUCTURE
One of several possible actions is taken,
depending on the contents of a variable.

Pseudocode

Why the ++?


++ is an operator in C++
C developed by Dennis Ritchie at AT&T
Bell Labs in the 1970s.
Used to maintain UNIX systems
Many commercial applications
written in C
C++ developed by Bjarne Stroustrup at
AT&T Bell Labs in the 1980s.
Overcame several shortcomings
of C
Incorporated object oriented
programming

C remains a subset of C++


A detailed description of what a
computer program or algorithm must do. Developing a program in C++ requires at
least four steps:
A textual presentation of a flowchart

8
Editing the program- You write a
program with words or symbols that are
understandable to human beings.
-

You type the program directly into a


window or screen and save the resulting
text as a separate file source file.
The text of a C++ program is stored in a
file with extension of .cpp for C++
programming language.

Compiling - You cannot directly execute MEMORY LOCATION


the source file.
Data Type - indicates what type of information
the address will store (e.g., numeric or textual).
- To run on any computer system, the
source file must be translated into binary Identifier - allows the programmer to refer to
numbers.
the memory location elsewhere in the program.
- This process produces an intermediate
object file with extension of .obj
- Names made up by the programmer.
Linking - The linker connect hardwareTypes of Identifier
specific code (eg. input/output functions)
Variables - are memory locations
to machine instructions, producing the
whose values can change during runtime
file extension .exe which are executable
(when the program is running). Most
file.
memory locations are variables.
Executing - The text editor produces .cpp
Constants - are memory locations
source files, which go to the compiler,
whose content cannot be changed
which produces .obj object files, which
during program execution. Often named
go to the linker, which produces .exe
in uppercase letters. Example: PI
executable files.
(constant), radius (variable)
- Steps 2-4 are often performed by a
Rules In Naming Identifiers (variables)
single command or button click.
- Errors detected at any step will prevent
execution of the following steps
Dev-C++ is a full-featured Integrated
Development Environment (IDE) - which is able
to create Windows or DOS-based C++
programs using the Cygwin compiler.
IDE a system that includes both editor and a
compiler.
Microsoft Visual C++, Borland C++ are other
example of IDE
Steps in Configuring a Dev-C++ Program

valid or invalid variables

C++ Keywords
Keywords are predefined reserved words
or reserved identifiers that have special
meanings.
-

They cannot be used as identifiers in


your program

Declaring Memory Location


When declaring a memory location a
data type and an identifier (variable
or constant) must be provided

Fundamental Data Types in C++


bool - stores Boolean values (true or
1 and false or 0)
short and int - store integers
(numbers without a decimal place)
-

Differences are range of values and


memory used (int has the greater of
both)
float and double - store real
numbers (numbers with a decimal
place)
-

Syntax for declaring a variable in C+


+
DataType Identifier ;
Examples:
string age;
float length;
int width;
string lastname;

Differences are range of


values, precision, and memory
used (double has the greater
of each)

char - stores characters (letter,


symbol, or number that will not SAMPLE C++ PROGRAM
be used in a calculation)
-

Only one character stored at a


time

string - is a user-defined data


type, can store zero (blank) or
more characters

10

cout<< "The sum is: ";


Note: Each statement must end with a
semi-colon ;
cin (see-in) console input - used to
obtain information from the keyboard
(program pauses while user enters data)
-

Pair with extraction operator (>>) takes information from the keyboard
to a variable and stores it in internal
memory

cout (see-out) console output - send


information out to the user or output to
the monitor
-

Pair with the insertion operator (<<)


- to display information on the
computer screen

Starting a New Line


endl (end line) - is a stream
manipulator that advances the cursor
to the next line on the screen
cout<< "Hello, there!" << endl;

\n (same as endl) causes a new


line to be started on the monitor

cout<< "Hello, there! \n";


Both are equivalent to pressing the
Enter key
Program Statement
cout<< "Input the first number: ";
cout<< "Input the second number: ";

Program Layout
Compiler accepts almost any pattern
of line
breaks and indentation
Programmers format programs so
they
are easy to read

11

Place opening brace { and


closing brace }
on a line by themselves
Indent statements
Use only one statement per
line
Variables are declared before they
are used
Typically variables are declared
at the beginning of the
program
Statements (not always lines)
end with a semi-colon

pauses program execution and


display Press any key to continue
message in the command prompt
window on the computer screen
return 0;
-

returns the number 0 to the


operating system to indicate
that the program ended
normally

Comment
is simply a message to the
person reading that program
and is referred to as internal
documentation
Begin with // (two forward
slashes) before the text you
want treated as a comment
through the end of the line.
Ex: // This is a sample C++
program.
Comment
Comments can span multiple
lines
Begin with /* and end with */
Ex:
/*---------------------------Multi-line C++ style comment
----------------------------*/
Program comments may be
used anywhere in the program,
and are ignored by the
compiler.

Layout of a C++ Program


system ("pause");

12

Debugging- Eliminating mistakes in


programs
Two Types of Program Errors
Syntax Errors
Special Characters in C++

Violation of the grammar rules of the


language
Discovered by the compiler
Error messages may not always show
correct location of
errors

Logic Errors
-Errors in the programs algorithm
-Most difficult to diagnose
- Compiler does not recognize an error
Bug- A mistake in a program

You might also like