You are on page 1of 13

i

ii

Quick Contents:
Preface 1
Overview 2
What is a computer program? 2
Introduction to Computer Programming 4
Uses of Computer Programs 7
Computer Programmer 7
Algorithm 8
How a Program Works? 9
1

PREFACE

You may already have used software, perhaps for word


processing or spreadsheets, to solve problems. Perhaps
now you are curious to learn how programmers write
software.

A program is a set of step-by-step instructions that


directs the computer to do the tasks you want it to do
and produce the results you want.

Computer language programmers use to develop


software programs, scripts, or other sets of instructions for
computers to execute.

In this lesson, we'll be giving you a brief introduction


about computer programming and languages.

As computers have evolved, many different


computer programming languages created for
various types of development. How many
programming languages are there? There are
hundreds! Can you name a few?
2

Computer Programming

Overview
Before getting into computer programming, let us first understand
computer programs and what they do.

WHAT IS A COMPUTER PROGRAM?


A computer program is a sequence of instructions written using a Computer
Programming Language to perform a specified task by the computer.
The two important terms that we have used in the above definition are:
 Sequence of instructions
 Computer Programming Language

To understand these terms, consider a situation when someone asks you


about how to go to a nearby restaurant. What exactly do you do to tell him
the way to go to restaurant?

You will use Human Language to tell the way to go to that restaurant,
something as follows:

First go straight, after half kilometer, take left from


the red light and then drive around one kilometer and
you will find the restaurant at the right.
3

Here, you have used English Language to give several steps to be taken to
reach the restaurant. If they are followed in the following sequence, then
you will reach the restaurant:
1. Go straight
2. Drive half kilometer
3. Take left
4. Drive around one kilometer
5. Search for restaurant your right side

Now, try to map the situation with a computer program. The above
sequence of instructions is actually a Human Program written in English
Language, which instructs on how to reach a restaurant from a given
starting point. This same sequence could have been given in Spanish, Hindi,
Arabic, or any other human language, provided the person seeking
direction knows any of these languages.

Now, let's go back and try to understand a computer program, which is a


sequence of instructions written in a Computer Language to perform a
specified task by the computer. Following is a simple program written in
Python programming Language:

print "Hello, World!"

The above computer program instructs the computer to print "Hello,


World!" on the computer screen.
4

 A computer program is also called a computer software, which can


range from two lines to millions of lines of instructions.

 Computer program instructions are also called program source code


and computer programming is also called program coding.

 A computer without a computer program is just a dump box; it is


programs that make computers active.

As we have developed so many languages to communicate among


ourselves, computer scientists have developed several computer-
programming languages to provide instructions to the computer (i.e., to
write computer programs). We will see several computer programming
languages in the subsequent lesson.

Introduction to Computer Programming


If you understood what a computer program is, then we will say: the act of
writing computer programs is called computer programming.

Levels of Language
Programming languages are said to be "lower" or "higher," depending on
how close they are to the language the computer itself uses (Os and 1s =
low) or to the language people use (more English-like-high). We will
consider five levels of language. They are numbered 1 through 5 to
correspond to levels, or generations. In terms of ease of use and
capabilities, each generation is an improvement over its predecessors.
5

The five generations of languages are:


1. Machine language
2. Assembly languages
3. High-level languages
4. Very high-level languages
5. Natural languages

As we mentioned earlier, there are hundreds of programming


languages, which can be used to write computer programs and following
are a few of them:

Table 1. Programming Languages


Language Description
Ada Ada was created in the 1970s, primarily for
applications used by the U.S. Department
of Defense. The language is named in
honor of Countess Ada Lovelace, an
influential and historic figure in the field of
computing.
BASIC Beginners All-purpose Symbolic Instruction
Code is a general-purpose language that
was originally designed in the early 1960s
to be simple enough for beginners to learn.
Today, there are many different versions of
BASIC.
FORTRAN FORmula TRANslator was the first high-
level programming language. It was
6

designed in the 1950s for performing


complex mathematical calculations.
COBOL Common Business-Oriented Language was
created in the 1950s, and was designed for
business applications.
Pascal Pascal was created in 1970, and was
originally designed for teaching
programming. The language was named in
honor of the mathematician, physicist, and
philosopher Blaise Pascal.
C and C++ C and C++ (pronounced “c plus plus”) are
powerful, general-purpose languages
developed at Bell Laboratories. The C
language was created in 1972 and the C++
language was created in 1983.
C# Pronounced “c sharp.” This language was
created by Microsoft around the year 2000
for developing applications based on the
Microsoft .NET platform.
Java Java was created by Sun Microsystems in
the early 1990s. It can be used to develop
programs that run on a single computer or
over the Internet from a web server.
JavaScript JavaScript, created in the 1990s, can be
used in web pages. Despite its name,
JavaScript is not related to Java.
Python Python, the language we use in this book,
is a general-purpose language created in
the early 1990s. It has become popular in
business and academic applications.
Ruby Ruby is a general-purpose language that
was created in the 1990s. It is increasingly
7

