0% found this document useful (0 votes)
11 views11 pages

Programming Computer

Intro an step by step guide to computer programming

Uploaded by

zohla12osano
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)
11 views11 pages

Programming Computer

Intro an step by step guide to computer programming

Uploaded by

zohla12osano
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/ 11

ELEMENTARY PROGRAMMING PRINCIPLES

Chapter outline

3.1 Introduction
3.2 Computer programming
3.3 Description of terms used in programming
3.4 Levels of programming languages
3.5 Advantages and disadvantages of low level and high-level languages

Introduction
Human beings have evolved from the Stone Age to a highly sophisticated and advanced society
by inventing things like the wheel, fire, transistors and today's ultra modem devices like computers.
The idea of computers started way back in the nineteenth century.
The first generation computers called Electronic Numeric integrator and Calculator (ENIAC 1)
were operated by plugging wires into a control panel that resembles the old telephone switchboards
Computer programming
A computer works by executing a set of instructions known as a program. The term programming
refers to the process of developing computer instructions (programs) used to solve a particular
task. It involves use of special characters, signs and symbols found in a particular programming
language to create computer instructions. A programming language is a special setof symbols that
can be translated into machine-readable form by the computer when arranged in a particular
sequence or order. Each language has a special sequence or order of writing characters usually
referred to as syntax.
It was John von Neumann of Princeton University (USA) who first came up with the proposition
to store programs in the computer memory. Perhaps, this was one of the most dramatic
developments in the computer history. Why? Because not only did the new stored-program way
of computing increase-processing speed but also allowed easy and flexible methods of editing and
updating the program.

Description of terms used in programming


Before we go further with programming, it is important to define some common terms used in
computer programming.

Source program
The term source program refers to the program code that the programmer enters in the program
editor window that is not yet translated into machine-readable form. The source program is usually
created using a particular programming language as discussed later.

Object code
The term object code refers to the program code that is in machine-readable. A source code that
is not in machine-readable form must be translated into object code.

Translators
The term translator is used to refer to language processors such as assemblers, interpreters and
compilers that convert the source program into object code.

Assembler
An assembler translates assembly language into machine language that the computer can
understand and execute.

Interpreter
An interpreter translates the source program line-by-line, allowing the CPU to execute one line
before translating the next. The translated line is not stored in the computer memory. It means that
every time the program is needed for execution, it has to be translated. This method of translating
programs was very common in early computers that did not have enough memory to store the
object code as a file that can be executed later

Compiler
A compiler translates the entire source program into object code: The object code file can be made
into a fully executable program by carrying out another process known as linking which joins the
object code to all the other files that are needed for the execution of the program. After the linking
process, an executable file (application file) is generated. This file is stored on a storage media
such as a disk with a name that has a unique extension (.EXE). Examples of executable files are
WINWORD.EXE and PM70.EXE used to start Microsoft Word and Adobe PageMaker 7.0
respectively.

The difference between the interpreters and compilers are summarised below:

Interpreters Compilers
1. Translates the source program 1. Translates the entire source
one statement at a time code
at once before execution
2. Translates the program each 2. Compiled program (object
Time it is run hence slower than code) can be saved on a storage
Compiling media and run as required, hence
Executes faster than interpreted
Programs.
3. Interpreted object code takes 3. Compiled programs require
Less memory compared to More memory as the object file
Compiled program. Are larger.

Levels of programming languages


Many programming languages have been developed over the years. These languages are
classified into two major levels namely:
1. Low-level languages
2. High-level languages

These levels are further subdivided into five generations. The first and second generations
consist of low-level languages while the third to the fifth generation consist of high-level
languages.

Low-Level languages
Low-level languages are classified as low because the computer can easily understand them
directly or they require little effort to translate into computer understandable form. These
languages are hardware oriented and therefore they are not portable i.e. a program written for
one computer cannot be installed and used on another. Two types of low level languages are the
machine languages and assembly languages.

Machine languages (First generation languages)


In machine languages, instructions are written using binary logic. Given that data and instructions
are in binary form, many lines of code are needed to accomplish even a simple task like adding
two numbers. A program written in machine language might look like this:
It is evident from the above code that it is hard for a person to guess what the program is all
about unless they have special knowledge in machine level programming. Furthermore, different
CPU's have different machine codes e.g. those for the Intel Pentium processors may differ from
Motorola or Cyrix processors. Therefore before decoding the meaning, a programmer has to know
for which CPU the program was written. Obviously, such programs are hard to understand from
the programmer's point of view, but very easy to execute from the computer's perspective.

Assembly languages (Second generation languages)


