What Is a Computer?
A computer is an electronic device that accepts data from the user, processes it, produces results, and stores those results for future use. Data is raw, unorganized facts; information is data that has been processed into something meaningful.
Hardware and Software
Hardware refers to the physical, mechanical parts of a computer — the devices you can touch. This includes the CPU, keyboard, mouse, hard drive, and other components.
Software is the set of instructions that drives the computer to perform tasks. Software falls into two categories:
- System software — operates directly on the hardware (e.g., Windows, Linux, Unix).
- Application software — designed to help users perform specific tasks (e.g., word processors, spreadsheets).
Programs and Programming
A program is the ordered set of instructions a computer follows to process data into information. Writing that set of instructions is called programming.
The five-step programming process:
- Define the problem — understand what needs to be solved. Specify objectives, identify users, define inputs and outputs, and assess feasibility.
- Design the solution — plan the logic using tools like hierarchy charts, flowcharts, or pseudocode.
- Code the program — translate the design into a specific programming language.
- Test the program — desk check, debug, and run with real data to confirm correctness.
- Document the program — write user, operator, and programmer documentation.
Types of errors:
- Syntax errors — incorrect formatting, caught during compilation.
- Logic errors — code runs but produces wrong results due to faulty reasoning.
Program Logic Formulation
Before writing code, plan the logic. Two common tools: flowcharts and pseudocode.
Flowcharts
A flowchart is a visual representation of a solution using standardized shapes connected by arrows.
| Symbol | Name | Purpose |
|---|---|---|
| Oval | Terminal | Marks start or stop |
| Parallelogram | Input/Output | User input or output of results |
| Rectangle | Process | Computation or data manipulation |
| Diamond | Decision | Condition — TRUE or FALSE paths |
| Arrow | Flow Line | Direction of execution |
| Circle | Connector | Connects parts across pages |
Three fundamental control structures:
1. Sequential — steps execute one after another in order.
START → Initialize → INPUT → PROCESS → OUTPUT → STOP
2. Selection — a decision point where one of two paths is taken.
START → INPUT A
IF A < 0 → OUTPUT "NEGATIVE"
ELSE IF A == 0 → OUTPUT "INVALID"
ELSE → OUTPUT "POSITIVE"
STOP
3. Repetition — steps are repeated until a condition is met.
START → N=0
LOOP while N < 10:
N = N + 1
IF N is odd: OUTPUT N
STOP
These three structures — sequence, selection, repetition — are sufficient to construct any program logic.
Algorithms (Pseudocode)
An algorithm is a step-by-step description of a solution written in structured English-like language. Also called pseudocode.
Common pseudocode conventions:
- Arithmetic:
+,-,*,/ - Assignment:
→(arrow pointing to the variable) - Input:
INPUTorREAD - Output:
OUTPUT,PRINT, orDISPLAY - Indentation shows grouping of related steps
Sequential example — sum of two numbers:
ALGORITHM sum
A → 0, B → 0, SUM → 0
INPUT A, B
SUM → A + B
OUTPUT SUM
END sum
Sequential example — product of three numbers:
ALGORITHM product
A → 0, B → 0, C → 0, PRODUCT → 0
INPUT A, B, C
PRODUCT → A * B * C
OUTPUT PRODUCT
END product
Selection example — positive or negative number:
ALGORITHM pos_neg
N → 0
INPUT N
IF N < 0 THEN
OUTPUT "NEGATIVE"
END IF
IF N == 0 THEN
OUTPUT "INVALID"
ELSE
OUTPUT "POSITIVE"
END IF
END pos_neg