becoming a popular language for programs


that run on web servers.
Visual Basic Visual Basic (commonly known as VB) is a
Microsoft programming language and
software development environment that
allows programmers to create Windows
based applications quickly. VB was
originally created in the early 1990s.

USES OF COMPUTER PROGRAMS

Today computer programs are being used in almost every field, household,
agriculture, medical, entertainment, defense, communication, etc. Listed
below are a few applications of computer programs:

 MS Word, MS Excel, Adobe Photoshop, computer games etc., are


examples of computer programs.
 Computer programs are being used to develop graphics and special
effects in movie making.
 Computer programs are being used to perform Ultrasounds, X-Rays,
and other medical examinations.
 Programs are being used in our mobile phones for SMS, Chat, and
voice communication.

COMPUTER PROGRAMMER
Someone who can write computer programs or in other words, someone
who can do computer programming is called a Computer Programmer.
Based on computer programming language expertise, we can name a
computer programmer as follows:
8

 C Programmer
 C++ Programmer
 Java Programmer
 Python Programmer
 Pascal Programmer
 Java Programmer
 Ruby Programmer

ALGORITHM
From programming point of view, an algorithm is a step-by-step procedure
to resolve any problem. An algorithm is an effective method expressed as
a finite set of well-defined instructions.

Thus, a computer programmer lists down all the steps required to


resolve a problem before writing the actual code. Below is a simple
example of an algorithm to find out the largest number from a given list of
numbers:

1. Get a list of numbers L1, L2, L3....LN


2. Assume L1 is the largest, Largest = L1
3. Take next number Li from the list and do the
following
4. If Largest is less than Li
5. Largest = Li
6. If Li is last number from the list then
7. Print value stored in Largest and come out
8. Else repeat same process starting from step 3

Example of simple algorithm


9

The algorithm has been written in a crude way to help beginners


understand the concept. You will come across more standardized ways of
writing computer algorithms as you move on to advanced levels of
computer programming.

HOW A PROGRAM WORKS


A computer’s CPU can only understand instructions that are written in
machine language. Because people find it very difficult to write entire
programs in machine language, other programming languages have been
invented.

CPU is the most important component in a computer because it is the part


of the computer that runs programs. Sometimes the CPU is called the
“computer’s brain,” and is described as being “smart.”
The CPU is an electronic device that is designed to do specific things. In
particular, the CPU is designed to perform operations such as the
following:
 Reading a piece of data from main memory
 Adding two numbers
 Subtracting one number from another number
 Multiplying two numbers
 Dividing one number by another number
 Moving a piece of data from one memory location to another
 Determining whether one value is equal to another value
10

As you can see from this list, the CPU performs simple operations on
pieces of data. The CPU does nothing on its own, however. It has to be told
what to do, and that’s the purpose of a program. A program is nothing
more than a list of instructions that cause the CPU to perform operations.
Each instruction in a program is a command that tells the CPU to perform
a specific operation. Here’s an example of an instruction that might appear
in a program:
10110000

To you and me, this is only a series of 0s and 1s. To a CPU, however, this is
an instruction to perform an operation. It is written in 0s and 1s because
CPUs only understand instructions that are written in machine language,
and machine language instructions always have an underlying binary
structure.

A machine language instruction exists for each operation that a CPU is


capable of performing. For example, there is an instruction for adding
numbers, there is an instruction for subtracting one number from another,
and so forth. The entire set of instructions that a CPU can execute is known
as the CPU’s instruction set.
NOTE: There are several microprocessor companies today that manufacture
CPUs. Some of the more well-known microprocessor companies are Intel and
AMD. If you look carefully at your computer, you might find a tag showing
a logo for its microprocessor.
Each brand of microprocessor has its own unique instruction set, which is
typically understood only by microprocessors of the same brand. For
example, Intel microprocessors understand the same instructions, but they
do not understand instructions for AMD microprocessors.
11

Figure 1. The fetch-decode-execute cycle

When a CPU executes the instructions in a program, it is engaged in a


process that is known as the fetch-decode-execute cycle. This cycle, which
consists of three steps, is repeated for each instruction in the program. The
steps are:

1. Fetch A program is a long sequence of machine language


instructions. The first step of the cycle is to fetch, or
read, the next instruction from memory into the CPU.
2. Decode A machine language instruction is a binary number
that represents a command that tells the CPU to perform
an operation. In this step the CPU decodes the instruction
that was just fetched from memory, to determine which
operation it should perform.
3. Execute The last step in the cycle is to execute, or perform, the
operation.

You might also like