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

Programming Fundamentals

The document outlines the fundamentals of programming, including definitions of key terms such as computer programs, programming languages, source code, and object code. It discusses the differences between low-level and high-level languages, their advantages and disadvantages, and the evolution of programming languages through various generations. Additionally, it covers the program development process, emphasizing the importance of algorithm design and the steps involved in writing and testing a program.

Uploaded by

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

Programming Fundamentals

The document outlines the fundamentals of programming, including definitions of key terms such as computer programs, programming languages, source code, and object code. It discusses the differences between low-level and high-level languages, their advantages and disadvantages, and the evolution of programming languages through various generations. Additionally, it covers the program development process, emphasizing the importance of algorithm design and the steps involved in writing and testing a program.

Uploaded by

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

PROGRAMMING FUNDAMENTALS

• To process any type of data, computer follows a set of well-designed


instructions known as a program.
• Like in construction industry, creating a good program requires the
programmer to provide design of the program.
• In construction a design is known as a plan or blue print, in
programming, a program design is known as algorithm.
• The process of designing a program is referred to as algorithm design.
• Algorithm design is both science and an art because scientific
approach and creative thinking is required to come up with a good
design.
DEFINITION OF TERMS USED IN
PROGRAMMING
1. COMPUTER PROGRAM
• Is a set of instructions written in programming language to instruct a
computer to perform a task.
• A program is like recipe.
• It contains a list of ingredients referred to as variables and list of
instructions that instructs a computer what to do.
2. PROGRAMMING LANGUAGES
• Is a formal language that specifies the syntax and semantic rules for
writing computer programs.
2. PROGRAMMING LANGUAGES

• Examples of programming languages include;


a) BASIC
b) C
c) C++
d) Java
e) Pascal
f) FORTRAN
g) COBOL e.tc.
3. COMPUTER PROGRAMMING
• Computer programming is the process of writing a computer program
using a programming language.
• The person who writes the programs is referred to as a programmer.
• Other terms used to refer to a programmer at higher levels are software
developer and software engineer.
4. SOURCE CODE
• Refers to set of instructions or statements written by a programmer
that are not yet converted into machine-readable form.
• A source code is mostly a text written using programming language like
BASIC, Pascal, C or C++.
5. OBJECT CODE
• Once a source code is written, it can be converted into machine
readable form referred to as object code.
• To convert source code to object code, language processors such as
assemblers, interpreters and compilers are used.
ASSEMBLER
• An assembler converts assembly language program into machine
readable form that a computer can understand and execute.
INTERPRETER
It converts the source code into machine code statement-by-statement
allowing the CPU to execute one line at a time.
COMPILER
• Converts the entire source code into object code.
• The object code can be made into executable file by carrying out
another process known as linking which combines the object code
with library files that are required for the execution of the program.
• After the linking process an executable file (application file) is
generated.
• In windows, the file may be stored on a storage media such as a disk
with a name and .exe extension such as hello.exe.
HOW A COMPILER TRANSLATES A
SOURCE CODE FILE INTO
EXECUTABLE OBJECT FILE.
DIFFERENCES BETWEEN
INTERPRETERS AND COMPILERS
HISTORY OF PROGRAMMING
LANGUAGES
• These are classified to two broad categories;
1. Low level languages
2. High level languages
These categories can be subdivided into five generations.
The low level languages consists of first generation and second
generation languages while the high level has third generation and fifth
generation languages
LOW LEVEL LANGUAGES
• Are classified as low because they can easily be understood by
computer since they require minimal effort to convert into computer
object code.
• Low level languages are hardware oriented hence they are not
portable i.e. a program written for one computer cannot be installed
on another computer.
• Two types of low level languages are
a. Machine language
b. Assembly language
MACHINE LANGUAGE (first
generation language)
• In machine language, instructions are written using binary code.
• A program written in machine language might look like the one shown
below;

