0% found this document useful (0 votes)
145 views56 pages

Computer System Programming

This document provides an introduction to computer programming. It discusses two main types of software: system software and application software. System software includes operating systems, utility programs, and computer language translators. It controls and manages computer hardware and helps application programs run correctly. Application software performs specific tasks for users, such as word processors or spreadsheets. The document also describes common system software including operating systems, which act as an interface between hardware and software, and programming language translators, which convert code written in high-level languages to machine-readable format.

Uploaded by

Abeh Aondoseer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views56 pages

Computer System Programming

This document provides an introduction to computer programming. It discusses two main types of software: system software and application software. System software includes operating systems, utility programs, and computer language translators. It controls and manages computer hardware and helps application programs run correctly. Application software performs specific tasks for users, such as word processors or spreadsheets. The document also describes common system software including operating systems, which act as an interface between hardware and software, and programming language translators, which convert code written in high-level languages to machine-readable format.

Uploaded by

Abeh Aondoseer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 56

INTRODUCTION TO

COMPUTER

PROGRAMMING

1 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
CHAPTER ONE
SOFTWARE

Sometimes abbreviated as SW and S/W, software is a collection of instructions that


enable the user to interact with a computer, its hardware, or perform tasks.
Without software, most computers would be useless. For example, without your
Internet browser software, you could not surf the Internet or read an internet
page. Without an operating system, the browser could not run on your computer.

TYPE OF COMPUTER SOFTWARE


There are basically two (2) types of software
1. System Software
2. Application Software

What is System Software?


System Software is a set of programs that control and manage the operations of
computer hardware. It also helps application programs to execute correctly.

System Software are designed to control the operation and extend the processing
functionalities of a computer system. System software makes the operation of a
computer more fast, effective, and secure. Example: Operating system,
programming language, Communication software, etc.

System software serves as the interface between hardware and the end users.
Examples are:

 Operating System
 Utility Software
 Computer Language Translator
Features of System Software are as follows:
 Close to system

2 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
 Fast in speed
 Difficult to design
 Difficult to understand
 Less interactive
 Smaller in size
 Difficult to manipulate
 Generally written in low-level language
What is an Application Software?
Application Software is a program that does real work for the user. It is mostly
created to perform a specific task for a user.
Application Software acts as a mediator between the end-user and System
Software. It is also known as an application package. This type of software is
written using a high-level language like C, Java, VB. Net, etc. It is a user-specific
and is designed to meet the requirements of the user.
Conceptual Diagram of a Software System

MICROSOFT
WORD
SOFTWARE

SPREADSHEET
PACKAGE
SYSTEM APPLICATION
SOFTWARE SOFTWARE
DATABASE
PACKAGE
OPERATING UTILITY COMPUTER
SYSTEM SOFTWARE LANGUAGE
TRANSLATOR GRAPHICS
PACKAGE

SINGLE MULTI
USER USER STRUCTURAL/
ARCHITECTURAL
PACKAGE
MAINTENANCE
TASK
CUSTOMIZED
PACKAGE

LOW LEVEL HIGH LEVEL


LANGUAGE LANGUAGE

3 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
TYPES OF SYSTEM SOFTWARE
Here are the important types of System Software:
A. Operating systems: - Operating system software helps you for the effective
utilization of all hardware and software components of a computer system.
B. Programming language translators: - Transforms the instructions prepared
by developers in a programming language into a form that can be interpreted or
compiled and executed by a computer system.
C. Utility programs: - Utility programs are a set of programs that help users in
system maintenance tasks, and in performing tasks of routine nature.

A. OPERATING SYSTEM
i. An operating system is a program that acts as an interface between the software
and the computer hardware.
ii. It is an integrated set of specialized programs that are used to manage overall
resources and operations of the computer.
iii. It is specialized software that controls and monitors the execution of all other
programs that reside in the computer, including application programs and other
system software.

OBJECTIVES OF OPERATING SYSTEM


 To make a computer system convenient to use in an efficient manner
 To hide the details of the hardware resources from the users
 To provide users a convenient interface to use the computer system
 To act as an intermediary between the hardware and its users and making it
easier for the users to access and use other resources
 To manage the resources of a computer system

4 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
 To keep track of who is using which resource, granting resource requests,
according for resource using and mediating conflicting requests from
different programs and users
 To provide efficient and fair sharing of resources among users and programs
Other Functions of Operating System are:
 It interprets and manages the flows of information keyed in from the input
devices to the computer to the output devices.
 It handles communication among the computer components
 Job control language interpretation
 Interrupt Handling
 Memory management
 Provision of good interface to the operator
 Protecting hardware, software and data from improper use
 Control over the hardware resources
 Job sequencing
 Handling errors when they occur and using correctives routine where
possible
 Every Operating System consists of utility program that perform specific
maintenance tasks.

B. COMPUTER LANGUAGE TRANSLATOR


These are specifically developed programs written to convert or translate high or
low level programming languages to machine language or machine code, i.e. 0s
and 1s
There are two types of programming languages;

i. Low Level Language


ii. High Level Language
5 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
i. Low Level Language: it is either an assembly language (the original
language used by all computers to execute program, its machine
dependent) or machine language (program written using coded string of
0s and 1s, tedious to read and to write, prone to errors).

Advantages of Low Level Language