Assembly languages were developed in order to overcome the difficulties of understanding and
using machine languages. These languages represented the first successful attempt to make
computer languages readable. The languages allowed programmers to write programs as a set of
symbolic operation codes called mnemonics. Mnemonics are basically shortened two or three
letter words. Programs written in assembly language require an assembler in order to convert
them into machine language that the computer can understand. Just like the machine languages,
assembly languages are also machine dependent and therefore a program written for one
computer cannot be used on another.
High-level languages
High-level languages are very close to the human language (English like) and they can be read and
understood even by people who are not experts in programming. There are many types of high-
level languages and each of them was developed to address a particular problem-solving domain
while others came about due to advancement in technology. These languages are machine
independent. This means that a programmer concentrates on problem solving during a
programming session rather than how a machine operates.
High-level languages can be classified into five groups:
1. Third generation languages. (3 GLs)
2. Fourth generation languages. (4 GLs)
3. Fifth generation languages. (5 GLs)
4. Object oriented languages. (OOPs)
5. Web scripting languages.

Third generation languages (3 GLs)


Third generation languages (3 GLs) are also called structured or procedural languages. A
procedural language makes it possible to break a program into components called modules each
performing a particular task. This is referred to as structured programming. The structured
programming approach emphasizes the following:
1. Large programs can be broken down into smaller sub programs each performing a single task.
2. Use of a few simple control structures in problem solving. These control structures include
sequence, selection and iteration as covered later in this book.
Structured programming offers many benefits because it is flexible, easier to read and modify.
Examples of third generation programming languages include:
Pascal: Pascal was initially developed as an academic language, to help in the teaching and
learning of structured programming.
FORTRAN: (FORmula TRANslator): This language was developed for mathematicians,
scientists and engineers. It enables writing of programs with mathematical expressions.
COBOL: (Common Business Oriented Language): This language is designed for developing
programs that solve business problems e.g. developing data processing applications such as
computer-based inventory control systems.
BASIC: (Beginners All-purpose Symbolic Instructional Code): This language was mainly
developed to enable students to easily learn programming. Basic is a simple general-purpose
language used for developing business and educational applications. Because of its simplicity, it
is a powerful tool for students who wish to learn programming. It was the first high-level
language that was available for microcomputer users.
C: This is a programming language mainly used for developing system software such as the
operating system. It is one of the most popular and powerful high-level languages in the business
world because of its ability to provide the programmer with powerful features of low-level
languages and at the same time easily understandable as a high level language.
Ada: This language was named after the first lady programmer, Ada Lovelace. Ada is suitable
for developing military, industrial and real time systems. .
A sample program written in Pascal language
Imagine the task of developing a program that would solve the equation of a straight line given
by the algebraic expression:
Y = MX + C.
To enter the program code below in Pascal, proceed as follows:
1. From Windows explorer, locate a folder called TP and open it.
2. From the TP folder select BIN
3. From BIN window, double click a file named turbo.EXE. Pascal program window is displayed
on the screen.
4. Enter the program code exactly as it is but ignore the numbering.
1. Program Straight Line (Input, Output);
2. Var
3. y, m, x, c: Integer;
4. Begin
5. Writeln ('Input the value of m');
6. Readln (m);
7. Writeln ('Input the value of x');
8. readln (x);
9. Writeln ('Input the value of c ');
10. Readln (c);
11. Y: = m * x + c;
12. Writeln (The value of y is:’, y);
13. End.
Fourth generation languages (4 GLs)
Fourth generation languages make programming an even easier task that the third generation
languages because they present the programmer with more programming tools. Examples of such
tools include command buttons, forms etc. With the advent of these languages, gone are the days
when a person had to write lines upon lines of code. Instead, the programmer selects graphical
objects on the screen called controls then uses them to create designs on a base form. The
programmer may also use an application generator that works behind the scenes to generate the
necessary code; hence the programmer is freed from the tedious work of writing the code.
Examples of fourth generation languages are: Visual Basic, Delphi Pascal and Visual COBOL.

A sample form designed using Visual basic programming language


The programmer in this case simply picks a tool from the toolbox and uses it to create objects such
as command buttons, textboxes etc. on the form by dragging the mouse pointer on the form during
design.
Fifth generation languages (5 GLs)
Fifth generation languages are designed around the concept of solving problems by enabling the
computer to depict human like intelligence. These programs are designed to make the computer
solve the problem for the programmer rather than the programmer spending a lot of time to come
up with the solution. With such languages, the programmer only worries about what problem needs
to be solved and what conditions need to be met without worrying about how to implement an
algorithm to solve them. Examples of these languages are those used in artificial intelligence like
PROLOG, Mercury, LISP and OCCAM.

Object-oriented programming languages (OOP)


The idea behind object-oriented programming (OOP) was developed in the 1960's but its
significance was not appreciated until lately. The concept behind object oriented programming
languages is to look at a program as having various objects interacting to make up a whole. Each
object has specific data values that are unique to it (called state) and a set of the things it can
accomplish called (functions or behavior). This process of having data and functions that operate