• It is evident from above code that it is hard for a person to understand


what the program is all about unless they have knowledge in machine
level programming.
MACHINE LANGUAGE (first
generation language) Cont..
• Different CPU’s understand different machine languages e.g. the code
for the Intel Pentium processors may differ from Motorola
processors.
• Therefore, before writing machine code, a programmer has to know
for which CPU the program is written.
• Such programs are hard to write and debug from the programmers
point of view, but very easy to execute from the computer’s
perspective.
ASSEMBLY LANGUAGES (Second
generation languages)
• Assembly language was developed in order to overcome the
difficulties of understanding and using machine languages.
• 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
• A program written in assembly language may look like one shown
below.
ASSEMBLY LANGUAGES (Second
generation languages) Cont…
• The first line in the code means move 15 into the processor register
with the name AX.
• The second line instructs the computer to subtract 10 from the value
in register AX.
• Programs written in assembly languages require an assembler to
convert them into machine codes that the computer can understand.
• Like machine language, assembly languages are also machine
dependent and therefore a program written for one computer cannot
be used on another.
ADVANTAGES OF LOW LEVEL
LANGUAGES
• The CPU understands machine language directly with minimal or no
conversion
• The processor executes low level programs written is faster because
complex instructions are already broken down into smaller simpler
ones.
• Low level languages are stable and hardly crash or break down once
written.
DISADVANTAGES OF LOW LEVEL
LANGUAGES
• Are difficult and cumbersome to use and learn.
• Require highly trained programmers both to develop and maintain
programs written in low level languages.
• Correcting errors (debugging) is difficult.
• Programs are not portable from one computer to another.
HIGH LEVEL LANGUAGES
• Are close to the human language hence they can be read and
understood even by people who are not experts in programming.
• High level languages are machine independent meaning that a
programmer concentrates on problem solving a particular problem
instead of understanding the architecture of the machine.
FIVE CATEGORIES OF HIGH LEVEL
LANGUAGES
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)
• Are also called structured or procedural languages.
• A procedural language makes it possible to break down a program
into components called modules, each performing a particular task
• The process of breaking down a program into modules or sub-
program is referred to as structured programming.
• Structured programming approach emphasizes the following;
1. Large programs should be broken down into smaller sub programs
each performing a single task.
2. Use control structures in problem solving
THIRD GENERATION LANGUAGES (3
GLS) Cont..
• Structured programming offers many benefits because it is flexible,
easier to read and modify.
COMMON EXAMPLES OF THIRD
GENERATION PROGRAMMING
LANGUAGES
1. PASCAL
was initially developed as procedural language to help in the teaching and
learning of structured programming
2. FORTRAN (FORmula TRANslator)
was developed for mathematicians, scientists and engineers.
it enables writing programs that solve scientific, mathematics and engineering
problems.
3. COBOL (Common Business-Oriented Language)
is designed for developing programs that solve business problems such as
computer-based inventory control systems
COMMON EXAMPLES OF THIRD
GENERATION PROGRAMMING
LANGUAGES Cont…
• BASIC (beginners All-purpose Symbolic Instructional Code)
Was developed to enable students easily learn programming.
Basic is a simple general purpose language used for developing business and
educational applications.
•C
 This is a programming language used for developing system software such as
the operating systems.
It is one of the most popular and powerful high level programming language
because of its ability to provide programmers with powerful features of low
level languages and at the same time easily understandable as a high level
language.
COMMON EXAMPLES OF THIRD
GENERATION PROGRAMMING
LANGUAGES Cont…
• Ada
 This language was named after the first lady programmer, Ada
Lovelace.
Ada is suitable for developing military, industrial and real-time
systems.
SAMPLE 3GLs PROGRAM
• In 3GLs programming languages, a simple source code known as
“hello World” may be used to introduce beginners into structured
programming.
• Figure below is a sample Hello World program written in Pascal
SAMPLE 3GLs PROGRAM Cont…
• Line 1
 the first line enclosed in a combination of parenthesis and asterisk is