1) Program translation is easier than high level language
2) It affords the programmer the opportunity to understand the internal
structure of the hardware and its registers.
Disadvantages of Low Level Language
1) It is machine dependent, That is, cannot be transferred to another
computer.
2) Program development is slow as the programmer must have detailed
knowledge of the hardware structure.
Program maintenance is slow and error prone

ii. High Level Language: High level language is a programming language


which is easily understandable / readable by human. E.g. BASIC (Beginners All-
Purpose Symbolic Instruction Code), COBOL (Common Business Oriented
Language), FORTRAN (FORmula TRANslator), etc.

Advantages of High Level Language


1. It makes programming easier for the human being.
2. High level instructions are easier to understand and faster to code.
3. Error correction and resting of program is easier
4. They are machine independent. That is, program written for computer can
be transferred to another computer with little or no modification.
Disadvantages of High Level Languages
1) High level language tends to be inefficient in the use of CPU and other
facilities.

6 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
2) It requires more storage spaces.
3) More time is required to run the program as it has to be translated.

TRANSLATOR
The main objective of a translator is to convert a set of instruction or program
written in high level language into an equivalent program in machine readable form
via one or more intermediate language.
Types of translator are:

Interpreter: This is a convertor which converts high level language programme to


low level language programme line by line.

Compiler: This is also a convertor which converts whole high level language
programme to low level language programme at a time.

C. Utility Software
Utility programs tend to perform specific tasks related to the management of
hardware. Examples of utility programs include compression programs, formatters,
defragmenters and other disk management tools.

7 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
WEEK TWO

Concept of programming
System development cycle
Stages of program development
Features of a good computer program

CONCEPT OF PROGRAMMING
A program is a set of instructions that tells the computer what to do. Computer
programming (often shortened to programming or coding), is the process of
writing, testing, debugging/troubleshooting and maintaining act of instructions
(source code) for solving a problem with the computer. A source code is written in
an acceptable computer programming language. The code may be a modification
of an existing source or something completely new.

The purpose of programming is to create a program that exhibits a certain


described behavior (customization). The process of writing source code requires
expertise in many different subjects, including knowledge of the application
domain. Alternatively. Programming is the craft of transforming requirements into
something that a computer can execute. Problem solving on computer is a task of
expressing the solution to the problem in terms of simple concepts, operations and
computer code (program) to obtain the results. To achieve this aim, you may
proceed as follows.

1. First, understand the problem clearly: Decide what you want to be


calculated by the computer. What will be the input data required? (if any).
This is the problem formulation.

2. Write the steps of computation that are necessary to arrive at the solution.
This is setting up the algorithm.
8 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
3. Prepare a flowchart corresponding to the algorithm.

4. Develop the computer program. Test and run it on the computer. There
is an ongoing debate on the extent to which the writing of programs is an art,

Develop the computer program


Source Code:(is the actual text
that is used to construct the
Design an Algorithm: its program using the language of
a set of steps or Prepare the flowchart: is choice.
Understand the instruction statements a diagrammatic
representation of an Compiler: is a software program
problem to be followed to that helps in converting the
accomplish specific Algorithm, a step-by-step
tasks. appraoch to solving a task source code into binary code
(machine language) thta is easy
for a computer to understand and
can be further executed using an
interpreter to run the program.

a craft or an engineering discipline. Good programming is generally considered


to be the measured application art, craft and engineering, with the goal of
producing an efficient and maintainable software (program) solution. The
discipline differs from may other technical professions in that programmers
generally do not need to be licensed or pass any standardized (or
governmentally regulated) certification tests in order to call themselves
“programmers” or even “software engineers”.

SYSTEM DEVELOPMENT CYCLE


Most IT projects work in cycles. First, the needs of the computer users must be
analysed. This task is often performed by a professional Systems Analysts who will
ask the users exactly what they would like the system to do, and then draw up
plans on how this can be implemented on a real computer based system.

9 | Page INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
The programmer will take the specifications from the Systems Analyst and then
convert the broad brushstrokes into actual computer programs. Ideally at this
point there should be testing and input from the users so that what is produced by
the programmers is actually what they asked for.
Finally, there is the implementation process during which all users are introduced to
the new systems, which often involves an element of training.

Once the users start using the new system, they will often suggest new
improvements and the whole process is started all over again.

These are methodologies for defining a systems development cycle and often you
will see four key stages, as listed below.

Implementation Feasibility Study

Programming Design

STAGES OF PROGRAM DEVELOPMENT


Before computer program is successfully written, documented and installed, it
must have passed through the following stages. Each stage has something to
contribute to the accomplishment of the whole task.
10 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
The stages are:
Problem definition:
Before any reasonable and meaningful program could be written, the problem that
prompted it must have to be defined. No one solves a problem he does not know.
The problem to be solved by computer should be well stated and understood
before the solution will be worked out. From the solution, it is expected that the
output of the problem is known and the input will be prepared to arrive at the
output.

Develop the algorithm


An algorithm is a well-defined set of instructions that is used to solve a particular
problem in a finite number of steps. It involves unambiguous stating of the
procedures and steps necessary to transform the input data into output. It
possess a little difficulty to the program planner, and once accomplished
successfully, the rest of the solution follows easily.

Plan the logic of the program/flowcharting:


The logic of the program will be planned using any of the program design tools it
flowchart, pseudocode or hierarchy chart. The choice of the design tool used
depends on the programmer, but the most popular and most handy is the use of
the flowchart to organize the thought of the program planner and to check for any
logic error or misrepresentation. A flowchart is a pictorial view of the program
logic

Write the computer program:


After the design or planning the logic of the program using the flowchart, the next
stage is the actual writing of the program using any of the programming languages
in a proper sequence. This is called, coding of the program. This is done by

11 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
strictly obeying the language syntax or following the established rules of the
programming language.

Type the program into computer:


The next stage after writing the program, it to key the program into the computer.
Any program that will be executed by the computer must be resident in the
computer memory. The typing is generally made one line after the other.

Test and debug the program:


The moment the program has been keyed into the computer, the programmer is
ready to see if the program is working. The program could be translated into
machine language by either a compiler or interpreter depending on the language in
use ie for BASIC program, when the command RUN is typed and entered, the
program begins executing. If any rules language is broken, the program will not
work. The errors must be removed before the program will start producing the
output. Testing is very necessary to ensure that the correct and required answers
are produced as the output.

Document the work:


Documentation helps the user to understand the program better. It identifies
exactly the purpose of the program. It is always referred to whenever changes are
to be made in the program to suite new development. It contains the following
parts.
i) A statement of the problem
ii) ii) Algorithm and program plans (ie flowchart, hierarchy chart or
pseudocode).
iii) Description of input and output
iv) Program listing
v) Test data and results

