Unit 3
Unit 3
Structure
3.0 Objectives
3.1 Introduction
3.6 Summary
3.8 Keywords
3.0 OBJECTIVES
In the previous Unit you have learnt about basics of computer software. In this Unit we
will discuss about programming and programming languages.
72
Programming
3.1 INTRODUCTION
A computer can neither think nor make decisions on its own. To solve a problem using
computers, a set of instructions should be given to the computer in a form which it can
understand. The process of writing these instructions is called programming.
The manual solution to this problem is to take out the dictionary and search pages for the
initial letter of the word. Once the word is found, search for the subsequent letters of the
word and on finding the word, read out its meaning given in the dictionary.
2) Match the words available in the dictionary one by one until the exact match is
found. (It is the simplest logic but we can apply more efficient logic)
Computers cannot understand natural languages such as English or Hindi for solving
problems. To communicate instructions and commands we need programming languages.
And learning programming languages requires learning the symbols, words and rules of
the language. There are many languages available to do programming. These are developed
for specific applications. Based on these applications, programs are of two types, system
programs and application programs.
System program: These are the programs which make computers available to use.
Operating Systems such as DOS and Windows which consist of many other programs
.for controlling input/output devices, memory, processor etc are system programs. The C
language is widely used to develop system software.
Application program: Application programs are designed for specific application such
as library automation, information retrieval, information processing, inventory control, etc.
These applications should be able to get input, produce output, do calculations, store and
retrieve data. There are many languages which contain instructions to support all these
operations. Before continuing with programming, we look at what algorithms and flow
charts are and how these helps in programming.
73
:::omputer Technology Self Check Exercise
1) What do you call a list of instructions for the computer to follow to process data?
Note: i) Write your answer in the space given below. <I
Flow chart has many symbols for basic operation in programming. The flow chart symbols
are:
i) Terminal
C_)
This is usually to represent terminal points in a program like BEGIN, END, START,
STOP.
ii) Input/Output
The parallelogram represents the Input/Output function, i.e., making the data available
for processing (input) or recording of the processed information (output). This step implies
obtaining a number from an input device (say, the keyboard and storing it in the storage
location named' A')
iii) Process
The rectangle represents the processing operation. A process changes or moves data.
An assignment is normally represented by this symbol.
----I~
•••••
f----
Lines or arrows represent the flow direction - the flow of control. Normally the flow
direction is from left to right or top to bottom. 75
Computer Technology v) Annotation
-------~_~I
A broken line .and rectangle as above represent the annotation function - the addition of
. descriptive comments or explanatory notes for clarification of some statements.
The diamond represents a decision or switching type of operations that determines which
of the alternative paths is to be followed. A decision indicates a question that can be
answered yes or no (or true or false).
vii) Connector
Circle is connector symbol which is used to represent functions in a flow line, i.e., the
part of flow chart which continues in the next or another page.
[1_D
The double sided rectangle represents a named process that consists of one or more
operations or programming steps that are specified elsewhere such as a module or
subroutine.
ii) Check your answer with the answers given at the end of this Unit.
76
Programming
3.3 PROGRAM DEVELOPMENT LIFE CYCLE
Programming is a six-step procedure for creating the list of instructions. Normally,
one would assume programming involves typing or keying in statements into a
computer. However, this is only one of the steps in program development. The six steps
are as follows:
Program objectives
We have learnt that programming involves solving problems. Therefore, at the outset, it is
essential to make a clear statement of the problem that you are tying to solve. An example
could be, "To develop a bibliographic database that can be searched by various fields".
Desired outputs
It is best always to specify outputs before inputs. The end result that is required from the
computer system should be noted down.
Input data
Once the output is known, the input data and the source data can be determined and
identified.
Processing requirements
In this step, the processing tasks that must happen for input data to be passed ou~ into
output is defined.
Now that outputs and inputs of the program are defined, a top-down program design can
be used to identify the program's processing steps. Such steps are called program modules
(or just modules). Each module is made up of logically related program statements.
Pseudocode is an outline of the logic of the program you will write. It is like doing a
summary of the program before it is written. Flow charts have already been discussed in
the previous section. Finally logic structure involves defining the sequence (one program
statement follows the other), selection (when a decision must be made) and loop (describes
a process that may be repeated as long as a certain condition remains true).
Debugging is a programmer's word for testing and then eliminating the errors. It means
running the program on a computer and then fixing the parts that do not work.
Programming errors are of two types, syntax errors and logic errors.
A syntax error is a violation of the rules of the programming language. For example, in
C++, each statement must end with a semicolon (;). If the semi-colon is omitted, the
program will not run due to a syntax error. A logic error occurs when the programmer
uses an incorrect calculation or leaves out a programming procedure. For example, a
payroll program that does not compute overtime hours would have logic error.
Several methods have been devised for finding and removing both syntax and logic errors.
These are:
• Manually testing with sample data: Using a calculator and sample data, a programmer
follows each program statement and performs every calculation. Looking for
programming logic errors, the programmer compares the manually calculated values
to the correct values.
• Testing sample data on the computer: After all syntax errors have been corrected,
the program is tested for logic errors. Sample data is used to test the correct execution
of each program statement.
• Testing by a select group of potential users: This is sometimes called beta testing.
It is usually the final step in testing a program. Potential users try out the program
and provide feedback.
Documentation consists of written descriptions and procedures about a program and how
to use it. It is not something done just at the end of the programming process. Program
documentation is carried on throughout all the programming steps. This documentation is
typically within the program itself and is in printed documents. In this step, all the prior'
documentation is reviewed and finalized. Documentation is important for users, operators
and programmer who may be involved with the program in the future.
The final step is program maintenance. The purpose of maintenance is to ensure that
current programs are operating error free, efficiently, and effectively. Activities in this
area fall into two categories: operations and changing needs.
3) What are the six steps in programming? What role does coding play in program
development?
ii) Check your answer with the answers given at the end of this unit.
The fundamental operation of these languages are storing and retrieving data values. For
example;
a=l
c=a+b
This statement retrieves 'a' and' b', adds and stores the result in 'c '. Some of the
procedural languages are discussed below.
FORTRAN
The name FORTRAN derives from FORmula TRANslation. The name itself indicates
that 'application of language with 'formula' of engineering-type application'. The first
commercial version of FORTRAN was released in 1957. This makes FORTRAN the
first high-level programming language. FORTRAN has some features ideally suitable for
problems that are heavily mathematical or computational oriented. High-level languages
are basically English like computer languages where we have 'higher' level of understanding
79
·.
Computer Technology as compared to Assembly and Machine languages. Programming languages like COBOL,
PASCAL, C, C++, BASIC etc also come under this category.
COBOL
The name COBOL derives from Common Business Oriented Language. COBOL
was designed to serve business needs such as managing inventories and payrolls. In such
applications summary reports are important output. Also data file handling is extensively
involved. Much of the business world concerns updating master files with change in
transaction files. For example master file contain names, manufacturers, and quantities
available for various items inventory; a transaction file would contain names, quantities
and items sold out of inventory over a period of time. The master file would be updated
from the transaction file on weekly or daily basis to reflect new quantities available and
print summary report.
PASCAL
The programming language Pascal was named after Blaise Pascal, the inventor of
Pascaline calculator.
The design of Pascal was to easily learn and enforce good programming techniques.
Pascal looks very similar to pseudocode. So it is easy to read and the syntax is easy to
learn. Even though Pascal is not much useful as commercial language, but programming
environment like Delphi uses Pascal language with a facility to develop windows based
applications with modem graphical user interface.
C
C was developed in early 1970s by Dennis Ritchie at AT&T Bell Laboratories. It was
originally developed for system programming, particularly for writing operating system
UNIX. It is a popular general-purpose language for two reasons. One is the relationship
with UNIX. Second reason is its efficiency that is, speed with which its operations can be
executed. The efficiency derives from the fact that C programs can make use of low-
level information such as knowledge of where data is stored in memory, yet has powerful
statements and portability to machines that high-level languages offer.
The strong feature of C is that it provides a data type called pointer. Variables of pointer
type contain memory addresses instead of integers, real numbers and characters. For
example the statement,
int* intPointer;
declares intPointer as a pointer variable that will contain the address of a memory location
containing integer data.
int A = 3;
intPointer = & A.
The first statement declares a variable called 'A' and assigns the value '3' to that. The
second statement makes the intPointer pointing to 'A'. We can also assign the integer
value '10' to variable 'A' by the statement
*intPointer = 10;
The powerful use of pointers are in the areas of writing system programming, operating
systems, assemblers, and programs that allows the computer to interact with input/output
devices and so on.
For example consider a problem of writing a device driver (software to interact with a
hardware device) for mouse on a PC. The port in which the mouse is connected reads
the changes in mouse position by voltage levels. It stores voltage levels in a fixed location
of memory. C provides facilities to access this memory and manipulate it.
Even though C is powerful for system programming it is widely used for general purpose
80 programming also.
ADA Programming
Ada development was for a common high-level language needed for various branches
of United States armed services for defense contracts. Ada is a large language like C++
and has been accepted not only in the defense industry, but also for other technical
applications and is a general-purpose language as well.
Ada is known for its multi-processing capability - the ability to allow multiple tasks to
execute independently and then synchronize the communication when directed.
The concept of Object-oriented programming is dividing the major task into sub tasks.
The program can be thought of a giant statement executor designed to carry out major
tasks, even though the main program may simply call the various modules that do the sub
task work.
JAVA
Java programming is associated with the World Wide Web. Java programs can access
data across the Web as easily as they access data from a local system. According to the
Sun Microsystems, Java is asimple, object oriented, distributed, interpreted, robust, secure,
architecture neutral, portable, high-performance, multithreaded and dynamic language.
Multithreading is the ability of an application to perform multiple tasks at the same time.
Multithreaded programs can be created through Java.
The procedural languages that we saw so far are more or less general-purpose
languages. There are several special purpsse languages designed for specialised
tasks. Here we take three representative special purpose languages which are very
popularly used.
SQL is designed to be used with databases, which are collections of related facts and
information. A database stores data centrally. The user of the database must be able to
add new data and to retrieve data already stored. For example, a database of library
catalogue may contain titles of book, its author's name, publisher name, year of publication,
etc. The database of catalogue user should be able to add information on a book and to
retrieve information on a book already in the database. In addition, databases can also be
queried with the user posing questions to the database. For example, the library catalogue
could be queried to reveal books by a particular author or by a publisher. Such queries
may be framed in SQL. SQL is the language used to frame database queries. Sample
SQL statement is as follows:
FROM CATALOGUE
Perl is designed to scan arbitrary text files, extract various kinds of information that is
contained within the text, and print reports based on the extracted information. The
language syntax is somewhat based on C. Perl uses sophisticated pattern matching
techniques to speed up the process of scanning large amounts of data for a particular text
string.
This is the language used to create HTML documents that, when viewed with Web
browser software, become Web pages. An HTML document consists of the text to be
displayed on the Web page, together with a number of special characters called tags that
achieve formatting, special effects, and references to other HTML documents. Tags are
enclosed in angle brackets (<» and often come in pairs. The end tag, the second tag in
the pair, looks like the begin tag, the first tag in the pair, but with an additional I in front.
<html>
<head>
</head>
<body> .
</body
<lhtml>
4) Write an SQL statement to display the books issued from the library for a member
named Amit.
ii) Check your answer with the answers given at the end of this unit.
82
Programming
3.5 GENERATIONS OF PROGRAMMING
LANGUAGES
Programming can be done in any language such as C, C++, COBOL, etc., which largely
depends according to need. But a computer executes programs only after they are
represented internally in binary form (sequences of Is and Os). Programs written in any
other language must be translated to the binary representation of the instructions before
they can be executed by the computer.
Just as hardware is classified into generations based on technology, computer languages
also have generations classification based on the level of interaction with the machine.
Since 1945 over the years, five categories or generations of programming languages
have evolved over the years which are as follows:
• First generation, 1945 - Machine language
• Second generation, mid 1950s - Assembly language
• Third generation, early 1960s - High level languages
• Fourth generation, early 1970s - Very high-level languages
• Fifth generation, early 1980s - Natural languages
Programs written for a computer may be in either one of the categories of languages.
For example, assume you need to display the details of a particular book (Introduction to
Computers) from the catalogue. In a procedural language, the programmer would have
to write a series of instructions in the following steps:
In a 4GL, however, the programmer would write a single instruction that says:
Majority of fourth generation languages are used to get information from files and databases
and display or print the information. These fourth generation languages contain a query
language which is used to answer queries or questions with data from a database.
Structured Query Language (SQL) is a standard language and universally used. Like
most other computer languages like C, C++, Pascal, or Java, you need a way to use it on
your computer.
Most database applications use the SQL, as their language to communicate with the
database, like add, delete, modify the data.
ii) Check your answer with the answers given at the end of this unit.
84
----------------------------
Programming
3.6 SUMMARY
In this Unit, we have dealt with programming and programming languages. The focuses
of attention in this Unit are the following:
• Steps in programming;
2) Algorithm consists of a set of explicit and unambiguous finite steps which, when
carried out for a given set of initial conditions, produce the corresponding output and
terminate in a finite time. A pictorial representation of the algorithm using standard
symbols is a flow chart.
3) The six steps in programming are (1) Program Specification, (2) Program Design,
(3) Program Code, (4) Program Test, (5) Program Documentation and (6) Program
Maintenance. Coding is one of the steps in programming that involves the actual
writing or keying in the set of instructions in a programming language.
3.8 KEYWORDS
Application program : Program that has been developed to solve a particular problem,
perform useful work on general-purpose tasks, or provide
entertainment
High level language : Also known as the procedural language it resembles human
languages such as English.
System program : Program that helps the computer to perform essential operating
tasks and enables the application program to run.
85
Computer Technology
3.9 REFERENCES AND FURTHER READING
Droomy, R.G. (2004). How to solve it by computer. New Delhi: Prentice Hall of India.