0% found this document useful (0 votes)
12 views

Programming I CH 1

The document provides an introduction to computer programming, including definitions of programming, programming languages, and the skills needed for programming. It discusses generations of programming languages from low-level machine languages to high-level languages. It also covers programming paradigms like procedural, structured, and object-oriented programming as well as problem solving processes and software engineering.

Uploaded by

y554bm55pd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Programming I CH 1

The document provides an introduction to computer programming, including definitions of programming, programming languages, and the skills needed for programming. It discusses generations of programming languages from low-level machine languages to high-level languages. It also covers programming paradigms like procedural, structured, and object-oriented programming as well as problem solving processes and software engineering.

Uploaded by

y554bm55pd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Chapter one

Introduction to Computer Programming


1.1. What is programming?
Programming is a skill that can be acquired by a computer professional that gives him/her the
knowledge of making the computer perform the required operation or task.
Why do we need to learn computer programming?
Computer programming is critical if one wants to know how to make the computer perform a
task. Most users of a computer only use the available applications on the computer. These
applications are produced by computer programmers. Thus, if someone is interested to make
such kind of applications, he/she needs to learn how to talk to the computer, which is learning
computer programming.
What is programming language?
Programming Language: is a different category of written symbols that instruct computer
hardware to perform specified operations required by the designer.
What skills do we need to be a programmer?
For someone to be a programmer, in addition to basic skills in computer, needs to have the
following major skills:
Programming Language Skill: knowing one or more programming language to talk to
the computer and instruct the machine to perform a task.
Problem Solving Skill: skills on how to solve real world problems and represent the
solution in understandable format.
Algorithm Development Skill: skill of coming up with sequence of simple and human
understandable set of instructions showing the step of solving the problem. Those set of
steps should not be dependent on any programming language or machine.
In every programming Language there are sets of rules that govern the symbols used in a
programming language. These set of rules determine how the programmer can make the
computer hardware to perform a specific operation. These sets of rules are called syntax.
1.2. Types of programming languages
Low-level languages: Languages that use instructions tied directly to one type of
computer
❖ machine language, assembly language
High-level languages: Instructions resemble written languages, such as English
❖ Can be run on a variety of computer types
❖ Visual Basic, C, C++, Java
➢ Machine language programs : only programs that can actually be used to operate a
computer
❖ Also referred to as object codes
❖ Consists of a sequence of instructions composed of binary numbers
❖ Contains two parts: an instruction and an address
➢ Assembly language programs: Substitute word-like symbols, such as ADD, SUB,
and MUL, for binary opcodes
❖ Use decimal numbers and labels for memory addresses
❖ One-to-one correspondence
• Usually, each line of assembly code produces one machine instruction
❖ Example: ADD 1, 2
❖ Assemblers: Translate programs into machine language
❖ One-to-many correspondence
➢ Each statement corresponds to several machine language instructions
➢ High-level languages programs
❖ Much easier to program than in assembly language.
❖ Data are referenced using descriptive names
❖ Operations can be described using familiar symbols
❖ Example:
cost = price + tax

1.3. Generation of programming language.


st nd rd th th
Programming languages are categorized into five generations: (1 , 2 , 3 , 4 and 5 generation
languages)
These programming languages can also be categorized into two broad categories: low level and
high level languages.
Low level languages are machine specific or dependent.
High level languages like COBOL, BASIC are machine independent and can run on
variety of computers.
From the five categories of programming languages, first and second generation languages are
low level languages and the rest are high level programming languages.
The higher the level of a language, the easier it is to understand and use by programmers.
Languages after the fourth generation are referred to as very high level languages.

1.3.1 First Generation (Machine languages, 1940’s):


Difficult to write applications with.
Dependent on machine languages of the specific computer being used.
Machine languages allow the programmer to interact directly with the hardware, and it
can be executed by the computer without the need for a translator.
Is more powerful in utilizing resources of the computer.
Gives power to the programmer.
They execute very quickly and use memory very efficiently.

1.3.2 Second Generation (Assembly languages, early 1950’s):


Uses symbolic names for operations and storage locations.
A system program called an assembler translates a program written in assembly language
to machine language.
Programs written in assembly language are not portable. i.e., different computer
architectures have their own machine and assembly languages.
They are highly used in system software development.

1.3.3 Third Generation (High level languages, 1950’s to 1970’s):


Uses English like instructions and mathematicians were able to define variables with
statements such as Z = A + B
Such languages are much easier to use than assembly language.
Programs written in high level languages need to be translated into machine language in
order to be executed.
The use of common words (reserved words) within instructions makes them easier to
learn.
All third generation programming languages are procedural languages.
In procedural languages, the programmer is expected to specify what is required and how
to perform it.

1.3.4 Fourth Generation (since late 1970’s):


Have a simple, English like syntax rules; commonly used to access databases.
Fourth generation languages are non-procedural languages.
The non-procedural method is easier to write, but you have less control over how each
task is actually performed.
In non-procedural languages, the programmer is not required to write traditional
programming logic. Programmers concentrate on defining the input and output rather
than the program steps required.

For example, a command, such as LIST, might display all the records in a file on
screen, separating fields with a blank space. In a procedural language, all the logic
for inputting each record, testing for end of file and formatting each column on
screen has to be explicitly programmed.

Fourth generation languages have a minimum number of syntax rules. This saves time
and free professional programmers for more complex tasks.

Some examples of 4GL are structured query languages (SQL), report generators,
application generators and graphics languages.

1.3.5 Fifth Generation (1990’s):


