Unit 1 PDF
Unit 1 PDF
• Students are advised to read below given answers. This is an additional supporting
document to help the students towards preparation of Unit 1.
• It is highly recommended that students must able to explain all terms (minor or major) used
in the questions. You may discuss doubts/queries during the Lectures.
• You are supposed to read recommended book thoroughly along this questionnaire?
The programming languages are evolved to great extent over past few decades from Assembly
Language to Kotlin and Swift. This post list down the evolution of these languages over time
since 1950.
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 1
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
Each programming language was invented for a specific purpose. Each succeeding
programming language builds on the strength of its predecessors. For example, Machine
Language is succeeded by Assembly Language, which is succeeded by high-level languages.
In other words, High-level programming languages are built on Assembly Language, which is
built on Machine Language. The idea is that higher level languages calls functions of a lower
level languages with a single-simple short code.
A computer’s native language is called Machine Language. Machine language is the most
primitive or basic programming language that starts or takes instructions in the form of raw
binary code. So that if you wanted to give a computer an instruction in its native or Machine
language, you have to manually enter the instructions as binary code.
For example, adding two numbers together in machine language would look like this:
1101101010011010
Assembly Language uses short descriptive words (mnemonic) to represent each of the Machine
Language instructions.
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 2
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
For example, the mnemonic add means to add numbers together, and sub means to subtract the
numbers. So, if you want to add the numbers 2 and 3 in assembly language, it would look like
this:
add 2, 3, result
So Assembly Languages were developed to make programming easier. However, the computer
cannot directly execute the assembly language. First another program called the assembler is
used to translate the Assembly Language into machine code.
Note that a program written in a high-level language is called the source code. Note that the
Source Code must be translated into machine code before the computer can execute the source
code. And the translations are done by programming tools called an interpreter or compiler.
Here’s an example of a High-Level Language statement that calculates the area of a circle with
a radius of 5:
area = 5 * 5 * 3.14159;
Examples of High-Level Programming Languages include Ada, BASIC, C, C++, C#, COBOL,
FORTRAN, Java, Pascal, Python, and Visual Basic.
4.1.Compiler
A compiler is a computer program (or a set of programs) that transforms source code written
in a programming language (the source language) into another computer language (the target
language).
Typically, from high level source code to low level machine code or object code.
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 3
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
4.2. Assembler
An assembler translates assembly language programs into machine code. The output of a
assembler is called an object file, which contains a combination of machine instruction as well
as the data required to place these instructions in memory.
4.3. Linker
Linker is a computer program that links and merges various object files together in order to
make an executable file. All these files might have been compiled by separate assembler.
The major task of a linker is to search and locate referenced module/routines in a program and
to determine the memory location where these codes will be loaded making the program
instruction to have absolute reference.
5.4.Loader
Loader is a part of operating system and is responsible for loading executable files into memory
and execute them.
It calculates the size of a program (instructions and data) and create memory space for it. It
initializes various registers to initiate execution.
5.1. Algorithm
An algorithm is a set of steps of operations to solve a problem performing calculation, data
processing, and automated reasoning tasks. An algorithm is an efficient method that can be
expressed within finite amount of time and space.
An algorithm is the best way to represent the solution of a particular problem in a very simple
and efficient way. If we have an algorithm for a specific problem, then we can implement it in
any programming language, meaning that the algorithm is independent from any programming
languages.
Characteristics of Algorithms
The main characteristics of algorithms are as follows −
• Algorithms must have a unique name
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 4
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
5.2. Pseudocode
Pseudocode gives a high-level description of an algorithm without the ambiguity associated
with plain text but also without the need to know the syntax of a particular programming
language.
The running time can be estimated in a more general manner by using Pseudocode to represent
the algorithm as a set of fundamental operations which can then be counted.
Step 1:
Start
Step 2:
Declare Variable n, fact, i
Step 3:
Read number from User
Step 4:
Initialize Variable fact=1 and i=1
Step 5:
Repeat Until i<=number
5.1 fact=fact*i
5.2 i=i+1
Step 6: Print fact
Step 7: Stop
Here is a pseudocode which describes how the high-level abstract process mentioned above in
the algorithm Insertion-Sort could be described in a more realistic way.
Read number
Fact = 1
i = 1
WHILE i<=number
Fact=Fact*i
i=i+1
ENDWHILE
WRITE Fact
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 5
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
6.3.Flowcharts
Flowchart Symbols
Different flowchart shapes have different conventional meanings. The meanings of some of the
more common shapes are as follows:
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 6
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
Flowchart examples
Here are several flowchart examples. See how you can apply a flowchart practically.
(a) Flowchart Example – Medical Service
This is a hospital flowchart example that shows how clinical cases shall be processed. This
flowchart uses decision shapes intensively in representing alternative flows.
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 7
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
A flowchart can also be used in visualizing algorithms, regardless of its complexity. Here is an
example that shows how flowchart can be used in showing a simple summation process.
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 8
Computer Programming (Object Oriented Programming) (CSN104) Unit 1
The flowchart example below shows how profit and loss can be calculated.
Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 9