12 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
vi) Technical details and instruction for the user.

All these are assembled into a finished program documentation.

FEATURES OF A GOOD COMPUTER PROGRAM

1. Reliability
Any developed program for a particular application can be depended upon to
do what it is supposed to accomplish. How often the results of a program are
correct. This depends on prevention of resulting from data conversion and
prevention of errors resulting from buffer overflows, underflows and zero
division.
2. Meeting Users Needs: Any developed system has a purpose for which it is
developed. A developed program is a failure if it cannot meet the objectives
for which it is proposed and designed, that is, if the potential users cannot
use it either because it is too complex or too difficult. The usability of an
application analysis involving the user.
3. Development on time within Budgets: Estimates of time and cost for
writing computer programs have frequently been under or over estimated.
The components of a structured disciplined approach to programming are:
 Proper control and management of
time and cost required.
 Increased programmer productivity
 More accurate estimates.
4. Error-Free Set of Instruction
Almost all large set of programs contain errors. If a program is designed and
developed in a disciplined structured approach, it minimizes the likelihood of
errors and facilitates detection/correction of such errors during program
testing.

13 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
5. Error-Resistant Operations: good program should be designed in such a
way that it can perform validation run on each input data to determine
whether or not they meet the criteria set for them. Eg Reasonableness
check, Existence check, Dependency check, etc.
6. Maintainable Code:
A good program design will always be easy to change or modify when the
need arises. Programs should be written with the maintenance activity in
mind. The structure, coding and documentation of the program should allow
another programmer to understand the logic of the program and to make a
change in one part of a program without unknowingly introducing an error in
another part of the same program.
7. Portable Code:
A good program design will be transferable to a different computer having a
language translator for that language without substantial changes or
modification
8. Readability: The program codes will be easy for a programmer to read and
understand the logic involved in the programming.
9. Storage Saving: A good program design is not to be verbous, that is, it will
not be allowed to be unnecessary long, thereby consuming much storage
that will be required for processing data and storage of information produced
from processing.
10. Efficiency: The amount of system resources a program consumes
(processor time, memory space, slow devices, network bandwidth and to
some extent even user interaction), the less the better.
11. Robustness: How well a program anticipates situations of data type
conflict and other incompatibilities that result in run time errors and program
halts? The focus is mainly on user interaction and handling of

14 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
12. Usability: The clarity and intuitiveness of a programs output can
make or break its success. This involves a wide range of textual and
graphical elements that makes a program easy and comfortable to use.

15 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
WEEK THREE

The Concept of Algorithm

Definition of Algorithm

Features of an Algorithm

Methods of representing Algorithm

CONCEPT OF ALGORITHM
An algorithm is a set of instructions to obtain the solution of a given problem.
Computer needs precise and well-defined instructions for finding solution of
problems. If there is any ambiguity, the computer will not yield the right results.
It is essential that all the stages of solution of a given problem be specified in
details, correctly and clearly moreover, the steps must also be organized rightly so
that a unique solution is obtained.

A typical programming task can be divided into two phases:

(a) Problem solving phase


In this stage an ordered sequence of steps that describe solution of the problem
is produced. Their sequence of steps can be called anti-Algorithm
(b) Implementation Phase
In this phase, the program is implemented in some programming languages.
Algorithm may be set up for any type of problems, mathematical/scientific or
business. Normally algorithms for mathematical and scientific problems involve
mathematical formulas. Algorithms for business problems are generally descriptive
and have little use of formula.

Features of an Algorithm
1. It should be simple

16 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
2. It should be clear with no ambiguity
3. It should head to unique solution of the problem
4. It should involve a finite number of steps to arrive at a solution
5. It should have the capability to handle unexpected situation.

Methods of Representing Algorithm


Algorithms are statements of steps involved in solving a particular problem. The
steps to the solutions are broken into series of logical steps in English related form.
Programs are written to solve real life problems.
There can’t be a solution if there is no recognized problem and once a problem
exist, one must take certain step in order to get a desired solution. The following
methods could be used to represent an algorithm.
 Methods of English like form
 Methods of Flowchart
 Methods of Pseudo code

1. ENGLISH-LIKE FORM OF AN ALGORITHM


