0% found this document useful (0 votes)
287 views9 pages

Unit 1 PDF

The document provides an introduction and overview of computer programming concepts for Unit 1, including: - The evolution of programming languages from machine languages to modern high-level languages. - Key software concepts like compilers, linkers, loaders, algorithms, pseudocode and flowcharts. - Explanations of low-level languages like machine language and assembly language, and how high-level languages build upon them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
287 views9 pages

Unit 1 PDF

The document provides an introduction and overview of computer programming concepts for Unit 1, including: - The evolution of programming languages from machine languages to modern high-level languages. - Key software concepts like compilers, linkers, loaders, algorithms, pseudocode and flowcharts. - Explanations of low-level languages like machine language and assembly language, and how high-level languages build upon them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer Programming (Object Oriented Programming) (CSN104) Unit 1

Introduction to Programing (Unit 1)


[Lecture Notes]
[Monday, September 2, 2019]
[By: Dr. Sachin Chaudhary]

• 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?

Syllabus: Evolution of languages: Machine languages, Assembly languages, Highlevel


languages. Software requirements for programming: System softwares like operating system,
compiler, linker, loader; debugging, Algorithm, specification of algorithm. Flowcharts. Logic
building for practical problems

1. What is a computer program?

It is a set of instructions to execute a specific task on a computer. A computer program is


usually written by a computer programmer in a programming language (e.g. C, C++, Java,
python, C#). Each programming language has its own way of writing i.e. syntax and compiler
i.e. a translator that convert the programming language into a machine understandable code
(machine language).

Fig 1. Illustration of program in machine language.

2. History of programming language:

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.

1951-60 1961-70 1971-80 1981-90 1991-2000 2001-10


2011-
Present
Fortran SNOBOL C, SQL, MATLAB, Python PHP, C#, Go Kotlin,
and Simula67, C++. FoxPro, Java, Ruby, and Rust. Swift.
COBOL PASCAL Objective C Javascript,

Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 1
Computer Programming (Object Oriented Programming) (CSN104) Unit 1

3. Machine languages, Assembly languages, High-level languages

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.

Fig 2. Levels of Programming Language

3.1. Machine languages

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

3.2. Assembly Language


Programming in Machine language is tedious (you have to program every command from
scratch) and hard to read & modify (the 1s and 0s are kind of hard to work with…). For these
reasons, Assembly language was developed as an alternative to Machine language.

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.

Fig 3. Illustration of conversion from assembly language to machine language.

3.3. High-level languages


High-Level languages are platform independent, meaning that you can write & run High-Level
Languages on different types of machines. High-Level Languages are English like and
therefore easier to learn and use. Note that instructions in a High-Level Language are called
statements.

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. Compiler, Linker, Loader

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

Fig 4. Illustration of the working of compiler

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. Algorithm, pseudocode and flow-charts.

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

• Algorithms should have explicitly defined set of inputs and outputs


• Algorithms are well-ordered with unambiguous operations
• Algorithms halt in a finite amount of time. Algorithms should not run for infinity, i.e.,
an algorithm must end at some point.

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.

5.3.Difference between Algorithm and Pseudocode


An algorithm is a formal definition with some specific characteristics that describes a process,
which could be executed by a Turing-complete computer machine to perform a specific task.
Generally, the word "algorithm" can be used to describe any high level task in computer
science.
On the other hand, pseudocode is an informal and (often rudimentary) human readable
description of an algorithm leaving many granular details of it. Writing a pseudocode has no
restriction of styles and its only objective is to describe the high level steps of algorithm in a
much realistic manner in natural language.
For example, following is an algorithm for Insertion Sort.

Algorithm: Factorial calculation

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

A flowchart is a graphical representation of an algorithm. It was originated from computer


science as a tool for representing algorithms and programming logic but had extended to use
in all other kinds of processes. Nowadays, flowcharts play an extremely important role in
displaying information and assisting reasoning. They help us visualize complex processes, or
make explicit the structure of problems and tasks. A flowchart can also be used to define a
process or project to be implemented.

Flowchart Symbols

Different flowchart shapes have different conventional meanings. The meanings of some of the
more common shapes are as follows:

Name Symbol Meaning


(a) Terminator The terminator symbol represents
the starting or ending point of the
system.
(b) Process A box indicates some particular
operation.

(c) Document This represents a printout, such as a


document or a report.
(d) Decision A diamond represents a decision or
branching point. Lines coming out
from the diamond indicates different
possible situations, leading to
different sub-processes.
(e) Data It represents information entering or
leaving the system. An input might
be an order from a customer. Output
can be a product to be delivered.
(f) On-Page This symbol would contain a letter
Reference inside. It indicates that the flow
continues on a matching symbol
containing the same letter
somewhere else on the same page.
(g) Off-Page This symbol would contain a letter
Reference inside. It indicates that the flow
continues on a matching symbol
containing the same letter
somewhere else on a different page.
(h) Delay or Identifies a delay or a bottleneck.
Bottleneck
(i) Flow Lines represent the flow of the
sequence and direction of a process.

Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 6
Computer Programming (Object Oriented Programming) (CSN104) Unit 1

When to Draw Flowchart?


Using a flowchart has a variety of benefits:
• It helps to clarify complex processes.
• It identifies steps that do not add value to the internal or external customer, including
delays; needless storage and transportation; unnecessary work, duplication, and added
expense; breakdowns in communication.
• It helps team members gain a shared understanding of the process and use this
knowledge to collect data, identify problems, focus discussions, and identify resources.
• It serves as a basis for designing new processes.

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

(b) Flowchart Example – Simple Algorithms

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

(c) Flowchart Example – Calculate Profit and Loss

The flowchart example below shows how profit and loss can be calculated.

Sachin Chaudhary
Asst. Proffesor, PEC, Chandigarh. Page 9

You might also like