known as Comment.
Use of comments is a good practice because it explains the purpose
of program or statement to other programmers.
• Line 2
 the second line is known as program header.
A Pascal program must start with the keyword “program” followed by
the name of the program, in this case Hello World.
SAMPLE 3GLs PROGRAM Cont…
 the word output in the parenthesis is known as parameter and
indicates that the program displays the output on the screen.
• Line 3
 the keyword Begin in the third line denotes the start of the executable
statements.
This where we define the structure of the program using input,
processing and output statements.
• Line 4
 Writeln (‘Hello World’) is the most important statement in this
program.
SAMPLE 3GLs PROGRAM Cont…
 once the program is executed, writeln is a Pascal output function for
instructing the computer to display Hello World! On the screen.
Note: the word Writeln is a short form of write line.
In programming, write means output while read means input.
Therefore, a statement that takes input in Pascal uses Readln (value)
• Line 5
 the last statement “End”.
Marks the end of the program.
Once the computer encounters the End (with period), the program is
terminated and unloaded from main memory.
FOURTH GENERATION LANGUAGE (4
GLs)
• Were improved on 3gls to reduce programming effort by making the
programmer focus more on the problem than algorithm or structure of
the program.
• 4GLs have advanced programming tools for integrating programs with
databases, generating reports and creating an graphical user interface
(GUI) applications.
• The programmer may also use an application generator that
automatically generates program code hence relieving the programmer
from tedious work of writing every line of code.
• Examples of 4GLs; Power Builder, FoxPro, Python, Progress 4GL,
Microsoft Visual Basic and Delphi Pascal.
SAMPLE 4 GLs PROGRAM
• The same Hello World program demonstrated using Pascal can be
rewritten using a 4GL.
• Figure below is Hello World program in Microsoft Visual Basic
SAMPLE 4 GLs PROGRAM
• This program in visual Basic 2010 is similar to one demonstrated using
Pascal except for syntax difference.
• Line 1
 the first line starts with apostrophe denotes a comment in Visual
Basic.
• Line 2
 the module header is equivalent to program header in Pascal.
Each module must be accompanied by a unique name
SAMPLE 4 GLs PROGRAM Cont…
• Line 3
 Subpoint Main is known as the Main method or subroutine hence the
word sub before Main ( ).
 it marks the start or entry point to executable statements.
• Line 4
 console. Writeln(‘Hello World’) statement is similar to writeln used in
Pascal.
The term console means screen.
Therefore, once the program is executed, writeln instructs the computer
to display HelloWorld! On the screen.
SAMPLE 4 GLs PROGRAM Cont…
• Line 5
 console.Readkey() function is similar to readln used in Pascal.
In this program it is used to pause the sreen displaying Hello World
until the user presses any key.
• Line 6
 End Sub marks the end of main method.
