ICT316_SWE316_Introduction to Programming LectNotes Nov2024
ICT316_SWE316_Introduction to Programming LectNotes Nov2024
Programming languages are tools used in developing software thus the concept of
programming language. This discussion on the concept of programming language is used
to refresh and prepare the us towards the main topics.
The fundamental of programing language which is the foundation is discussed , also with
the categories of programming language as well as the attribute of good programming
language.
Programming languages have been in active over 40 years ago thus, all languages have
their link to the earlier versions developed.
• Syntax is a set of rules that define how the commands have to be arranged to make
sense and to be correctly translatable to the machine code.
• Grammar is a set of rules of using different punctuation, quotation marks, semicolons, and
other symbols to divide and clarify the syntax of a particular language.
• Semantics is a set of meanings assigned to every command of the language and is used
to properly translate the program to machine code.
A program is a set of instructions, written to perform a specific task by the computer. A set of
large programs is called software. To develop software, one must have knowledge of a
programming language.
Before moving on to any programming language, it is important to know about the various
types of languages used by the computer.
Let us first know what the basic requirements of the programmers are & what difficulties they
faced while programming in that language.
COMPUTER LANGUAGES
Languages are a means of communication. Normally people interact with each other
through a language. On the same pattern, communication with computers is carried out
through a language. This language is understood both by the user and the machine. Just as
every language like English, Hindi has its own grammatical rules; every computer language
is also bounded by rules known as syntax of that language. The user is bound by that syntax
while communicating with the computer system.
➢ Low Level Language: The term low level highlights the fact that it is closer to a language
which the machine understands.
• Machine Language: This is the language (in the form of 0’s and 1’s,
called binary numbers) understood directly by the computer. It is
machine dependent. It is difficult to learn and even more difficult to
write programs.
➢ High Level Language: Low level language requires extensive knowledge of the hardware
since it is machine dependent. To overcome this limitation, high level language has been
evolved which uses normal English, which is easy to understand to solve any problem.
High level languages are computer independent and programming becomes quite easy and simple.
o BASIC (Beginners All Purpose Symbolic Instruction Code): It is widely used, easy to learn
general purpose language. Mainly used in microcomputers in earlier days.
o COBOL (Common Business Oriented language): A standardized language used for
commercial applications.
o FORTRAN (Formula Translation): Developed for solving mathematical and scientific problems.
One of the most popular languages among scientific community.
o C: Structured Programming Language used for all purpose such as scientific application,
commercial application, developing games etc.
o C++: Popular object oriented programming language, used for general purpose.
Copyright @ Eugene Tebo November 2024
2
ICT316/SWE316 : Introduction to Programming , Lecture Notes Part 1
As you know that high level language is machine independent and assembly language
though it is machine dependent yet mnemonics that are being used to represent
instructions are not directly understandable by the machine. Hence to make the machine
understand the instructions provided by both the languages, programming language
instructors are used. They transform the instruction prepared by programmers into a form
which can be interpreted & executed by the computer. Flowing are the various tools to
achieve this purpose:
➢ Compiler: The software that reads a program written in high level language and translates it
into an equivalent program in machine language is called as compiler. The program written
by the programmer in high level language is called source program and the program
generated by the compiler after translation is called as object program.
➢ Interpreter: it also executes instructions written in a high-level language. Both complier &
interpreter have the same goal i.e. to convert high level language into binary instructions,
but their method of execution is different. The complier converts the entire source code into
machine level program, while the interpreter takes 1 statement, translates it, executes it &
then again takes the next statement.
➢ Assembler: The software that reads a program written in assembly language and translates
it into an equivalent program in machine language is called as assembler.
➢ Linker: A linker or link editor is a computer program that takes one or more object files
generated by a compiler and combines them into a single executable file, library file, or
another object file.
➢ Assembly language
o Machine Language:
Every computer has its own language called machine language. It depends on the
specific Hardware of the computer. A machine language is also known as low level
language also called machine understandable language. Computer understands &
executes the program only in machine level language. This low-level language is in the form
of (1‘s and 0‘s) binary code Low Level Language requires memorizing or looking up
numerical codes for every instruction that is used. These are machine dependent
languages. These are used for simulation languages, and LISP, artificial intelligence
applications.
o Assembly Language:
Assembly language is the mnemonic language written in some specific symbolic codes,
such as ADD, SUB etc. An assembly language program is first translated into machine
language instruction by system program called assembler, before it can be executed.
These are languages understandable by CPU & ALU section of Computer Assembly
languages are called low level languages.
This translation, called compilation is done by a systems program called a compiler. The
original program written in High level language is called source program and its translation.,
machine code is called object program. Some popular High Level languages are Basic,
Fortran, Cobol, Pascal, C & C++.High-level language offers three significant advantages
over machine language: simplicity, uniformity and portability (i.e., machine
independence).
Compilers and Interpreters program written in a high level language must be translated into
machine language before it can be executed. This is known as compilation or
interpretation, depending on how it is carried out.
Compilers translate the entire program into machine language before executing any of the
instructions. Interpreters, on the other hand, proceed through a program by translating and
then executing single instructions, or small groups of instructions. A compiler or interpreter is
itself a computer program that accepts a high-level program (e.g. a C program) as input
data, and generates a corresponding machine – language program as output. The original
high-level program is called the source program, and the resulting machine-language
program is called the object program. Every high-level language must have its own
compiler or interpreter for a particular platform. It is generally more convenient to develop
a new program using an interpreter rather than a compiler. Once an error-free program
has been developed, a compiled version will normally be executed much faster than an
interpreted version.
Self-Assessment Exercises
• List and explain the three categories of programming language
• Discuss the attribute of a good programming language
• State any five features of a computer program
• List five program performances
Programmer for developing the program can not directly start any program or project.
Programmer has to understand whole program or project, has to analyze the sequence
and flow of the program
Examples of end users include payroll management system, they needs a printed list of all
employees, a Billing department that wants a list of clients who are 30 or more days
overdue on their payments, they need their deduction information. Since programmers are
providing a service to these users, programmers must first understand what the users want.
When a program runs, you usually think of the logic as a cycle of input processing-output
operations, but when you plan a program, you think of the output first. After you
understand what the desired result is, you can plan the input and processing steps to
achieve it.
Suppose the manager needs a list of all employees who have been here over five years,
because we want to invite them to a special thank-you dinner.
On the surface, this seems like a simple request. An experienced programmer, however, will
know that the request is incomplete. For example, you might not know the answers to the
following questions about which employees to include: Does the manager want a list of full-
time employees only, or a list of full and part-time employees together?
Does she want to include people who have worked for the company on a month-to month
contractual basis over the past five years, or only regular, permanent employees?
Do the listed employees need to have worked for the organization for five years as of
today, as of the date of the dinner, or as of some other cutoff date?
What about an employee who worked three years, took a two-year leave of absence, and
has been back for three years?
The programmer cannot make any of these decisions; the user must address these
questions to manager.
For example, no one knew they wanted to play Angry Birds or leave messages on
Facebook before those applications were developed. Mobile app developers also must
consider a wider variety of user skills than programmers who develop applications that are
used internally in a corporation. Mobile app developers must make sure their programs
work with a range of screen sizes and hardware specifications because software
competition is intense and the hardware changes quickly.
The programmer shouldn‘t worry about the syntax of any particular language during the
planning stage, but should focus on figuring out what sequence of events will lead from the
available input to the desired output.
Planning the logic includes thinking carefully about all the possible data values a program
might encounter and how you want the program to handle each scenario. The process of
walking through a program‘s logic on paper before you actually write the program is
called desk checking.
Languages like Java or Visual Basic are available for programmers because someone has
written a translator program (a compiler or interpreter) that changes the programmer‘s
English-like high-level programming language into the low-level machine language that the
computer understands.
When you learn the syntax of a programming language, the commands work on any
machine on which the language software has been installed. However, your commands
then are translated to machine language, which differs in various computer makes and
models.
Input myNumber
setmyAnswer = myNumber * 2
outputmyAnswer
If you execute the program, provide the value 2 as input to the program, and the answer 4
is displayed, you have executed one successful test run of the program. Testing of logical
errors, syntactically errors are done.
Once the program is thoroughly tested and debugged, it is ready for the organization to
use. Putting the program into production might mean simply running the program once, if it
was written to satisfy a user‘s request for a special list then we can finalize the program.
Writing Pseudocode
You have already seen examples of statements that represent pseudo code earlier in this
chapter, and there is nothing mysterious about them. The following five statements
constitute a pseudocode representation of a number-doubling problem:
start
inputmyNumber
setmyAnswer = myNumber * 2
outputmyAnswer
stop
Using pseudocode involves writing down all the steps you will use in a program. Usually,
programmers preface their pseudocode with a beginning statement like start and end it
with a terminating statement like stop. The statements between start and stop look like
English and are indented slightly so that start and stop stand out. Most programmers do not
bother with punctuation such as period sat the end of pseudocode statements, although it
would not be wrong to use them if you prefer that style. Similarly, there is no need to
capitalize the first word in a sentence, although you
might choose to do so. This book follows the conventions of using lowercase letters for verbs
that begin pseudocode statements and omitting periods at the end of statements.
Pseudocode is fairly flexible because it is a planning tool, and not the final product.
• Instead of start and stop, some pseudocode developers would use the terms begin and
end.
• Instead of writing input myNumber, some developers would write getmyNumber or read
myNumber.
• Instead of writing set myAnswer = myNumber * 2, some developers would write calculate
myAnswer = myNumber times 2 or computemyAnswer as myNumber doubled.
• Instead of writing output myAnswer, many pseudocode developers would write display
myAnswer, print myAnswer, or write myAnswer.
The point is, the pseudocode statements are instructions to retrieve an original number from
an input device and store it in memory where it can be used in a calculation, and then to
get the calculated answer from memory and send it to an output device so a person can
see it. When you eventually convert your pseudocode to a specific programming
language, you do not have such flexibility because specific syntax will be required.
For example, if you use the C# programming language and write the statement to output
the answer, you will code the following:
The exact use of words, capitalization, and punctuation are important in the C# statement,
but not in the pseudocode statement.
2. Algorithm is first step of the solution process, after the analysis of problem, programmer
write the algorithm of that problem.
3. Example of Algorithms:
Ans.
step 1 : start
step 2 : input number
step 3 : rem=number mod 2
step 4 : if rem=0 then
print "number even"
else
print "number odd"
endif
step 5 : stop
Flowchart
Defination : - Graphical representation of any program is called flowchart.
Flowchart Symbols
Here is a chart for some of the common symbols used in drawing flowcharts.
Symbol Symbol Name Purpose
Arrow
Example Flowcharts
In the early days, Charles Babbage had made the device, but he was confused about
how to give instructions to the machine, and then Ada Lovelace wrote the instructions for
the analytical engine. The device was made by Charles Babbage and the code was
written by Ada Lovelace for computing Bernoulli’s number. That was the first time in history
that the capability of computer devices was judged.
1954 - : FORTRAN
FORTRAN was developed in 1954 by John Backus and IBM. It was designed for numeric
computation and scientific computing. Software for NASA probes voyager-1 (space probe)
and voyager-2 (space probe) was originally written in FORTRAN. It is first high level
language. It was developed using the first compiler and it is Machine Independent
Language. In 1958 FORTRAN 2nd version was developed which introduces subroutines,
functions, loops and primitive for loop. It started as a Project and later renamed as
ALGOL58.
1958: ALGOL
ALGOL stands for ALGOrithmic Language. The initial phase of the most popular
programming languages of C, C++, and JAVA.
It was also the first language implementing the nested function and has a simple syntax
than FORTRAN.
The first programming language to have a code block like “begin” that indicates that your
program has started and “end” means you have ended your code.
It introduced concepts like: Block structure code (Marked by BEGIN and END), Scope of
variables (Scope of local variables inside blocks), BNF (Backus Naur Form), Notation for
defining syntax, Dynamic Arrays, Reserved words and IF THEN ELSE, FOR, WHILE loops
1959: COBOL
It stands for COmmon Business-Oriented Language. In 1997, 80% of the world’s business ran
on Cobol. The US internal revenue service scrambled its path to COBOL-based IMF
(individual master file) in order to pay the tens of millions of payments mandated by the
coronavirus aid, relief, and economic security.
COBOL was rated in May 1959 by the ShortRange committee of the US department of
DOD.
1964: BASIC
BASIC (Beginner's All-purpose Symbolic Instruction Code). It was designed as a teaching
language in 1963 by John George Kemeny and Thomas Eugene Kurtz of Dartmouth
college. Intended to make it easy to learn programming. In 1991 Microsoft released Visual
Basic, an updated version of Basic but the first microcomputer version of Basic was co-
written by Bill Gates, Paul Allen, and Monte Davidoff for their newly-formed company,
Microsoft.
1970: Pascal
Pascal is named after a French religious fanatic and mathematician Blaise Pascal. It was
Created in 1970 with the intension of replacing BASIC for teaching language. It was quickly
developed as a general purpose language. It was Programs compiled to a platform-
independent intermediate pcode. The compiler for Pascal was written in Pascal.
1972: C
C is a general-purpose, procedural programming language and the most popular till now.
All the previous codes (like operating system and kernel) written in assembly language gets
replaced by the C language. C can be used to implementing operating system,
embedded system, and on the website using the Common Gateway Interface (CGI). C is
the mother of almost all higher-level programming languages like C#, D, Go, Java,
JavaScript, Limbo, LPC, Perl, PHP, Python, and Unix’s C shell.
By the word paradigm, we understand a set of patterns and practices used to achieve a
certain goal. Millions of programming languages have been invented, and several
thousands of them are actually in use. Compared to natural languages that developed
and evolved independently, programming languages are far more similar to each other
because:
• different programming languages share the same mathematical foundation (e.g.,
Boolean, algebra, logic);
• they provide similar functionality (e.g., arithmetic, logic operations, and text processing);
• they are based on the same kind of hardware and instruction sets;
• they have common design goals: find languages that make it simple for humans to use
and efficient for hardware to execute;
• designers of programming languages share their design experiences.
It is worthwhile to note that many languages belong to multiple paradigms. For example,
we can say that C++ is an object-oriented programming language.
However, C++ includes almost every feature of C and thus is an imperative programming
language too. We can use C++ to write C programs. Java is more object- oriented, but still
includes many imperative features. For example, Java’s primitive type variables do not
obtain memory from the language heap like other objects. Lisp contains many
nonfunctional features. Scheme can be considered a subset of Lisp with fewer
nonfunctional features. Prolog’s arithmetic operations are based on the imperative
paradigm.
➢ Imperative paradigm
➢ Functional paradigm,
➢ Logic paradigm
➢ Object-Oriented paradigm
➢ Visual paradigm
➢ Parallel/concurrent paradigms,
➢ Constraint based paradigm
➢ Dynamic paradigms.
✓ Imperative Paradigm
The imperative, also called the procedural programming paradigm expresses computation
by fully specified and controlled manipulation of named data in a stepwise fashion. In other
words, data or values are initially stored in variables (memory locations), taken out of (read
from) memory, manipulated in ALU (arithmetic logic unit), and then stored back in the
same or different variables (memory locations). Finally, the values of variables are sent to
the I/O devices as output. The foundation of imperative languages is the stored program
concept-based computer hardware organization and architecture (von Neumann
machine). The stored program concept will be further explained in the next chapter.
Typical imperative programming languages include all assembly languages and earlier
high-level languages like Fortran, Algol, Ada, Pascal, and C.
✓ Object-Oriented Paradigm
The object-oriented programming paradigm is basically the same as the imperative
paradigm, except that related variables and operations on variables are organized into
classes of objects. The access privileges of variables and methods (operations) in objects
can be defined to reduce (simplify) the interaction among objects. Objects are considered
the main building blocks of programs, which support language features like inheritance,
class hierarchy, and polymorphism. Typical object-oriented programming languages
include Smalltalk, C++, Python, Java, and C#.
If the question finds a match, we receive a yes answer to the question. Otherwise, we
receive a no answer to the question. Logic programming is about finding facts, defining
rules based on the facts, and writing questions to express the problems we wish to solve.
Prolog is the only significant logic programming language.
Self-Assessment Exercises
• Explain the evolution of programming language.
• What is programming language paradigm?
• List all categories of programming language paradigm.
• Compare and contrast the four programming paradigms: imperative, object-oriented,
functional, and logic
• Explain in details the four common programming language paradigm.
Conclusion
Paradigm is a set of basic principles, concepts, and methods for how a computation or
algorithm is expressed. We have several programming paradigms nowadays. Although
there is similarity between some of these programming languages. The above topic
emphasizes the need to know which paradigm the programming language in use belong
to.
EXERCISE:
1. What is Imperative Programming ? What are its Types ?
2. Write a Difference between Compiler and Interpreter.
2. Clarity: refers to the overall readability of the program, with specific logic. If a program
should not be complicated it should be clearly written, it should be possible for another
programmer to follow the program logic without much effort. It should also be possible for
the original author to follow his or her own program after being away from the program for
an extended period of time. One of the objectives in the design of C is the development of
clear, readable and disciplined approach to programming
3. Simplicity: The clarity readability of the program and accuracy of a program are usually
enhanced by keeping things as simple as possible, uniqueness and consistency should be
included with the overall program objectives. In fact, it may be desirable to sacrifice a
certain amount of computational efficiency in order to maintain a relatively simple,
straightforward program structure.
4. Efficiency: is concerned with execution speed and efficient memory utilization. Many
complex programs require a tradeoff between these characteristics. hence experience
and common sense are key factors are used to increase efficiency of the program.
5. Modularity: Many programs can be broken down into a series of identifiable subtasks. It is
good programming practice to implement each of these subtasks as a separate program
module. In C programming language, such modules are written as functions. The use of a
modular programming structure enhances the accuracy and clarity of a program, and it
facilitates future program alterations.