The English form of representing as algorithm entails breaking down the solution
steps of the problem into single and sequential English words. The steps are
represented in English to say what action should be taken in such a step.
Example 1
Develop an algorithm to obtain a book on computer from your school library
located on the fourth floor of the building. You are to proceed to the library from
your ground floor classroom.
SOLUTION
1. Start from the classroom
2. Climb the stairs to the 4th floor and reach the library
3. Search a book on computer
17 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
4. Have the book issued 5. Return to your classroom
5. Stop.
Note: The above algorithm solution of example 1, has been written in simple and
clear English way.
Example 2
Develop an algorithm to find the average of four numbers stored in variables
A,B,C,D
SOLUTION
1. Start
2. Read values in variables A,B,C,D
3. Calculate the average as (A+B+C+D)/4 and store the result in P.
4. Write the value stored in P
5. Stop.
Example 3
Develop and algorithm to find the average of four numbers stored in variables A,
B, C, D. When the value of variable A is zero, no averaging is to be done.
SOLUTION
1. Start
2. Read values stored in variable A,B,C.D
3. If the value of A is Zero, then jump to step 6
4. Calculate the average of A, B, C, D and store the result in variable P.
5. Write the value of P
6. Stop.

2. PSEUDO CODE
A pseudo code is the English-like representation of the program logic. It does not
make use of standard symbols like the flowchart. It is a sequential step by step

18 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
arrangements of the instructions to be performed to accomplish a task. It’s a set
of analytical statements written to show the steps and order that would be
followed to solved a problem.
Example 1
Write a pseudo code for findings the area of a room.
Solution:
• Begin process
• Input room length
• Input room width
• Multiply length by width to get area
• Print area
• End process
Example 2
Write an Algorithm to determine a student’s final grade and indicate whether it is
passing or failing. The final grade is calculated as the average of four marks.
Solution:
• Begin process
• Input a set of 4 marks
• Calculate their average by summing and dividing by 4.
• If average is below 50 Print “Fail” else Print “Pass”
• End process

Solution II (below under pseudo code)


• Begin process
• Step 1: Input M1, M2, M3, M4
• Step 2: Grade ← (M1 + M2 + M3 + M4)/4
• Step 3: If (Grade < 50) then

19 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
• Print “FALL”
• Print “Pass”
• End it.

3. FLOWCHART
Flowchart is a representation of the algorithm using standard symbols. Each
symbols has a new function. The Algorithm steps determine which symbol to use
to represent it in the flow each step is linked to another step by using the
directional arrows. A flowchart is a pictorial representation of an Algorithm or of
the plan of solution of a problem. It indicates the process of solution, the relevant
operations and computations, point of decision and other information that are part
of the solution. Flowcharts are of particular importance for documenting a
program. Special geometrical symbols are used to construct flowcharts. Each
symbol represents an activity. The activity could be input/out of data,
computation/processing of data, taking a decision, terminating the solution, etc.
The symbols are joined by arrows to obtain a complete flowchart.

Name Symbol Use in flowchart

Oval Denotes the beginning or end of the program.

Parallelogram Denotes an input operation

Rectangle Denotes a process to be carried out e.g


addition, subtraction, division, etc.

20 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
Diamond Denotes a decision (or branch) to be made. The program should
continue along one of two routes (e.g if/then/ese)

Directional Denotes the directors of logic flow arrows or


in the program.

Flow Chart Symbols and Flow Chart for Mailing Letter

EXAMPLE 1
Draw a flowchart to find the average of four numbers stored in variables A,B,C,D

21 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
SOLUTION Start

Read numbers in
A,B,C,D

Calculate the average


P=(A+B+C+D)/4

Write the value of P

Stop

EXAMPLE 2
Draw a flowchart to find the average of four numbers stored in variables A,B,C,D.
when the value of A is zero, no averaging is to be done.
SOLUTION

Star
t

READ values
For A,B,C,D.

Is
A=0
?

Calculate the
average

Write the value


P
of

Stop

22 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
EXAMPLE 3
Draw a flowchart to calculate the area of a rectangle if the length is L and the
width is B.
SOLUTION

Start

INPUT L, B

AREA = L * B

PRINT L, B,
AREA

END

EXAMPLE 4
Write an algorithm and draw a flowchart that will read the two sides of a rectangle
and calculate its area.
SOLUTION

Pseudo code

 Input the Width(w) and Length(L) of a rectangle

23 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
 Calculate the area (A) by multiplying L with W
 Print A.
Algorithm

Step 1: Input W, L
Step 2: A= L * W
Step 3: Print A.

Flowchart

Stop

Input
W,L

A = L*W

Print A

Stop

24 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
EXAMPLE 5
Write an algorithm and draw a flowchart that will calculate the roots of a
quadratic equation.
Hint: d = Sqrt (b2 – 4ac), and the roots are:
X1 = (-b + d)/2a and X2 = (b – d)/ 2a
SOLUTION PSEUDO CODE
 Input the coefficients (a, b, c) of the quadratic equation
 Calculate d
 Calculate X1
 Calculate X2
 Print X1 and X2
ALGORITHM
Step 1: Input a, b, c
Step 2: d = Sqrt (b * b – 4 * a * c)
Step 3: X1 = (- b + d)/ (2 * a)
Step 4: X2 = (- b – d)/ (2 * a)
Step 5: Print X1, X2

FLOWCHART
Start

Input
a, b, c