These are used in artificial intelligence (AI) and expert systems; also used for accessing
databases.
5GLs are “natural” languages whose instruction closely resembles human speech. E.g.
“get me Jone Brown’s sales figure for the 1997 financial year”.
5GLs require very powerful hardware and software because of the complexity involved
in interpreting commands in human language.
1.4. Programming paradigms
The major land marks in the programming world are the different kinds of features or properties
observed in the development of programming languages. Among these, the following are worth
mentioning: Procedural, Structured and Object Oriented Programming Paradigms.
Procedural Programming.
Procedural programming is a programming paradigm based upon the concept of procedure call.
Procedural programming is often a better choice than simple sequential programming in many
situations which involve moderate complexity or which require significant ease of
maintainability.
Possible benefits: the ability to re-use the same code (function or procedure) at different places,
an easier way to keep track of program flow than a collection of “GO TO” or “JUMP”
statements.
Structured Programming.
This is a process of writing a program in small, independent parts. This makes it easier to control
a program's development and to design and test its individual component parts.
Structured programs are built up from units called modules, which normally correspond to single
procedures or functions. This paradigm can be seen as a subset or sub discipline of procedural
programming. It is most famous for removing or reducing reliance on the GO TO statement.
Object-Oriented Programming.
The idea behind OOP is that, a computer program is composed of a collection of individual units,
or objects as opposed to traditional view in which a program is a list of instructions to the
computer.
Object-oriented programming is claimed to give more flexibility, easing changes to programs.
The OOP approach is often simpler to develop and maintain.

1.5. Problem solving processes and software engineering.


Software engineering is the profession that creates and maintains software applications by
applying technologies and practices from computer science, project management, engineering,
application domain and other fields.
The method used in solving problems in computer science and/or information systems is called
the software development life cycle.
The software development life cycle has the following components.
❖ preliminary investigation
❖ analysis
❖ design
❖ implementation
❖ testing and maintenance
Problem Solving
Problem solving is the process of transforming the description of a problem into the solution by
using our knowledge of the problem domain and by relying on our ability to select and use
appropriate problem-solving strategies, techniques, and tools.
A problem is an undesirable situation that prevents the organization from fully achieving its
purpose, goals and objectives. Or problem can also be defined as the gap between the existing
and the desired situation where problem solving will try to fill this gap.
There are two approaches of problem solving:
➢ Top down design: is a systematic approach based on the concept that the structure
of the problem should determine the structure of the solution and what should be
done in lower level. This approach will try to disintegrate a larger problem into
more smaller and manageable problems to narrow the problem domain.
➢ Bottom up design: is the reverse process where the lowest level component are
built first and the system builds up from the bottom until the whole process is
finally completed.

1.6. Algorithm design and modeling the logic using flowchart.


An algorithm is a finite set of well-defined instructions for accomplishing some task which,
given an initial state, will terminate in a corresponding recognizable end-state.
The algorithm should be:
❖ Precise and unambiguous
❖ Simple
❖ Correct
❖ Efficient
Algorithm could be designed using many techniques and tools. One tool of designing algorithm
is by using flowcharts.
Flowchart is a graphical way of expressing the steps needed to solve a problem (Or it is a
schematic (diagrammatic description) representation of a process).
Basic flowcharting symbols are:
Symbol Description

Terminal point

Input output

Process box

Decision

Flow line

Example: draw the flow chart for an algorithm that accepts a number from the user and checks if
that number is even or odd?
Start

Enter the
number

Num
True /2==0 False

Display Display
The number The
is even number is
odd

End

1.7. Compilers and interpreters


Any program written in any languages other than machine language need to be translated to
machine language. The set of instructions that do this task are known as translators. There are
different kinds of translator software, among these are compilers and interpreters.
1. Compilers: a compiler is a computer program that translates a series of statements
written in source code (a collection of statements in a specific programming language)
into a resulting object code (translated instructions of the statements in a programming
language). A compiler changes or translates the whole source code into executable
machine code (also called object code) which is output to a file for latter execution. E.g.
C++, Pascal, FORTRAN, etc.
2. Interpreters: is a computer program that translates a single high level statement and
executes it and then goes to the next high level language line etc.
E.g. BASIC, Lisp etc.
1.8. Mechanics of creating a program in C++.
C++ programs typically go through five phases to be executed: these are
❖ Edit: this is accomplished with an editor program. The programmer types C++
statements with the editor and makes corrections if necessary. The program’s source
file is then stored on secondary storage device such as a disk with a “.cpp” file name.
After the program is edited, C++ is principally compiled in three phases:
preprocessing, translation to object code, and linking (the last two phases are what
is generally thought of as the "compilation" process).
❖ Preprocess: In a C++ system, a preprocessor program executes automatically before
the compiler’s translation phase begins. The C++ preprocessor obeys command
called preprocessor directives, which indicate that certain manipulations are to be
performed on the program before compilation. The preprocessor is invoked by the
compiler before the program is converted to machine language. The C++
preprocessor goes over the program text and carries out the instructions specified by
the preprocessor directives (e.g., #include). The result is a modified program text
which no longer contains any directives.
❖ Compile: Then, the C++ compiler translates the program code. The compiler may be
a true C++ compiler which generates native (assembly or machine) code. The
outcome may be incomplete due to the program referring to library routines which
are not defined as a part of the program. For example, the << operator which is
actually defined in a separate IO library.
❖ Linking: C++ programs typically contain references to functions and data defined
elsewhere, such as in the standard libraries. The object code produced by the C++
compiler typically contains “holes” due to these missing parts. A linker links the
object code with the code for the missing function to produce an executable image
(with no missing pieces). Generally, the linker completes the object code by linking
it with the object code of any library modules that the program may have referred to.
The final result is an executable file
❖ Loading: the loader takes the executable file from disk and transfers into memory.
Additional components from shared libraries that support the program are also
loaded. Finally, the computer, under the control of its CPU, executes the program.

You might also like