CSC201 2023 Lecture ONE
CSC201 2023 Lecture ONE
UNIVERSITY
ILÉ-IFÈ., NIGERIA.
FACULTY OF TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
INTRODUCTORY LECTURE NOTES
O
. DÉ.JO
. BÍ, O
. dé.túnjı́ A.
Room 109, Computer Buildings,
[email protected]
November, 2023
Contents
ii
Lecture Note 1
The Lectures in this aspect of the course is concerned with preliminary subject-matter
in Computer Programming. Here the instances of abstraction and formal definitions
of fundamental terminologies in computer programming are introduced. History of
modern computers and the techniques and methods underlying Computer Program De-
velopment process are also explained with examples.
1
The instruction that a computer executes is prescribed by its human programmer.
The instruction to achieve a problem-solving task is expressed using a “computer pro-
gramming language. “Computer programming language” differs from human written
language in the following aspects:
In this course, therefore, you should NEVER confuse a material agency (ma-
chine), no matter its sophistication, with biological agency (human).
Computer Programming is a process. A process has instances of state and transi-
tion. A programming language instruction is used to influence computer components
to give expression to the state and transition in the process. The sequence of Com-
puter instructions that describe a process from its “Beginning to its “End is a “program.
“Programming Language are created by mimicking “Written human language. The for-
mulation and expression of written sentences are replete in Computer Programming
language instruction. This is because “computer program instructions” are constructed
by taken recourse in the metaphor of “human written sentence construction”. The sim-
ilarities between “Computer programming language” and “Written human language”
are discussed in Section 1.8. However, there are fundamental distinctions between the
“Written human language” and “Computer programming language”. In the written hu-
man language, a NOUN is the name (label) used to identify an instance or agency. The
metaphor of NOUN used in computer programming language is an operand (string)
ascribed to a constant or variable data. In written human language, a VERB is word
ascribed to the motion (action) of an instance or agency. The metaphor of VERB in
computer programming language is the operator (e.g. Addition, Subtraction, Multi-
plication) used to manipulate data in the process of giving expression to the transition
2
in computer states. Whereas Verb and Noun are part-of-speech in the grammar of writ-
ten language, Operator and Operand are symbols in the syntax of a valid computer
instruction.
In a simple formulation:
1 EXPRESSION = ACTOR + ACTION
2 HUMAN WRITTEN LANGUAGE SENTENCE = NOUN + VERB
3 COMPUTER LANGUAGE INSTRUCTION = OPERAND + OPERATOR
Item 1 above is inherent in human sensory experience. An Action and its Actor
are inextricably intertwined and inseparable in human sensory experience. Item 2 is
located in human language expression. Action (Verb) and its Actor (Noun) are sepa-
rated and expressed individually. Item 3 is ascribed to the Manipulation (Operation) of
Operand (Data) in computer memory.
In this course, therefore, you should NEVER confuse Computer Program-
ming Language (E.g. Python, Java, Fortran), no matter its sophistication, for
Human Written Language (E.g. Yorùbá, Hausa, Igbo, English).
In order that two or more humans can communicate with each other, they must be
familiar with a language. Therefore, familiarity with a programming language, such as
Python, is required to effectively write instructions for a computer system. Familiarity
is acquired through a careful study of the instruction construction in a programming
language as well as engagement and practises with the prescribed standard and con-
vention. The more program you write in a Programming Language, the more your
familiarity and competency with its use.
DATA
PROCESS OUTPUT
INSTRUCTION
3
2. Processing data following the instruction.
3. Produce the output of the processed data according to the instruction.
A material agency (machine) or tool that has the capacity to carry out the tasks
listed above is a computer. Indeed modern computers have the capacity listed above,
but they are unlike other machines. What sets the modern computer apart from all the
machines before it is Language. Humans have created a language with which to give
instruction to modern computers. The language is created by imitating written human
languages. The language is called Computer Programming Language.
4
The Diode device era is followed by Transistor Era. During the Transistor
Era, circuits that implement basic logical operation such as AND, OR and NOT were
fabricated as a single ship. This way, the computing machine during this era consumes
less electricity. Magnetic cores and index register where incorporated into computing
machines. Example of machines in this era include: Honeywell 800, UNIVAC, IBM
7000 Series.
Transistor Era is followed by the Integrated Circuit Era. During this era, elec-
trical resistors, capacitors and transistors, are integrated as a silicon ship. The sil-
icon ships are use manufacture computing machine components. The microproces-
sor emerges during this era. The microprocessor is a device capable of automatically
carrying out arithmetic and logical operation. This makes it possible to manufacture
Calculator-on-a-chip devices. Example of machines in this era include Honeywell 6000
and the IBM 360/370 series. The disused chassis of IBM 370 machine used at the Uni-
versity of Ife. Computer Centre is depicted in Figure 1.2.
Figure 1.2: Plate of IBM 370 machine at the University of Ife. Computer Centre
From about 1975 onwards, Large Scale Integrated Circuit have emerged with
more advancement in technology. The number of electronic components and part that
5
can be integrated into a single ship has increased tremendously. The modern Nano-
technology era makes it possible to put millions of circuit into a material ship that is
about the size of human index-finger nail.
As a summary, you should note the following in respect of computer technology:
6
you cannot see human mental activity, but you could see the physical activities through
his/her action. However, human physical activities are the manifestation of human
mental activity. Hence, human mental and physical aspects work in harmony in hu-
man activities. Similarly, the hardware and software must work in harmony before the
computer can function properly.
The next section introduces you to the hardware components of the computer. The
components discussed here are necessary for understanding how the computer program
works. There are other hardware components of the computer which you do not really
need to know much about before you can write a program. For example, the computer
motherboard and power supply unit.
7
subcomponents:
This is the place where the computer stores results of ongoing operation. The memory
element are inside the processor. They are also called register. Each of the register
inside a process severs a specified purpose. An example is the Accumulator Regis-
ter, which stores the results of an ongoing arithmetic operation. Another example is
the processor Status Register, which stores the status of an ongoing operation, such
as when “an overflow” or “negative” result is generated. The Memory element can be
likened to a scratch pad that you use while solving mathematics problem: a place where
rough work is written. The content of the Memory Element or register is lost imme-
diately power is switched off from the computer. This is why the Memory Element of
register is called a Volatile Memory.
The Control Unit determines the operation of all the other hardware component of the
computer. However, the activity of the Control Unit is determined by the Computer
Software. The Control Unit (CU) will, for example, determine when the input device
must read data, when the output device must write output and when data and instruction
are transmitted between devices. The CU reads program instructions from the computer
memory and interprets (decodes) the instructions. It then uses the interpreted instruc-
tion to determine what is to be done. To achieve the tasks specified in the instructions,
the CU generates a series of control signals to the other parts of the computer hardware.
When everything seems to be working well but nothing is working, the control unit is
probably faulty.
Control units in advanced computers may change the order of some instructions
so as to improve performance.
The ALU carries out arithmetic and logical operation. It arithmetic operations include:
Addition (+) and Multiplication (×). Its logical operations are those that evaluate to
True or False. Examples includes Greater Than (>), Less than (<). Most computer in-
structions are realised through these simple operations. It turns out that by performing
these simple operations, a computer can be programmed to achieved complex tasks.
This is done by breaking the complex tasks into simple steps that are realised through
the operation of the Arithmetic and Logical Unit. Therefore, modern computers can
be programmed to perform a well-defined task; although it will take more time to do
so if its ALU does not directly support the operations in the task. An ALU may also
compare numbers and return boolean (true or false) value depending on whether one is
8
equal to, greater than or less than the other (“is 64 greater than 65?”). Logic operations
also include boolean logic: AND, OR, XOR and NOT. These can be useful both for cre-
ating complicated conditional statements processing boolean logic. Modern computers
(e.g. Superscalar machines) contain multiple ALUs so that they can process several
instructions at the same time. Graphics processors and computers with SIMD (Single
Instruction Multiple Data) and MIMD (Multiple Instruction Multiple Data) features
often provide ALUs that can perform arithmetic on vectors and matrices.
Memory elements (ME), Arithmetic and Logical Unit (ALU) and Control Unit
(CU) are together called the Central Processing Unit (CPU) of the computer.
CPU = ME + ALU + CU
The computer’s capacity to carry out small to large scale processes, its CPU must
be supported by Memory Devices.
There are two categories of memory devices: (i) Main memory and (ii) Mass
memory. These are discussed in the following subsection.
The Main memory is the memory device in which the computer stores the data and
instruction in the currently running program. The computer store temporary result of
operation in this memory. When a program is executing, its data and instructions are
store in the Main memory. The main memory is a Random Access Memory (RAM).
This implies that the computer can access data in the memory at any location of the
memory without delay and in any order. Main memory is usually smaller in size than
the Mass memory. It is also more expensive than the mass memory. A major weakness
of the Main memory is that when electric power is lost, its contents will be lost as well.
This is why it is called Volatile memory. The Main memory is also called Primary
memory or Core memory. The data and instruction that we wish to retrieve latter are
stored in the Mass memory. This is discussed as follows.
The Mass memory is the memory device in which the computer stores data and in-
struction that can be retrieved latter. When a program is NOT executing, its data and
instructions are store in the Mass memory. The mass memory is a Sequential Access
Memory (SAM). This implies that the computer can access data in the memory in the
9
sequence or order they are store in the memory. Mass memory is usually much larger in
size than the Main memory. The Mass memory is also cheaper than the Main memory.
A major strength of the Mass memory is that when electric power is lost, its contents
are retained. This is why it is called Non-Volatile memory. A major weakness of Mass
memory is that it is slower than the Main memory. The Mass memory is also called
Secondary memory or Peripheral memory. There are other memory devices, such
as the Read only Memory (ROM) and Programmable Read only Memory (PROM). In
these memory devices, specialised data and instructions are stored. For example, the
data and instruction that the computer requires for its intrinsic operations are kept in
these specialised memory devices. Examples of such specialise data and instruction
are those that the computer system use during “start-up” and “Booting”. The computer
timing data is also stored in Specialised memory devices. This class of memory are
usually of interest to “Embedded” or “Real-time” system programming.
10
Table 1.1: Computer memory metric
Ser. Name Description
Num-
ber
1. Bit A status of the computer cell. It can be Zero (0)
or One(1); 0 and 1
2. Nibble Four bits. 0 1 0 1
3. Byte Eight(8) Bits or Two (2) Nibble
4. Word This is the number of bytes that a machine can
process at one instance of its operation. This is
the data bus of the computer.
5. Kilobyte (KB) A byte is computed as 210 (1024) Bytes.
6. Megabyte One Megabyte is computed as 220 (1,048,576)
(MB) Bytes.
7. . Gigabyte A Gigabyte is a computed as 230
(GB) (1,073,741,824) Bytes.
8. Terabyte (TB) A Terabyte is computed as 240
(1,099,511,627,776) Bytes.
9. Petabyte (PB) A Petabyte is computer as 250
(1,125,899,906,842,624) Bytes.
10. Exabyte (EB) An Exabyte is computed 260
(1,152,921,504,606,846,976) Bytes.
11
A software is a set of programs that influences and controls a computer
hardware during the task of executing a process.
Computer software are of Two (2) categories:
(i) System software.
(ii) Application software
These are explained in the following Subsection.
12
1.6.2 Application software
An Application Package is a collection or suit of software intended for solving prob-
lems in a particular user environment. Each of the set of programs in an Application
software is for achieving specific user task. For example, a set of program can be writ-
ten for assisting with all the work done in the office. The work may include document
typing and processing also called word processing. Keeping a “table of inventory” also
called spreadsheet. Other program may be written for “drawing of graphics” and/or
“Architectural Design”. Some others may also be written for music compilation and
processing. An example of Application Package is Microsoft Office. This pack-
age comprises (i) MS Word (for word processing) (ii) Excel (For spreadsheet) (iii)
MS FrontPage (For graphic design) (iv) MS Publisher (For publishing works), (v) Ms
PowerPoint (For making presentation slides), etc. Another examples is OpenOffice. It
comprises similar applications like Microsoft Office. Other examples of Application
Software include:
As you are already aware, there are Application programs (Apps) on your Mobile
Phone for doing all sort of tasks from banking, to playing games, searching for lo-
cation, and so forth. These Apps cannot run except there is a System program e.g
Android, already running on the hardware of your Computer or Phone. Application
programs are written by Application programmers. Substantial parts of Application
programmers are written using High Level Programming languages such as Python,
Java, C++, Pascal, FORTRAN.
13
After applying this instruction to the data the computer produces an output. This
means that all what you want the computer to do must be reduced into data and in-
structions. While following the instruction, the computer will be manipulating the
data. If we adequately describe our instruction and accurately specify our data, then
the output that the computer generates will be what we want.
1. Operand (Data)
2. Operation (Operator)
14
1.7.1 Operand: Data
Data are the elements that the computer will manipulate during its processing operation.
Individual Data item (or datum) is labelled with a name. If the datum is a variable, it
is labelled with Variable name. If the datum is a constant, it is labelled with Constant
name. Other types of data including: Numerical, Literal or Logical are also labelled
accordingly. Operands are like the NOUN of a computer instruction because they state
the identity of the data to be manipulated.
15
Note that a letter is written by humans and the instruction or message in it will be
read by another human being.
In the same manner a computer program is written by human being (a Program-
mer) but the primary target or audience of the instructions or messages a machine (the
computer). A program:
1. A computer instruction is written in a Programming Language { e.g. Python,
FORTAN, JAVA, C++, VisualBasic, etc. }.
2. The symbols for composing an instruction are drawn from the alphabet of the
computer language.
3. There is format to which admissible instruction must conform {e.g. this is called
the Syntax or Format of instruction }.
4. A program has an opening and closing statement
5. There are sequence of instruction, functions and sub-programs between the Open-
ing and Closing statements.
6. The program conveys the writer (programmer’s) instructions to the computer (re-
ceiver).
The following subsections, and indeed, other aspects of this course will explicate
the above analogy.
To compose an effective computer program, it is important to be familiar with the
Programming Language and Programming Process. Familiarly with Programming
Language includes:
16
1. Data formatting.
2. Input and output statements.
3. Decision, Control and Conditional Statements.
4. Loops and Looping.
5. Array data structures.
6. Routings and Functions: Modular Programming (Breaking a complex program-
ming problem into smaller problems call modules).
7. File processing.
8. Object Oriented Programming
17
Table 1.2: Python Reserved or Key words
True elif try return def in raise
and else while lambda del is from
as except with nonlocal break import finally
assert finally yield None continue if
class global pass not false for
composition of names in Python, however, follow a set of rules. Some of the rules
include:
1. A variable or constant name can only be composed using the Python set of sym-
bols. This includes upper case letters {A, B, C, ..Z}, lower case letters {a, b, c,
..z} and digits {0,1,2,3,4,5,6,7,8,9}.
2. Variable or constant names are case-sensitive. What this implies is that Number,
number and NUMBER are three different names.
3. A variable or constant name CANNOT be any of the Python keywords.
4. A name should be limited to Thirty-one (31) characters in length. That is a name
should have not more than 31 characters.
5. A number should not start a name. For example example, the variable 5name is
wrong but Name5 is correct.
6. A special character (except the underscore, ), should not be used in forming a
name. For example, the variable Fn*ame is wrong but the name Fn ame is correct.
18
(iv) How to compile the digital version in (iii) into computer native language, that is
streams of 0 and 1.
(v) How to identify and remove errors and mistakes from your code.
(vi) How to document your code for future use and improvement.
Familiarly with Programming Process is briefly discussed in the following sec-
tions.
1.9 Algorithm
The origin of the term Algorithm was traced to a 9th century Arabic scholar called Abu
Ja’far Muhammed Ibn Musa Al-Khowarizm. An algorithm is a sequence of formal
instruction describing the solution to a computing problem. An algorithm describes
the solution one problem only. This implies that when an algorithm is written for a
problem it cannot be used to solve a different problem.
The following are the features of an algorithm:
1. [Terminal:] There is exactly one ENTRY (START) and one EXIT (END) points
in the algorithm. These are called the terminals of the algorithm.
2. [Finite process:] The steps in the algorithm must be finite. The number of steps
from when the input is applied and an output is generated must be totally count-
able. A step corresponds to an instruction.
3. [Effective:] The algorithm must produce the total output corresponding to the
input data.
4. [Soundness:] The algorithm must produce the same output for an input no matter
the number of times that the input is applied.
5. [Practical:] An algorithm must be executable on a computer system.
6. [Halt:] The program corresponding to an algorithm must release all computer
resources immediately after its termination.
The instruction in an algorithm and how they are structured follows a standard set
of rules. An algorithm intended for a program is design before it is reduced into codes
(set of instruction) and implemented on a computer. Algorithm designs are primarily
intended for use among programmers during the programming process. An algorithm
is, therefore, an important aspect of computer programming just as the Plan is important
in Building a house.
There are two (2) popular tools for designing an algorithm. These are: (i) Pseudo-
code and (ii) Flowchart. A pseudo-code uses instructions written out in long-hand as
19
well as mathematical expression to express an algorithm. This is done in a fashion
similar to human written language discussed above. Pseudo-code are usually not very
explicit as their interpretation often require an understanding of the rule for writing the
expression in the pseudo-code.
In the flowchart approach to algorithm design, however, geometric symbols are
used to represent instructions. Familiarity with only a few geometric symbols is re-
quired in order to design the algorithm for a complete problem. We will be using the
flowchart more often in this course. Some important flowchart symbols are shown in
Figure 1.5. We will discuss them further during our lecture.
20
1.10 Computer program development process
To develop a program for the solution a problem using the Python programming Lan-
guage, you need to follow some steps.
(i) Creating the source file. Here you type the program (from paper) into a com-
puter Text Editor.
21
(ii) Compiling the program. The program text will be applied to Python Compiler
software which will check it for Syntax error. If there are syntax errors (or
warning in your program) you will need to correct it in your source file. If no
error is found, the system will generate the object or executable file.
(iii) Repeat steps (i) and (ii) until your programe is running as desired. The out-
come of this sequence of steps, therefore, is a RUNNING PROGRAM.
Step 6: Programe Testing Run the program with the Input data you used in Step 1 to
confirm that the output you computer manually is also what the computer gener-
ates. Thereafter, select a number of example input data that you already familiar
with their outputs. If the output produce by your program is not correct, you need
to go back to the design [Step 4] of the solution. If the problem persists, then you
move to Step 3, and so forth. The outcome of this step is a PROGRAM TEST
DOCUMENT. The document contains a description of how the testing was per-
form. It states the data you used for each test and the output generated and the
programmers comments on the correctness of the output.
Understand the problem: The name of the program is FindAverage. The task of
finding the average of Five (5) numbers involves: (i) Finding the Sum by adding
the numbers together and (ii) Dividing the Sum by 5. We will assume that the
numbers are of type Real. Type Real are numbers with factional part. For example,
5 is an Integer because it has no fractional part, but 5.0 is a Real number because
it has a fractional part; even when the fractional part is zero.
The command f loat is used to convert an input into a real number in Python.
Therefore, an input data is converted to real number by applying the f loat com-
mand to it.
The command int is used to convert an input into a integer number in Python.
Therefore, an input data is converted to integer number by applying the int com-
mand to it.
If we assume that the numbers we wish to find the Average are:
• 5.0
• 8.0
• 7.0
• 9.0
22
• 24.0
We will
1. Sum the numbers, i.e. 5.0 + 8.0 + 7.0 + 9.0 + 24.0 = 53.0
53.0
2. Divide the Sum by 5, i.e. 5.0 = 10.6
Identify the input and output: The input to the problem are the five numbers: let us
label them using the variables:
N umber1, N umber2, N umber3, N umber4, N umber5
The output from the program is the average: let us label it with the variable name:
Average.
Formulate the process: The process require for computing the output from the input
are as follows:
Sum = N umber1 + N umber2 + N umber3 + N umber4 + N umber5
and
Sum
Average =
5.0
Design the solution algorithm: The solution algorithm is represented by the flowchart
in Figure 1.6.
Start
Read Number1
Read Number2
Read Number3
Read Number4
Read Number5
Average = Sum/5.0
Write Average
Stop
23
Implement the solution: To implement the design, create the source file by typing the
following program code into the Python editor.
Run the program as instructed in the CSC201 Laboratory and tutorial manual.
Test the Program: Run the program using the data used in Step 1 and see your output.
Now run the program again with at least Three (3) other set of input of your choice.
1 item = 5
2 Sum = 0.0
3
4 for n in range(item):
5 NextNumber = float(input("Enter the next number : "))
6 Sum = Sum + NextNumber
7
8 Average = Sum / item
9 print("Average of ", item, " numbers is :", Average)
The program in Table 1.3 will work only when the number of input is Five (5).
What this implies is that even if you want to find the Average of Three (3) numbers,
the program will not work. Also, the instruction to read every number is in the code.
Most often, programs are designed to be more flexible. The flowchart in Figure 1.7 is
the design for a program that can read a specified number of input data and output their
average. The Python code for the flowchart design in Figure 1.7 is in Table 1.4.
24
Start
Sum = 0.0
NextNumber = 0.0
Average =0.0
Item =0
Read NextNumber
No
Item = 5?
Yes
Average = Sum/5.0
Write Average
Stop
The Python program codes in Table 1.3 and Table 1.4 will work only when the
number of input is Five (5). What this implies is that even if you want to find the
Average of Three (3) numbers, the program will NOT work. Most often, programs
are designed to be more flexible. To improve the flexibility of the program, it will be
designed to be able to handle various number of input data.
1.12 Exercise
The Python code to find the average for any number of input data is in Table 1.5.
You are to carry our the Program development process above in respect of the
code.
25
Table 1.5: Python code for flexible Average computation
1 item = 0
2 Sum = 0.0
3
4 for n in range(item):
5 NextNumber = float(input("Enter next number : "))
6 Sum = Sum + NextNumber
7 item = item + 1
8 Average = Sum / item
9 print("Average of ", item, " numbers is :", Average)
26