d = Sqrt + (b * b – 4*a*c

X1
25 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O

(
Print
X1, X2

= ( - b + d)/ (2*a)

X2 = - b – d) / (2* a)

Stop

EXAMPLE 6

Draw a flowchart that would compute the area of a triangle, given the base as B
and height H
SOLUTION

Start

INPUT B, H

AREA = 1/2B * H

PRINT B, H
AREA

26 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
END

USES OF FLOWCHARTS

1. It gives us an opportunity to see the entire system as a whole.


2. It makes us to examine all possible logical outcomes in any process.
3. It provides a tool for communicating i.e a flowchart helps to explain the
system to others.
4. To provide insight into alternative solutions.
5. It allows us to see what will happen if we change the values of the variable
in the system.

Flowchart Advantages
 Flowcharts are easier to understand compare to Algorithms and Pseudo
code.
 It helps us to understand Logic of given problem.
 It is very easy to draw flowchart in any word processing software like MS
Word.
 Using only very few symbol, complex problem can be represented in
flowchart.
 Flowcharts are one of the good way of documenting programs.
 It helps us in debugging process. 
Flowchart Disadvantages
 Manual tracing is needed to check correctness of flowchart drawn on paper.
 Simple modification in problem logic may leads to complete redraw of
flowchart.
 Showing many branches and looping in flowchart is difficult.
 In case of complex program/algorithm, flowchart becomes very complex and
clumsy.
27 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
 Modification of flowchart is sometimes time consuming

28 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
WEEK 4
Programming Languages (High Level Language)
Types of Programming
Procedural Programming (Basic Programming)
Object-Oriented Programming (Visual Basic Programming)

PROGRAMMING LANGUAGE - High-Level Languages


As computers have developed in complexity, so have programming languages.
High-level language programming are the result of sophistication in programming
languages. The Machine and Assembly languages discussed before require
programmers to construct programs in a form that does not follow normal ways of
human thinking, communication and language notation.
To avoid this problem High-level languages were developed. Another name for
high-level languages is problem-oriented languages. With this language,
programmers’ attention are now directed towards problem solving instead of
operations going on inside computer.
These languages allow mathematicians and Scientists to use common algebraic
notations for coding formulas while other lay programmers can write their
programs in ordinary sentence form. The time and effort needed to write
programs are now reduced considerably and programs are easier to correct and
modify.
A large number of high-level languages are in use today. In fact, more are being
developed daily as researchers are still going on.
Example of high-level languages commonly in use today include:

 BASIC (Beginners All-purpose Symbolic Instruction Code)


 FORTRAN (Formula Translator). There are many versions of FORTRAN
However the modern version is called FORTRAN 77
29 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
 COBOL (Common Business Oriented Language).
 PASCAL (language named after an ancient French Mathematician and
inventor of Pascal engine)
 SQL (Structured Query Language)
 PYTHON
 JAVA SCRIPT etc.

Each of the high-level languages has rules that govern how to write instructions in
them. Like any human language, it is the duty of the programmer or user to learn
the rules of the language he wants to use.

Unlike low-level language which is machine-dependent, high-level languages are


machine independent. That is to say, a program written in any of the high-level
languages can be run with little or no changes by computer made by many
different manufacturers. Thus, as new computers come into existence,
programmers do not have to rewrite the existing programs and learn new language
as it is the case with assembly programming.

The example below shows how to add two numbers held in variables X and Y
placing the sum in X using the most common four high-level languages.

BASIC……. LET X = X + Y

FORTRAN ……. X=X+Y

COBOL………. ADD Y TO X

PASCAL…….. X: = X + Y

It can be observed that the notation is very similar to human ways of thinking and
expression and very remote from the machine language.

TYPES OF PROGRAMMING

30 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
There are two types of programming, they are procedural and Object Oriented
Programming

Procedural Programming
Procedural Programming can be defined as a programming model which is derived
from structured programming, based upon the concept of calling procedure.
Procedures, also known as routines, subroutines or functions, simply consist of a
series of computational steps to be carried out. During a program’s execution, any
given procedure might be called at any point, including by other procedures or
itself. Languages used in Procedural Programming: Q-BASIC, FORTRAN,
COBOL, BASIC, Pascal and C.

Object Oriented Programming:


Object oriented programming can be defined as a programming model which is
based upon the concept of objects. Objects contain data in the form of attributes
and code in the form of methods. In object oriented programming, computer
programs are designed using the concept of objects that interact with real world.
Object oriented programming languages are various but the most popular ones are
class-based, meaning that objects are instances of classes, which also determine
their types. Languages used in Object Oriented Programming:
Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Objective-C, Dart, Swift,
Scala.

Difference between Procedural Programming and Object Oriented


Programming:

31 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
Procedural Oriented Programming Object Oriented Programming

In procedural programming, program is In object oriented programming,


divided into small parts program is divided into small parts
called functions. called objects.

Procedural programming follows top Object oriented programming


down approach. follows bottom up approach.

Object oriented programming have


There is no access specifier in access specifiers like private, public,
procedural programming. protected etc.

Adding new data and function is not


easy. Adding new data and function is easy.

Procedural programming does not have


any proper way for hiding data so it Object oriented programming provides
is less secure. data hiding so it is more secure.

In procedural programming, Overloading is possible in object


overloading is not possible. oriented programming.

In procedural programming, function is In object oriented programming, data


more important than data. is more important than function.

32 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
Procedural Oriented Programming Object Oriented Programming

Procedural programming is based Object oriented programming is based


on unreal world. on real world.

Examples: C, FORTRAN, Pascal, Basic


etc. Examples: C++, Java, Python, C# etc.

THE STRUCTURE OF QBASIC

QBasic is a procedural language. Unlike object-oriented language, it has no


standard structure according to programming style rule. Howbeit, it does have
structure for programmers to follow.

Guide to QBasic Structure


i. Line Number: Programs in QBasic are easily written with line numbers for
readability purpose.
ii. CLS: This means CLear Screen
iii. REM: Implies REMark – Comment.
iv. END: To signify the end of a program

Guide to QBasic Structure- Illustration


For example, the program below does nothing but shows the guide to QBasic
Structure:
5 CLS
10 REM
15 END
33 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
OR
2 CLS
4 REM
6 END

GARBAGE IN & OUT IN QBASIC


To feed/supply data unto the computer system using QBasic, we make use of any
of the following two commands:
i. INPUT statement
ii. READ & DATA statement
To fetch/retrieve stored or inputted data from the computer system using QBasic,
we make use of PRINT statement.
OUTPUT STATEMENTS
These are statements that are used for fetch/retrieve/show to screen, inputted or
stored data from the computer system.
The major/basic output statement used in QBasic is called PRINT. Others will be
treated under FILE.
PRINT can be used in two ways:
For outputting literals e.g. PRINT “I am a programmer”
For outputting variables (values of an identifier) e.g.
PRINT radius, (where radius is a variable having a particular value that has
previously been inputted /captured / stored)
• 5 CLS
• 10 REM
• 15 PRINT “I am a Programmer”
• 20 END
• Press F5 to RUN

34 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
See the output below:

To save:

35 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
OUTPUT STATEMENTS
5 CLS
10 REM
15 INPUT radius
20 PRINT radius
25 PRINT radius * 2
30 END
Press F5 to RUN
OR
Click on RUN and click on START.

36 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
You will first see something like this, prompting you to input/supply value for
radius.
…do the inputting now…and press the ENTER key

…the system responds thus:

To go back to the coding screen, obey the instruction: ‘Press any key….’

37 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
38 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
Class Exercise I
Code in QBasic to output the literals:
BIO-DATA Quiz
HE was born and brought up in Lagos.
He hails from Kwara.
He settles down in Ondo.
Who is He?
SOLUTION I

5 CLS
10 REM
15 Print “BIO-DATA Quiz”
20 Print “_____________”
25 Print “He was born and brought up in Lagos.”
30 Print “He hails from Kwara.”
35 Print “He settles down in Ondo.”
40 Print
45 Print “Who is He?”
50 END

39 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
40 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
CLASS EXERCISE II
Given two variables: birthyear and currentyear, input values for the two variables
and compute your AGE by finding the difference of the two variables.
SOLUTION II

5 CLS
10 REM
15 INPUT birthyear
20 INPUT currentyear
25 PRINT currentyear-birthyear
30 END

INPUT STATEMENT
These are statements that are used for feed/supply data unto the computer
system.
Two Types:
Input Method
Read & Data Method
INPUT Method

41 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
This is used where the program given is a closed problem (e.g. values not
specified). e.g. INPUT A OR INPUT “Enter value for A: ”, A
Here the value of A is expected to be inputted.

42 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
Programming Example
Code in QBasic to solve:
(i) Z = x2 + w/y
(ii) F = b2/4ac
Solutions (i)
5 CLS
10 REM
15 INPUT “Enter value for X: ”, x
20 INPUT “Enter value for W: ”, w
25 INPUT “Enter value for Y: ”, y
30 Let Z = ((x*x) + (w/y))
35 PRINT “The answer is: ”, Z
40 END

SOLUTION (i)
5 CLS
10 REM
15 INPUT “Enter value for A: ”, a
43 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
20 INPUT “Enter value for B: ”, b
25 INPUT “Enter value for C: ”, c
30 Let F = ((b^2) / (4*a*c))
35 PRINT “The answer is: ”, F
40 END

44 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
READ Method
This is used where the program given is an open problem (e.g. values specified).
e.g. READ A
DATA 7
OR
READ A, B, C
DATA 7, 15, 87

Here there is no need using INPUT to enter the value of A because it is already
given.
Programming Example
Given: t = 15, u = 210, s = 14, r = 11
Code in QBasic to compute:
1. V = t + (u – r)
2. W = u/ t2 + s3/t2

Solutions
5 CLS

45 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
10 REM
15 READ t, u, r
20 DATA 15, 210, 11
30Let V = (t + (u-r))
35 PRINT “The answer is: ”, V
40 END

Solutions
5 CLS
10 REM
15 READ u, s, t
20 DATA 210, 14, 15
30 Let W = ((u/(t^2)) + ((s^2)/(t^2)))
35 PRINT “The answer is: ”; W
40 END

46 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
EXECRISE I
Write a QBASIC program that would calculate the area of a rectangle of length L,
and width or breadth B

SOLUTION
10 REM PROGRAM AREA OF A RECTANGLE
15 INPUT L, B
20 AREA = L * B
25 PRINT B, H, AREA
30 END

EXECRISE II
Write a QBASIC program to compute the area of a triangle, given that the base B
and the height H.

SOLUTION
10 REM PROGRAM AREA OF A TRIANGLE
15 INPUT B, H
20 AREA = (B/H)/2
25 PRINT B, H, AREA
30 END
47 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,
B.O
EXECRISE III
Write a QBASIC Program that would compute the sum and average of any four
numbers, print the sum as well as the average.
SOLUTION
10 REM PROGRAM TO SUM AND AVERAGE FOUR NUMBERS
15 CLS
20 INPUT “ENTER THE FOUR NUMBERS”, A,B,C,D
25 SUM = A+B+C+D
30 AVG = SUM/4
35 PRINT “SUM = “; SUM; “AVERAGE = “; AVG
40 END

ASSIGNMENT
1. Write a QBasic program that inputs your scores in ACC101, ACC103 and ACC105.
Computes:
1. Their Sums
2. Their Average
2. Draw a flowchart and write a QBASIC program for adding the integers 1 to 50
and producing their average

48 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
INTRODUCTION TO OBJECT ORIENTED BASIC

Visual Basic Step in Developing Applications

The visual Basic development environment makes building an application a straight


forward process.

There are three primary steps involved in building a visual Basic application.
1. Draw the user interface by placing controls on the form.
2. Assign properties to controls.
3. Attach code to control events (and perhaps write other procedures)

Note:

1. These same steps are followed whether you are building a very simple
application or one involving many controls and many lines of code.
2. The event – driven nature of visual Basic allows you to build your application
in stages and test it at each stage. You can build one procedure, or part of
a procedure, at a time and try it until it works as descried. This minimizes
errors and gives you, the programmer, confidence as your application takes
shape.
3. As you progress in your programming skills, always remember to take above
sequential approach to building a visual Basic application Build a little, test a
little, modify a little and test again. You will quickly have a completed
application.
 Microsoft VB is the fastest and easiest way to create applications for
Microsoft windows.
 The visual part refers to the method used to create the graphical user
interface (GUI).
 The Basic part refers to the BASIC Beginners All – Purpose symbolic
construction code Language.

49 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
With VB an individual can build simple applications in minutes. VB enables you to
write object oriented programmes or simple programs.

HOW WINDOWS WORK


Windows is a GUI operating system. With GUI it easily recognized graphic icons be
selected using the mouse and commands chosen from menus, This is much easier
for the user than typing in the specific lines of code that were required by MS-Dos
in order to perform basic operations. In GUI operating system, more than one
application can be open at the same time. Processor time is shared between
computing tasks and this called multitasking.
1.1 The concept of computer programming
Programming means designing a set of instructions to instruct the computer to
carry out certain jobs that are very much faster than human beings can do. The
earliest programming language is called machine language which uses the binary
code(comprises 0 and 1) to communicate with the computer. However, the
machine language is extremely difficult to learn . Fortunately , scientists have
invented some high-level programming languages that are much easier to master.
Among the high-level programming languages are Java, Javascript, C, C++, c# and
Visual Basic.
If you are looking for help with your computer science essays and research papers,
don't hesitate to contact paper writing services provided by CustomWritings.com.
1.2 What is Visual Basic?
Visual Basic is a third-generation event-driven programming language first released
by Microsoft in 1991. It evolved from the earlier DOS version called
BASIC. BASIC means Beginners' All-purpose Symbolic Instruction Code. Since
then Microsoft has released many versions of Visual Basic, from Visual Basic 1.0 to
the final version Visual Basic 6.0. Visual Basic is a user-friendly programming

50 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
language designed for beginners, and it enables anyone to develop GUI window
applications easily.
In 2002, Microsoft released Visual Basic.NET (VB.NET) to replace Visual Basic 6.
Thereafter, Microsoft declared VB6 a legacy programming language in 2008.
Fortunately, Microsoft still provides some form of support for VB6. VB.NET is a fully
object-oriented programming language implemented in the .NET Framework. It
was created to cater for the development of the web as well as mobile applications.
However, many developers still favor Visual Basic 6.0 over its successor Visual
Basic.NET.
Features of Visual Basic (VB)
 Visual Basic (VB) contains various features that make it similar to other
programming languages such as C, C++, and Java.
 VB is a modern programming language and it is very powerful, simple for
building the applications
 Visual Basic (VB) is useful in developing windows, web and device
applications.
 Visual Basic provides automatic memory management by clearing unused
objects
 VB is a type-safe programming language and it makes impossible to perform
unchecked type casts.
 VB provides a structured and extensible approach for error detection and
recovery.
 Visual Basic is a structure-oriented programming language and the compilation,
execution of VB applications are faster due to automatic scalability.

What programs can you create with Visual Basic 6?

51 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
In VB 6, you can create any program depending on your objective. For math
teachers, you can create mathematical programs such as Geometric
Progression, Quadratic Equation Solver, Simultaneous Equation Solver ,Prime
Number Tester, Factors Finder, Quadratic Function Graph Plotter and so on. For
science teachers, you can create simulation programs such as Projectile, Simple
Harmonic Motion, Star War  etc. If you are in business, you can also create
business applications such as inventory management system , Amortization
Calculator , investments calculator, point-of-sale system, payroll system, accounting
program and more to help manage your business and increase productivity. For
those of you who like games, you can create programs such as slot machine, tic-
tac-toe and more. Besides, you can create multimedia programs such as Smart
Audio Player, Multimedia Player  and more. Indeed, there is no limit to what
program you can create! We offer many sample codes in our tutorial.

The Visual Basic 6 Integrated Development Environment


Before you can write programs in VB 6, you need to install Visual Basic 6 compiler
on your computer. You can purchase a copy of Microsoft Visual Basic 6.0 Learning
Edition or Microsoft Visual Basic Professional Edition from Amazon.com, both are
vb6 compilers. Besides, you can also buy it from eBay at Microsoft Visual Basic 6.0
6 Professional PRO MSDN Library Manual Service Pack. If you have already
installed Microsoft Office in your PC or laptop, you can also use the built-in Visual
Basic Application in Excel to start creating Visual Basic programs without having to
spend extra cash to buy the VB6 compiler.
You can also install VB6 on Windows 10 but you need to follow certain steps
otherwise the installation will fail. First, you need to run setup as administrator.
Next, you need to use custom installation. Clear the checkbox for Data Access. If
you don't, set up will hang at the end of the installation. Finally, click next and wait

52 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
for the installation to complete. For complete instructions, please follow this
link Install VB6 on Windows 10
After installing the vb6 compiler, the icon will appear on your desktop or in your
programs menu. Click on the icon to launch the VB6 compiler. On start up, Visual
Basic 6.0 will display the following dialog box as shown in Figure 1.1.

Figure 1.1: New Project Dialog


You can choose to either start a new project, open an existing project or select a
list of recently opened programs. A project is a collection of files that make up your
application. There are various types of applications that we could create, however,
we shall concentrate on creating Standard EXE programs (EXE means executable).
Before you begin, you must think of an application that preferably have
commercial, educational or recreational value. Next, click on the Standard EXE icon
to go into the actual Visual Basic 6 programming environment.

53 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
When you start a new Visual Basic 6 Standard EXE project, you will be
presented with the Visual Basic 6 Integrated Development Environment (IDE). The
Visual Basic 6 Integrated Programming Environment is shown in Figure 1.2. It
consists of the toolbox, the form, the project explorer and the properties window.

Fig
ure 1.2: VB6 Programming Environment
The Form is the primary building block of a Visual Basic 6 application. A Visual
Basic 6 application can actually comprise many forms, but we shall focus on
developing an application with one form first. We will learn how to develop
applications with multiple forms later. Before you proceed to build the application,
it is a good practice to save the project first. You can save the project by

54 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
selecting Save Project from the File menu, assign a name to your project and save
it in a certain folder. You shall now proceed to learn Visual Basic programming from
the next lesson onwards.

List of Computer Programming Languages

ALGOL ALGOrithmic Language First structured procedural programming language, used


1960 mainly for solving math problems.

APL A Programming Language Interpreted language using a large set of special


1961 symbols and terse syntax. Used primarily by
mathematicians.
BASIC Beginners All-Purpose
Very popular high-level programming language,
1965 frequently used by beginning programmers.
Symbolic Instruction Code
C Predecessor was Bell 1972 Compiled, structured, programming language commonly
used in many workplaces because its programs are easy
Laboratory's 1972 B
to transfer between different types of computers.
Programming Language
C++ Advanced version of C. C++ is used in numerous fields, such as accounting and
1985 Developed at ATT finance systems, and computer-aided design. Supports
Bell Labs. object oriented programming.
COmmon Business- English-like programming language, emphasizes data
COBOL Oriented 1959 Language structures. Widely used, especially in businesses.
FORTH FOuRTH-Generation 1970 Interpreted, structured language, easily extended.
language (4GL) Provides high functionality in limited space.
Fortran FORmula TRANslation Initially designed for scientific and engineering uses, a
1954 high-
level, compiled language now used in many fields.
Introduced several concepts such as variables,
conditional statements, and separately compiled
subroutines.
HTML HyperText Markup Designed for publishing hypertext on the Internet.
Language 1989

JAVA Sun Microsystems Originally developed for use in set-top boxes,


developers 1990 drank a transitioned to the World Wide Web in 1994.
lot of coffee when coding
for this.

55 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O
LISP LISt Processing 1960 A list-oriented programming language, mainly used to
manipulate lists of data. Interpreted language, often
used in research, generally considered the 'standard'
language for Artificial Intelligence (AI) projects.
LOGO Derived from Greek logos, Programming language often used with children.
1968 meaning word Features a simple drawing environment and several
higher-level features from LISP. Primarily educational.
Modula-2 MODULAr Language, 1980 Language that emphasizes modular programming.
designed as High-level language based on Pascal, characterized by
secondary phase of lack of standard functions and procedures.
Pascal (Niklaus Wirth
devised both)
Pascal Blaise PASCAL 1971 Compiled, structured language, based on ALGOL. Adds
data mathematician and inventor of types and
structures while simplifying syntax. Like C first
computing device language, it is a standard
development language for microcomputers.
PERL Practical Extraction and It is a text-processing language that looks like a
1988 Report Language combination of C and several Unix text processing
utilities.
PILOT Programmed Inquiry, 1969 Programming language used primarily to create
Language Or Teaching applications for computer-aided instruction. Contains
very little syntax.
PL/1 Programming Language Designed to combine the key features of Fortran,
One 1964 COBOL, and ALGOL, a complex programming language.
Compiled, structured language capable of error handling
and multitasking, used in some academic and research
environments.
SGML Standard Generalized Designed as a metalanguage, it is used as an
Markup 1986 international standard for the description of marked-up
Language electronic text.
SQL Structured Query Designed to be used for creating complex databases and
Language 1986 accessing data in a relational database.
VB Visual Basic 1990 Sometimes called the Rapid Applications Development
system, is used to build applications quickly.

56 | P a g e INTRODUCTION TO COMPUTER PROGRAMMING-AKILAPA,


B.O

You might also like