on the data within an object is called encapsulation. Several objects can then be linked together to
form a complete program. Examples of object-oriented languages include Simula, which was
developed in the 1960's. However, C++, Java and SmallTalk are contemporary languages in this
range. Although Java is sometimes associated with development of web sites it can be used to
create whole application programs that do not need a web browser to run. OOP has contributed
greatly to the development of graphical user interface operating systems and application
programs.
I
Web Scripting languages!
Web scripting languages are used to develop or add functionalities on web pages. Web pages are
hypertext documents created in a language called Hypertext Markup Language (HTML). The
language simply consists of tags that are interpreted by the web browser software to display text
when the HTML file is opened on the screen by a web browser software. A tag is a special word
enclosed between the less than and greater than (<>) symbols and the browser can interpret it as
a command. For example, to start a HTML page, one must use the <HTML> tag at the very top of
the document. Other languages like Extended HTML (XML) have been derived directly from
HTML with the only difference being that XML allows the user to define their own tags instead
of using the standard HTML tags.
Unlike other programming languages, HTML does not have the declaration part and control
structures (to be covered later in the book). Due of this reason, it is not considered as a true
programming language.
Due to its simplicity, HTML has many limitations and cannot be used alone when it comes to
developing functional websites. Some special blocks of code known as scripts may be inserted in
HTML pages using scripting languages like JavaScript, VBScript and Hypertext Preprocessor
(PHP) in order to add functionality to the HTML page. A script is a small program fragment,
written in a different language other than HTML but inserted into the HTML program.
Most HTML tags have an opening tag and a closing tag. An opening tag is enclosed between < >
while a closing one between </ >. Text that is to be displayed on the screen is enclosed between
an opening and closing tag. For example, the statement <B> Hello </B> will display the word
"Hello" in boldface on the screen. Table 3.1 shows examples of HTML tags and their meanings:

1
Table 3.1
Tag Meaning
1. <HTML></HTML> Marks the beginning and end of a HTML
document. All other tags and text fall
between these two tags.
2. <HEAD> </HEAD> Marks the header part of the document.
3. <TITLE> </TITLE> Gives title of the web page. Text between
this tags appears in the title bar when the
page is browsed.
4. <BODY></BODY> Marks the body part of the document.
5. <CENTER></CENTER> Centres text and objects on the web page.
6. <B></B> Bolds the text on the web page.
7. <1></1> Italicise the text.
8. <Hl></Hl> Sets size of text on the web page with H6
displaying the smallest and H1 the largest
Size.

Creating a script using Javascript


Javascript is a popular scripting language. Before writing your HTML program with a script
inserted, make sure that you have the latest browser software installed on your computer. Older
browsers may not have support for Javascript. If you are using Internet Explorer, it should be
version 5.0 and above.
Open Notepad and key in the following program. Do not write the numbers to the left of each line
of code.
1. <HTML>
2. <HEAD>
3. < TITLE> Scripting Example </TITLE>
4. </HEAD>
5. <BODY>
6. <HI> < CENTER. <B> We are the world </B> </CENTER> </HI>
7. <SCRIPT LANGUAGE = 'JavaScript'>
8. Document. Write ('My name is strongman');
9. alert ('congratulations for succeeding to run this script');
10. </SCRIPT>
11. </BODY></HTML>

Advantages and disadvantages of low-level and high-level languages


Having looked at the various programming languages, it is important to identify the advantages
and disadvantages associated with each level of programming languages.
Advantages and disadvantages of low level languages
Advantages
1. The CPU understands machine language directly without translation.
2. The processor executes them faster because complex instructions are already broken down
into smaller simpler ones.
3. Low level languages are stable and hardly crash or break down once written.
Disadvantages
1. Low level languages are difficult and cumbersome to use and learn.
2. They require highly trained experts both to develop and maintain programs.
3. Removing errors (debugging) in low level language programs is difficult.
4. Low level programs are machine dependent i.e. they are not transferable from one hardware or
software platform to another.

Hence we say they are not portable.


Advantages and disadvantages of high level languages
Advantages
1. High level languages are portable i.e. they are transferable from one computer to another.
2. High level languages are user friendly and easy to use and learn.
3. High level languages are more flexible; hence they enhance the creativity of the programmer
and increase productivity in the workplace.
4. High level languages are far much easier to correct errors (debug).

Disadvantages
1. Their nature encourages use of many instructions in a word or statement hence the complexity
of these instructions causes slower program processing.
2. They have to be interpreted or compiled to machine readable form before the computer can
execute them.
(Review questions 3.1)
1. Define the term computer program.
2. What is programming?
3. State three advantages of high level languages over low level, languages.
4. List four examples of high level languages and for each state its most appropriate application
area.
5. Why is an executable file unique as compared to any other file?
6. Differentiate between a compiler and an interpreter. Why did early computers work well with
interpreters?
7. List the various examples of programming languages per generation.
8. State one advantage of machine language over all the other languages.
9. Write the following in full:
(a) HTML (b) OOP
10. Distinguish between source program and object code in programming.
Define the term encapsulation as used in object oriented programming

You might also like