Professional Documents
Culture Documents
Lecture 2
Lecture 2
Lecture-2 PO 1
2.1 Programming
Programming is the process of taking an algorithm and encoding it into a notation, using
a programming language, so that it can be executed by a computer. Although many
programming languages and many different types of computers exist, the important first
step is the need to have the solution. Without an algorithm there can be no program.
Computer science is not the study of programming. Programming, however, is an
important part of what a computer scientist does. Programming is often the way that
we create a representation for our solutions. Therefore, this language representation and
the process of creating it becomes a fundamental part of the discipline.
Algorithms describe the solution to a problem in terms of the data needed to repre-
sent the problem instance and the set of steps necessary to produce the intended result.
Programming languages must provide a notational way to represent both the process and
the data. To this end, languages provide control constructs and data types.
Control constructs allow algorithmic steps to be represented in a convenient yet un-
ambiguous way. At a minimum, algorithms require constructs that perform sequential
processing, selection for decision-making, and iteration for repetitive control. As long as
the language provides these basic statements, it can be used for algorithm representation.
9
is an artificial language designed to communicate instructions to a machine, particularly
a computer. Programming languages can be used to create programs that control the
behaviour of a machine and/or to express algorithms. Any programming language is
composed of a set of predefined words that are combined according to predefined rules
(syntax) to generate a computer program.
10
• Machine Language: Machine language is the sequence of bits (machine code)
that directly controls a processor, causing it to add, compare, move data from one
place to another, and so forth at appropriate times. The computer microprocessor
can process directly the machine codes without a previous transformation. Spec-
ifying programs at this level of detail is an enormously tedious task. Currently,
programmers almost never write programs directly in machine code, because it
requires attention to numerous details which a high-level language would handle
automatically, and also requires memorizing or looking up numerical codes for ev-
ery instruction that is used.
At present, High Level languages have replaced machine and assembly language in all
areas of programming. Programming languages were designed to be high level if it is inde-
pendent of the underlying machine. High-level languages (also known as problem-oriented
languages) enable a programmer to write programs that are more or less independent of
a particular type of computer. Such languages are considered high-level because they are
closer to human languages and farther from machine languages. High level languages are
portable (machine independent) as it can be run on different machines with little or no
change. Furthermore, the rules for programming in a particular high-level language are
much the same for all computers, so that a program written for one computer can gener-
ally be run on many different computers with little or no alteration. Thus, we see that a
high-level language offers three significant advantages over machine language: simplicity,
uniformity and portability. Higher-level languages provide a richer set of instructions
and support, making the programmer’s life even easier. The languages such as BASIC,
COBOL, FORTRAN, C, C++, JAVA and Visual Basic are popular examples of high level
languages. High level languages use translator programs such as compiler and interpreter
to convert it into a machine language program.
11
codes ease programmer to write efficient program. But an intermediary agent is required
to translate these mnemonic codes into machine codes. There are different types of
translators for different categories of languages Software viz. assembler for assembly
language, interpreter and compiler for high-level language.
• Compiler:The language processor that reads the complete source program written
in high level language as a whole in one go and translates it into an equivalent
program in machine language is called as a Compiler.In a compiler, the source code
is translated to object code successfully if it is free of errors. The compiler specifies
the errors at the end of compilation with line numbers when there are any errors
in the source code. Example: C, C++, Java
12
• Perform basic tasks, such as recognizing input from the keyboard, sending output to
the display screen, keeping track of files and directories on the disk, and controlling
peripheral devices such as disk drives and printers.
• Ensure that different programs and users running at the same time do not interfere
with each other.
• Provide a software platform on top of which other programs liks application software
can run.
The first two responsibilities address the need for managing the computer hardware
and the application programs that use the hardware. The third responsibility focuses
on providing an interface between application software and hardware so that application
software can be efficiently developed. Since the operating system is already responsible
for managing the hardware, it should provide a programming interface for application
developers.
13