Once the user presses any key and the End Sub and End Module are
encountered, the program returns control to the operating system to
unload the program from memory.
FIFTH GENERATION LANGUAGES (5
GLs)
• Are also known as natural languages and are used to develop systems
that solve problems using artificial intelligence.
• Artificial intelligence refers to computer systems that mimic human-
like intelligence.
• Such intelligence include; visual (seeing) perception, speech
recognition, decision making and movement.
• Examples of 5GLs include; PROLOG, Mercury, LISP and OPSS.
OBJECT ORIENTED PROGRAMMING
• In OOP, a program may consist of several objects that interact by
sending messages to each other.
• This is similar to the way a person considered as an object sends a
message to another person requesting for something to be done.
• Most of the programming languages that supported structured
programming like C have been enhanced to support object oriented
programming.
• In OOP, several objects are linked together through a method known
as association to create a complete program.
OBJECT ORIENTED PROGRAMMING
Cont…
• Examples of OOP; Java, Microsoft Visual Basic, Net, Objective-C, C++,
C#, Python, Perl, Ruby, Delphi Pascal and Smalltalk.
SAMPLE OOP PROGRAM
Figure below shows sample Hello World in GUI environment of Visual
Basic. Net.
WEB DEVELOPMENT AND 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).
• HTML consists of tags that are interpreted by the web browser
software t display content when the file is opened on the browser.
• A tag is a word, symbol or character enclosed in angle brackets <>
that a browser can interpret it as a command.
• For example, to create HTML document, one must use the <HTML>
tag at the very top of the document.
WEB DEVELOPMENT AND SCRIPTING
LANGUAGES Cont…
• Unlike programming languages, HTML does not have declaration part
and control structures. This is why it is not considered as programming
language.
• To enhance interaction and dynamism of HTML web pages, special types
of web programming languages known as scripting languages are used.
• Examples of scripting languages include; JavaScript, VBScript and
Hypertext Preprocessor (PHP)
• A script is a small program code written in a scripting language and then
appended into the HTML program to add functionalities like sliding
calender and form validation.
WEB DEVELOPMENT AND SCRIPTING
LANGUAGES Cont…
• Most HTML elements have an opening and a closing tag.
• An opening tag is enclosed between <> while a closing one between
</ >.
• The content to be displayed on the browser is enclosed between an
opening and closing tags.
• For example, the statement <h2> Hello World </h2> will display the
word “Hello World” in big bold text on the screen.
WEB DEVELOPMENT AND SCRIPTING
LANGUAGES Cont…
• The table below shows examples of HTML tags and their meanings.
SAMPLE HTML PAGE
• Below is a simple structure of HTML for web page that displays Hello World
on a browser.

• Although the code can be written using any text editor, the file must be
saved with .html extension.
BENEFITS OF HIGH LEVEL
LANGUAGES
• Are portable i.e. can be installed in more than one computer.
• Are user friendly and easy to use and learn
• Are more flexible. They enhance creativity and innovation of the
programmer and increase productivity in the workplace.
• It is easier to correct programs written in high level languages.
LIMITATIONS OF HIGH LEVEL
LANGUAGES
• They require large computer memory to be executed.
• High level language programs have to be interpreted or compiled to
machine form before the computer can execute them hence need
more hardware and software resources.
• Their nature encourages use of many instructions in a statement
hence the size of these instructions cause slower program processing
Program development Process
• Guidelines on how to solve a programming problem are;
1. Clearly define what a program is to do (problem definition)
2. Close your eyes and visualize the program running on the computer
3. Write a pseudocode version (algorithm design) of the program
4. Desk-check (dry-run) the pseudocode for any logical flow errors
5. Write the program code on a paper using a programming language
6. Test the program on paper for any syntax and logical errors
7. Write the source code using a programming language such as Basic,
C++ etc
Program development Process
Cont…
8. Compile the program and correct any errors displayed by the
compiler
9. Run the program with test data for input to test for any logic errors
10. Validate the results of the program
Summary of the guidelines
• The guidelines outlined above can be summarized into five main
phases of program development life-cycle. (PDLC)
1. Problem definition
2. Algorithm design
3. Program coding
4. Program testing and debugging
5. Program review and maintenance
Problem Definition
• Refers to one’s ability to identify a problem that need to be solved
using a computer program.
• The following three situations may motivate a programmer to develop
a computer program.
a. Problem or undesirable situations that prevent an individual or
organization from achieving their objectives.
b. Opportunity to improve the current system of service.
c. New directive given by the management or government requiring
change in the status quo.
Sample Problem
• Consider a mathematical problem such as calculating the area of a
circle. In this case, the problem is finding the area of a circle. As a
programmer, it is your responsibility to develop a program that can be
used to calculate the area of any circle. For such a problem, a
programmer must conceptualize the solution by first understanding
the problem, then identify input, processing logic and the expected
output.

You might also like