Notes: Basics of a Computer Program
For First Year Mechanical Engineering Students
1. What is a Computer Program?
A computer program is a sequence of instructions written to perform a specific task using a
comp ut er.
It automates problem-solving and data processing, turning user inputs into meaningful
outputs 1 2 .
2. Algorithms
Definition:
An algorithm is a precise, step-by-step procedure for solving a problem or carrying out a
task 3 4 5 .
Algorithms are not tied to any specific programming language—they represent logical steps.
Example Making Tea Algorithm):
Boil water.
Add tea leaves to boiled water.
Pour into cup.
Add sugar and milk as required.
Properties of Algorithms:
Clearly defined input and output.
Finiteness (they must end).
Definiteness (unambiguous steps).
Effectiveness (practical to carry out)4 5
.
3. Flowcharts
Definition:
A flowchart is a diagrammatic way to represent an algorithm using symbols like ovals,
rectangles, diamonds, and arrows.
Basic Symbols:
O val :Start/End
Rectan g l e:Process/Instruction
Diamond: Decision/Condition
Parallelogram: Input/Output
Creating Flowcharts Using Dia Tool:
Dia is free, open-sourcesoftwarefor drawing flowcharts and diagrams.
Steps to create a flowchart in Dia 6 7 8 :
Open Dia and select the flowchart module.
Drag and drop shapes (e.g., ovals, rectangles, diamonds) onto the canvas.
Connect shapes with arrows to indicate flow of control.
Label each symbol clearly.
Export the flowchart as an image or PDF for inclusion in reports.
Benefits of Flowcharts:
Easy visualization of algorithms.
Helps in debugging and documentation.
4. Pseudocode
Definition:
Pseudocode is a plain-language description of the steps in an algorithm, structured to look
similartoprogramming code but not tied to any language's syntax 9 10 11 .
Ch ar acter i s ti cs :
Written in plain English.
Uses programming constructs (“IF THEN ELSE”, “FOR”, “WHILE”, etc.).
Focuses on logic, not syntax.
Pseudocode Example:
BEGIN
Input number
IF number > 0 THEN
Print "Positive"
ELSE
Print "Not Positive"
ENDIF
END
Advantages:
Easy transition from logic to actual code.
Useful for planning and discussion.
5. Introduction to Compilation and Execution
The Life Cycle of a Program
1. Writing Source Code:
The programmer writes the code in a high-level language (e.g., C, Python)12 13
.
2. Compilation:
A compiler translates high-level source code into machine code.
Steps in compilation may include:
Preprocessing: Handles instructions like #include C/C , inserts code from other
f ile s.
Parsing: Checks the code structure for errors.
Static Checking: Ensures type correctness.
Code Generation: Converts code into machine instructions.
Linking: Combines code with libraries into an executable file.
Optimization: Improves code for speed or efficiency 13 14 .
3. Execution:
The executable file is loaded into memory and run by the operating system.
In interpreted languages (like Python), the interpreter reads and executes code line-by-line
instead of compiling 12 .
Key Points:
Compilation exposes errors before execution.
Execution is the actual running of the compiled program.
Understanding this process helps with debugging and program efficiency.
6. Quick Reference Table
Co n cep t Description Example/Tool
Algorithm Step-by-step solution procedure Sorting a list
F l o wch art Visual diagram of algorithm using standard symbols Dia tool
Pseudocode Human-readable algorithm logic, resembles programming code “IF age>18 THEN...”
Compilation Translation of source code to machine code gcc, Python (for .pyc files)
Execution Running the actual program Running .exe file
7. Key Takeaways
Algorithms form the foundation of all computer programs.
Flowcharts help visualize and design algorithms easily and are simple to create using tools
like Dia.
Pseudocode bridges the gap between logic and real programming.
Understanding compilation and execution is vital for writing error-free, efficient programs.