You are on page 1of 74

COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,

08069018655)
DOWNLOADED FROM FUTABASE.COM

A TUTORIAL GUIDE

TO

CSC 102

WRITTEN & COMPILED BY:

BALOGUN, T. R

(a.k.a. B. PROGRAMMER)

COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE


MOSQUE (08161885095, 08069018655)
FUTABASE.COM

COURSE OUTLINE

Introduction to General computing


Introduction to programming language
Algorithm design tools (Pseudocode & flowcharting)
Programming with BASIC
Introduction to programming with Visual BASIC 6.0
Introduction to MS-DOS
Solution to Practical Questions on BASIC

1
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
INTRODUCTION TO GENERAL COMPUTING

What is Computer?

A computer is an electro-mechanical device, which accepts input data in a


prescribed form, through an input device, store & process it through the
processor and produce the required result in a specific format (information,
or signal) through an output device.

The fundamental function of a computer

The basic purpose of using the computer is to process data quickly,


efficiently so that meaningful and accurate information is obtained in time.

The basic function of the computer can be represented as in figure 1.1 below
INPUT PROCESS OUTPUT

Fig 1.1 Schematic representation of computer operation

(1) Input: this is the entry point to a computer where data is fed into it
for processing, i.e. computer accepts input data
(2) Process: this is the operation of converting data (raw fact) read into
the computer into a finished and meaningful product (information) i.e.
a program or instruction in execution
(3) Output: this is the terminal point where information is being
produced i.e. computer generates information as output.

DATA: this can be defined as a representation of raw facts or figures which


are meaningless; thus require processes in order to produce a meaningful
entity known as information.

Information: information can be defined as processed, structured, well


defined and meaningful data. For instance, a mark obtained by a 100 level
student in CSC 102 is a data used to process the students grade point
average (GPA), which is known as information.

Why do we need the computer?

The benefit derived from the computer can be attributed to the following:

High speed: computer is a very fast machine that can perform at a


very high speed measured in nanoseconds or more.

2
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Accuracy: the result produced from the computer is reliable as long
as the input is entered correctly
Vast storage capability: computer can store large data, information,
and instruction in a small-size memory which has enough/very large
storage location or places.
Economically: computer is very cheap to buy and can perform tasks
that would not otherwise be feasible or cost effective by other system
or machines
Versatility: computer can be used at a very wide range of application
such as engineering, science, technology, government etc.
Durability: computer can work for hours, days, weeks, months, years
non-stop without getting tired.

Types of Computer

Basically there are two types of computer namely; analogue computer and
digital computer. The comparison between the two is hereby presented in a
tabular form below;

ANALOGUE COMPUTER DIGITAL COMPUTER


Represents physical variable by Represents non-physical variable by
continuous measurements of discrete, coded pattern (digital data),
analogue quantity (e.g. voltage, such as perforations in cards or
temperature) presence of pulses
Setup an analogue of problems breaks down problems into
arithmetic form
Basic operations performed by Operations performed by relatively
relatively few single-purpose devices many interchangeable arithmetic
(such as integrators, summers, devices (adders, registers,
multiplier, resolvers etc.) accumulator etc.)
Relatively few device needed, hence Many devices needed, hence high
comparatively low cost and easy of cost and difficult programming,
programming; Distinct element used identical elements used in sequence
for each operation (parallel (primary series operation).
channels).
Accuracy limited to about one part in Unlimited accuracy (one part in
10,000. billion or more).
Data storage (memory) dispersed in Data storage concentrated in space,
various non-interchangeable devices. interchangeable and unlimited
duration.

3
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Represent physical or mathematical Represent numbers, letters, or
quantities in a continuous form. symbols in a discrete or
discontinuous form.
Mostly used as special- purpose Mostly used as a general device.
device.

When a computer makes use of both analogue and digital components and
techniques; it is called HYBRID COMPUTER. Such a computer requires
Analogue-to-Digital and Digital-to- Analogue converters; which would make
analogue data acceptable to a digital computer & vice versa.

The computer system

A system: This is a collection of an inter-related or inter-dependent


components or elements working together as a whole with the aim of
accomplishing a common goal. Examples are: Accounting system, Banking
system, Circulating system, Producing system, Computer system etc. A
Computer System as a system consists of 3 main subsystems which are:
Hardware subsystems, Software subsystems, and Humanware
subsystems.

The Computer Hardware Subsystem

The computer hardware subsystem is made up of all the electrochemical


gadgetry that form the physical part of the computer system which can be
seen and touched. This can be broken down into 2 major components or
functional units, namely; the peripheral, and the Central Processing Unit
(CPU).

1. Peripheral devices/units: These consist of all the components that


are externally attached to the CPU that do not form the part of CPU
i.e. the Input unit, Output unit and Auxiliary storage.
INPUT UNIT: This provides medium through which data is
being fed into computer i.e. it accepts input data & transmit the
data as a series of electrical pulses into the CPU e.g. mouse,
joystick, scanner, light pen, E-tablet or digitizer, keyboard, card
reader, punch card.

4
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
OUTPUT UNIT: provides the medium by which the results of the
computer operations on input data are transmitted to the user. It
retrieves the information in computer readable form e.g. printers,
computer monitor, speaker etc.
AUXILIARY STORAGE: is a storage unit of larger capacity than
the main memory, for external (off-line) storage of data and
programme in readable form. Unlike the main memory, it is
non-volatile and thus provides a means of permanent storage of
information to be processed by the computer e.g. floppy diskette
drive, magnetic tape drive, magnetic disk drive, hard disk drive,
CDROM, flash drive, memory card etc. It is also known as Back-
up storage.
2. Central Processing Unit: This is the heart & central controller of all
activities of a computer. It consists of main memory, Control unit,
Arithmetic Logic Unit (ALU).
o Main memory: This is known as memory unit or primary
memory which serves as the brain of the computer that
provides temporary storage medium for input data of
programme. Before the computer can solve any problem,
all other related (data and instructions) must be loaded
into the memory unit. This comprises RAM and ROM.
o RAM- Random Access Memory, this is a volatile memory
that can hold data and instruction temporarily, data can
easily be lost if there is power interruption.
o ROM- This is a non-editable memory whose contents
cannot be change but can only be read i.e. it allows solely
read from but disallow written to its contents.
Control unit: This is main controller of activities of the
computer system. It selects relevant instruction from the stored
program(main memory) and interprets them, coordinates the
flow of data and program from the entry point of input, through
the memory for storage, to the ALU for execution and finally to
the output terminal.
Arithmetic Logic Unit (ALU): is the circuitry system for
performing both the arithmetic and logical operations on data
and program.

The Computer Software Subsystem

5
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
The computer software subsystem is a collection of all program
modules that are required by a computer system, to determine what the
computer does and how to do it. Unlike the computer hardware, it cant be
seen and touched; It can broadly be divided into 2 categories viz: SYSTEM
SOFTWARE and APPLICATION SOFTWARE.

SYSTEM SOFTWARE: This is a collection of all program developed


basically to control and coordinate the activities performed by the computer
hardware, as well as to manage the operation of all other software
(Application software). This may include Operating System (OS), translators
& Utility Software.

OPERATING SYSTEM: This is a set of program which when


installed into the computer allows other program to run on it.
On the other hands, Operating system is a set of program that
control, supervise and manage computer resources (memory,
processors, files, printers etc.) judiciously, as well as, allowing
execution of users programs in order to solve many users
problem. E.g. MS-DOS, PC-DOS, Windows, UNIX, LINUX.
Functions of Operating system
1. Resource sharing
2. Memory management
3. Processor management
4. File management
5. Interrupt handling
6. Security
7. Networking
Types of Operating System
1. Single User Operating System: this allows a user to run a
program at a time.
2. Multi-User Operating System: this allows several users to run
a program at a time.
3. Distributed Operating System: this provides facilities to
support networking.

TRANSLATOR: This is a program that takes as an input a


program written in one programming language (source
language)and produce as an output a program in another
language (Object or Target language). Besides , a translator can

6
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
also be viewed as an interface between the Source program and
the Object program i.e.

A program written in one programming language (HLL & Assembly


language) that serve as an input to the translator is known as
Source Language or Program while a program written in a
language (Assembly& Machine Language or Program) that serves
as an output to the translator is known as Object or Target
Program.

The 3 types of translators are ASSEMBLER, INTERPRETER, and


COMPILER.

Assembler: This is a program translator that takes as an input


a program written in assembly language and produces as an
output the machine language equivalent form of the same
program.

Interpreter: is a language translator that takes input program


in high-level language and produces its equivalent machine
language conversion in the form of an intermediate target
code as an output. Interpreter program needs to undergo
translation process each time or at every time of execution.
Interpreter translates high level language program line by line
or statement by statement.

COMPILER: This does the same translation activities as the


interpreter i.e. it converts source program to high level language
to its equivalent machine language. Unlike the interpreter,
compiler translates the whole high level program (source
program) at once, so that execution is done easily and quickly
without undergoing translation process at every time of
execution. Besides, compiler generates object code or diagnoses
and reports syntax error found in source program.

UTILITY SOFTWARE: These are service programs which


provide facilities need by the computer as the users to perform
common routine tasks. Examples are Debugging aids, file
copying, file sorting, link/loader etc.

7
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
APPLICATION SYSTEM: These are set of programs that develop
basically with the intent of providing solution to different users programs or
to perform certain task. There are 2 categories of this software.

1. Generalised Application Package: is application software


designed in a standardised and customisable form, usually
as a marketable product for solving general users programs.
Examples are:
o Word processing package - MS-WORD, WORD
PERFECT, WORD STAR.
o Spread sheet package - MS-Excel, Lotus 1-2-3.
o Desktop publishing/Graphics design - PageMaker,
CorelDraw, Photoshop.
o Database management system - MS Access, Oracle,
Apache SQL
o Presentation packages - MS PowerPoint, Rolex.
o Computer Aided Design (CAD) packages - AutoCAD,
Autodesk, Inventors
o Statistical packages - SPSS, SAS.
2. User Application Packages: is an application designed to
perform specific task or to solve specific a users problem
e.g. Payroll program, Medical management system,
accounting program, banking program etc.

THE HUMANWARE SUBSYSTEM

This is referring to as computer system users (Nave, Programmer, Expert,


and Sophisticated).

RAD:- RAPID APPLICATION DEVELOPMENT


JAD:- JOINT APPLICATION DEVELOPMENT
VBA:- VISUAL BASIC APPLICATION
CASE:- COMPUTER AIDED SOFTWARE ENGINEERING
PERT:- PROGRAM EVALUATION AND REVIEW
EPROM:- ERASABLE PROGRAMMABLE READ ONLY MEMORY
VDU:- VIDEO/VISUAL DISPLAY UNIT
P.C:- PERSONAL COMPUTER
SVGA:- SUPER VISUAL/VIDEO GRAPHICS ADAPTER
HDD:- HARD DISK DRIVE
CRT:- CATHODE RAY TUBE
LCD:- LIQUID CRYSTAL DISPLAY

8
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

INTRODUCTION TO PROGRAMMING LANGUAGE

What is a programming language?

A programming language is a communication means between the


user (programmer) and the computer. It is a tool use by a programmer to
instruct the computer in other to solve problem. Like English language,
programming language also possesses syntax and semantics.

Syntax of a language is a rule that governs the way symbols,


statements, and grammars are formed or constructed.
Semantics of a language is a rule that governs it meanings.
Meanings is what happens when a programme is executed or
the result of execution of a program or what signal/outcome
produce as a result of the use of language.

What is a program?

A Programme is set of coded instruction written and given to


computer in order to solve problem or to carry out specific task.

What is programming?

Programming is art of writing program using programming language.

Who is a Programmer?

A programmer is an expert that specialises in using programming


language to instruct the computer in order to solve problem i.e. the
one who writes computer program.

TYPES OF PROGRAMMING LANGUAGE

Basically, we have 2 types of programming languages which are

1. Low level language


2. High level language

Low-level language

9
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
This is a 1st form of language developed basically for the computer
system. There are 2 types of low-level language viz:
Machine Language: This is a computer-understandable
language developed mainly for the operation of the
underlying hardware of a computer system. Instruction
written in machine language consists of series of binary
format code (bits), which does not require translator for its
execution, so there is fast execution. Programming with this
language is highly time-consuming, tedious and the most
error prone process.

Assembly language: This is another type of low-level


language which is very close to machine language and has its
instruction in a symbolic or mnemonic form. It is machine
dependent requires a translator (Assembler) for the computer
to understand, not too time consuming, tedious and less
error prone than machine language. It does not consume
memory space and execution is slow compared to machine
language.

High-level language: This is very close to human language


as it consists of instruction written in English-like and
mathematical notation. High level language is not machine-
oriented/dependent rather it is a problem-oriented language
which is portable and required translators (computer or
interpreter) for the computer so understand. It is easy to
learn, understand and execute, also not too time consume,
least error prone but slow in execution has compare to low
level language. Categorically there are two types of high level
language:
o Procedural language
o Declarative language

Examples of high-level programming language are: BASIC,


FORTRAN, PYTHON, JAVA, C#, C/C++, PASCAL etc.

PROPERTIES OF GOOD PROGRAMMING

1. ACCURACY: It must be correct, working according to


specification.

10
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
2. MAINTAINABILITY: It must be easy to change, modify and
maintain.
3. EFFICIENCY: It must be fast in execution and be able to occupy
less memory space in term of storage.
4. RELABILITY: It must be able to produce expected result and
never crash.
5. PORTABILITY: It must be machine independent and must be
able to transfer from one machine (computer) to another.
6. DOCUMENTATIONABILITY: It must be easy to document or
keep for future use or further program
7. USABILITY: It must be useful for its purpose.
8. FRIENDLINESS: It must be user-friendly.
9. INTERACTIVITY: It must be interactive for user.
10. SIMPLICITY: It must enable the programmer to state a
computational solution to specific problem in a notation which
is both formal and human intelligible.

STEPS INVOLVE IN WRITING PROGRAM (PROGRAMMING)

There are 5 basic steps to good programming:

1. Identification and understanding the problem.


2. Development of an algorithm
3. Coding
4. Compilation, debugging and test-running.
5. Documentation.

IDENTIFICATION AND UNDERSTANDING THE PROBLEM: The


problem to be solved has to be defined, clearly stated and known in
advance. This involved a total analysis of the problem at hand.
DEVELOPMENT OF AN ALGORITHM: Once the problem has been
well established, there is need to find a solution to the problem by
designing the logic of the program using different design tools,
( flowcharts, pseudo code, data flow diagram).
CODING:-This involves the process of programming by writing
codes for the designed algorithm or procedures i.e. transcribing the
method defined into a computer executable instruction using
suitable programming language.

11
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
COMPILATION, DEBUGGING, AND TEST-RUNNING: This involves
the process of key-in the source code into the computer using
appropriate text-editor or IDE(Integrated Development
Environment) of the selected language, converting the source code
into computer-understandable code, during which there may be
errors (syntax error)found in the program, which requires
correction by fixing out the error and change it to the correct
syntax for the program to perfectly execute, finally, using various
values to test the correctness of the program as it is being
executed.
DOCUMENTATION:- There is need for keeping record of all the detail
description of every method/procedure used in solving the program, as
well as explanation on how the program function and uses.
Consequently, good documentation gives room for continuity and
maintainability.

BUGS AND DEBUGGING

BUGS means errors found in programming while Debugging refer to the


terminology used to describe the act of removing or correcting of the
errors found in program so that the program will be error-free and
perfectly executed.

Two types of BUG/Errors found in program:

Syntax error
Semantic error

1. SYNTAX ERROR

This is an error caused due to violating the syntax rule of the


language. This error can be identified by the translator (computer or
interpreter), which halt the execution of the program.

2. SEMANTIC ERROR

This is error due to semantic rule of a language, this error cannot be


identified by the translator (compiler) as this does not halt the
execution of the program but makes the program produces
unexpected result and can only be diagnosed by the programmer.
This is known as LOGICAL ERROR.

12
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
BASIC STEPS OF DEBUGGING

i. Recognise that a bug exists.


ii. Isolate the source of the bug.
iii. Identify the cause of the bug.
iv. Determine a fix for the bug.
v. Apply the fix and test it.

ALGORITHM DESIGN

WHAT IS AN ALGORITHM?

An algorithm is a finite set of well-defined step-by-step methods,


procedures or rules for solving any given problem. A good algorithm
must have the following properties:
1. It must be correct
2. It must be definite
3. It must terminate i.e. it must have a good beginning and a
specific end.
4. At the end of every step the next step must be well defined.
5. It must contain no ambiguity i.e. every step must be clearly
stated.
6. It must be composed of finite numbers of steps.

COMPONENTS OF ALGORITHM

There are three components of algorithm:

I. SEQUENCE
II. SELECTION and,
III. ITERATION
SEQUENCE: This involves specification of steps of statements or
methods in a specific order i.e. every step of methods is written
in order they will be executed.
SELECTION: this involves specifying step of methods or
instruction by making decision based on condition that must be
satisfied, i.e. execution of set of instruction will be based on
making some choices/a choice from various options available.
ITERATION: This means repetition or looping, which refers to
repeating the flow of execution of set of statement for a specific
number of times or based on specific condition.

13
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
TWO WAYS OF DESIGNING ON ALGORITHM

I. PSEUDOCODE
II. FLOWCHART
PSEUDOCODE: This is an English-like representation of an
algorithm. Pseudocode cannot actually run on computer
because it is not an actual computer programming language,
rather it merely provide a convenient method that will assist
programmer to think out a program before attempting to write
it in a particular programming language.

EXAMPLES:

1. Develop an algorithm (pseudocode) to find the sum of two numbers.

Step 1: enter the first number, say A

Step2: enter the second number, say B

Step 3: calculate the sum of the two numbers, i.e. C = A + B

Step 4: display the result i.e. print C

Step 5: exit.

2. Write an algorithm to find the area of a circle


Area = r2

Step 1: Set pie= 3.142

Step 2: Read in value for radius i.e. Read r

Step 3: Compute Area = pie *r *r

Step 4: Display Area

Step 5: Stop

3. Write a Algorithm to find the Area of a triangle

A=1/2bh
Step 1: Obtain value for base i.e. b
Step2: Obtain value for height i.e. h
Step 3: Multiply base, height, and half i.e. Set A=1/2*b*h

14
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Step 4: Print A
Step 5: Stop

4. Design an Algorithm (pseudocode) to find the larger of 2 numbers


Step 1: Read A, B
Step 2: Is A>B? If yes go to step 3, otherwise go to step 4
Step 3: Print A
Step 4: Print B
Step 5: Exit.

5. Design an Algorithm (pseudocode) that generates all integers between


1 and 100, and compute their sum.

Step 1: [Initialize counter and sum] set count=1, set sum =0


Step 2: Repeat step 3 to step 5 while count <=100
Step 3: Set sum = sum + count [Accumulate sum]
Step 4: [Display count] print: Count
Step 5: [Increment counter] set count = count + 1
[End of Step 2 (while) loop]
Step 6: Print sum [Display value of sum]
Step 7: Stop

FLOWCHART: This is a graphical, pictorial or diagrammatical


representation of an algorithm. It is equally used to develop the
logic of a program. Also, It illustrates to sequential order of the
steps that must be taken by the computer in processing input
data to produce meaningful results. There are some rules
guiding the way flowchart is drawn. This rules include the
following:
1. Standard flowchart symbols must be used.
2. Symbol templates must be used and not freehand drawings
3. Avoid cross of flow lines.
4. It should not be cramped.
5. Adopting a consistent direction of flow of instruction and boxes
except when there is need to loop
6. A label containing explanatory notes should be appended.

There are 2 major types of standard flowcharts, these are:

I. Systems flowchart
II. Program flowchart

15
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Symbols used in flowcharting involve:

1. START/STOP SYMBOL: use to denote the beginning and


ending of a flowchart.

2. INPUT/OUTPUT SYMBOL: use to denote making data available


for processing (input) and producing the data (output).

3. PROCESSING/COMPUTATION SYMBOL: Use to denote the


execution of an operation or event

4. DECISION SYMBOL: Use to indicate the point at which the


decision or selection are made.

5. CONNECTION SYMBOL: Use to denote


continuation/connection of a part of the chart to another part
of the chart and can be used to mark entry and exit point in a
flowchart either on the same page or another page.

6. ARROW SYMBOL: Used to denote the direction of flow

16
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
7. INITIALIZATION SYMBOL: Optionally used to denote the
parameters initialization

EXAMPLES:

1. Develop an algorithm(flowchart)to find the sum of two numbers

START

ENTER a,b

C=a+b

Print c

STOP

Start
r 2
2. Design a flowchart to find the area of a circle A =

Pie= 3.142

Read r

A = pie*r^2

Print A

17

stop
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

3. Design a flowchart to find the area of triangle (A=1/2bh)


Start

Input b, h

A=1/2*b*h

Print A

Stop

4. Design a flowchart to find the larger of two numbers

Start

Read A, B

No

Is A > B?
Yes

Print B

Print A

18
Stop
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

5. Design a flowchart to generate all positive integers between 1 to 100


and compute their sum

Start

Count = 1, Sum = 0

No Is count <= 100?

Yes

Print Sum Print Count

Sum = sum + count


Count = count + 1

Stop

19
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

PROGRAMMING WITH BASIC

WHAT IS BASIC?

BASIC stands for Beginner All-Purpose Symbolic Instruction Code;


BASIC was regarded as a programming language which was developed in
1964 at Dortmouth College, USA by professors John Kemeny and Thomas E.
Kurtz in order to teach beginner the construction of programming theory. It
is used to solve problems covering a wide range of applications on many
different type of digital computer. Also used for users who are not well-
trained programmers.

BASIC is considered as Beginners language for the following reasons:

It is easy to understand and quick to learn.


It is relatively easy to code
It is suitable for most application.
It is made up of simple grammar and relatively low number of
statements.
It is the most commonly used programming language for mini and
micro computers because of its small interpreter.
It provides direct instruction between the user and the computer.

20
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Version of BASIC language: Microsoft BASIC, Burmese BASIC,
Extended BASIC, Cassette BASIC, MFBASIC, Small BASIC, GW-BASIC,
Q-BASIC, etc. they all features in common but the systematic difference
between them are associated with hardware on which they are designed
to be used.

IS BASIC, A HIGH-LEVEL LANGUAGE?

BASIC is known as high-level language since it consists of statement


written in English-like words and mathematical notation, BASIC
interpreter provided by DOS include GW-BASIC, BASICA and QBASIC
(Quick BASIC).

BASIC CHARACTER SET

Character means letters, digit, and symbols. The collection of


characters recognised by BASIC programming language is referred to as
BASIC CHARACTER SET. The following are BASIC character sets:

I. Numbers/digits (0-9)
II. Alphabets/letters (A-Z, a-z)
III. Decimal point (.)
IV. Blank character
V. Grouping characters e.g. colon, semi-colon, comma, single and
double quotes/apostrophe, and parenthesis.
VI. Arithmetic operators e.g.=,+,*,-,/,^,\
VII. Comparison operators e.g. =,<,>,<=,>=,<>
VIII. Underscore (_)

BASIC DATA TYPES

Data types refer to the type of value that a particular data represent.
Data in BASIC can be classified into two types:

Numeric types and,


Character string.
1. NUMERICAL TYPES: These are subdivided into:
a. INTEGER NUMBER: Contain neither decimal point nor
exponent i.e. only whole numbers e.g.100, +457,-32 etc.
b. REAL NUMBERS: Can contain either decimal point or exponent
or both together with whole numbers e.g. 12.45,-18.27,
+15.47e-8 etc.

21
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
c. NUMERICAL CONSTANT: are static value(s) that BASIC
interpreter uses during program execution, which may either be
positive or negative numbers.

There are 5 different types of numeric constant:

INTEGER CONSTANT: they are either positive or negative


whole numbers e.g.-12,+45
FIXED POINT CONSTANT: Are either positive/negative
decimal numbers or fractional numbers e.g. -40.7,54.5
etc.
FLOATING-POINT CONSTANTS: are either
positive/negative exponential figures e.g. 26.17E,-47.5E
etc.
HEXADECIMAL CONSTANT: are base 16 numbers, which
must have the prefix & and H(&H)e.g. &H0A5, &HC47,
&HB4 etc.
OCTAL CONSTANTS: are base8 numbers, which must
have the prefix &0 or & e.g. &0745, &213, &6, etc.

2. CHARACTER STRINGS: This is also known as STRING CONSTANT,


which is sequence of not more than 255 alphanumeric character
(letters, digits, symbols and blank spaces) enclosed between identical
inverted commas or a pair of identical quote/apostrophe-......... e.g.
THE FEDERAL UNIVERSITY OF TECHNOLOGY, AKURE, x+y.

IDENTIFIERS, VARIABLES AND CONSTANTS


What is an identifier?

Identifier means a name given to program entities/elements, such as


variables, constants, function, procedure, reserved words, etc. which made
up of alphabets, digits and/or underscore, that must start with a
letter/alphabet.

What is a variable?

A variable is name given to data-items with changing values. A variable can


be referred to as identifier that represents quantity/data-item capable of
accepting different values throughout the course of program execution. On
the other hands, a variable can represent a memory location storing non-
static values.

22
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
What is a constant?

A constant is name given to data-items with static values. A constant can be


a quantity/ data-item capable of accepting fixed values throughout the
program execution.

Rules guiding variables formation


I. It may comprise alphabets, digits, and underscore but must begin
with a letter
II. It must not be more than 40 character in length
III. It must not be spacious, i.e. no blank space
IV. It must not contain any special character except underscore
V. It must be BASIC reserved words.

THE FOLLOWING ARE EXAMPLE OF GOOD VARIABLES

1. Length
2. Breadth
3. A102
4. Sum2
5. Volume_Of_Sphere

THE FOLLOWING ARE EXAMPLE OF BAD VARIABLES

1. Circle-4 --- Invalid because it contain special character -


2. 521E --- Invalid because it starts with digit.
3. Area of a circle --- Invalid because it contain blank spaces
4. Sum. --- Invalid because it contain special character .
5. END --- invalid because it is BASIC reserved words.

A VARIABLE ENDING WITH THE FOLLOWING CHARACTER IMPLIES A


TYPE DECLARATION:

$ STRING VARIABLE e.g. name$, matriculation number$, sex$

% INTEGER NUMBER e.g. count%, sum%, A%

! SINGLE PRECISION (4 bytes) e.g. volume!, length!,

# DOUBLE PRECISION (8 bytes) e.g. Area#, Total#

BASIC OPERATORS AND EXPRESSIONS

23
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
OPERATOR MEANING ALGEBRAIC BASIC
EXPRESSION EXPRESSION
+ Addition a+b a+b
- Subtraction a-b a-b
* Multiplication a*b a*b
/ Division a/b a/b
\ Integer division a/b a\b
^ Exponentiation Ab A^b
= Assignment A = b+c A = b+c

THE BASIC HIERACHY OF OPERATOR PRECEDENCE IS:

1. All exponentiation ^ first followed by


2. All multiplication * and/or division / from left to right.
3. Then, all addition + and/or subtraction - evaluate from left to
right.

NOTE: Expression within parenthesis, function are evaluated first before any
other operation is carried out.

EXAMPLES

1. Write the BASIC statement or expression for the following:


a) xy+z
b) 4y/27-5c/x
c) b+ (b2-4ac)
d) S=ut+1/2at2

SOLUTION: BASIC EXPRESSION

a. Xy+z - x * y + z
b. 4y/27-5c/x - 4 * y / 27 5 * c / x
c. b+ (b2-4ac) - -b + (b ^ 2 4 * a * c) ^ 0.5
d. S=ut+1/2at2 - s = u * t 1 / 2 * a * t ^ 2

2. Evaluate the following expression given that x=2, y=3, z=5, b=10, a=4,
c=4
a. Xy+z
b. 4y/3-5c/x

c. b+ b2-4ac)

24
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
SOLUTION: BY USING BASIC HEIRACHY OF OPERATOR PRECEDENCE

a. Xy+z - x * y + z = 2 * 3 + 5 = 6 + 5 = 11
b. 4y/3-5c/x -4 * y / 3 5 * c / x = 4 * 3 / 3 5 * 4 / 2 = 4 10 = -6
c. b+ (b2-4ac) - -b + (b ^ 2 4 * a * c) ^ 0.5 = -10 + (10 ^ 2 4 *
4 * 4) ^ 0.5 = -10 + (100 -64) ^ 0.5 = -4

RELATIONAL OPERATORS

The following relational operators are used in testing a relation between two
entities

OPERATORS MEANING EXAMPLES


< Less than A<B
> Greater than A>B
= Equal to A=B
<= Less than or equal to A<=B
>= Greater than or equal to A>=B
<> Not equal to A<>B

LOGICAL OPERATOR

These are based on conditional statements which are either true or false. We
have the following logical operators:

-AND logical AND indicate that logical expression X AND Y, is true (T) if
and only if X is true and Y is true

-OR (inclusive OR) indicate that logical expression X OR Y is true (T), if


either X is true OR Y is true or both

-XOR (exclusive OR) indicate that logical expression X XOR Y is true if


either X is true or Y is true, but not both

-NOT (logical operator NOT) indicates the negation or the reverse of a truth
value, i.e. NOT Y is true if Y is false, and false is Y is true.

SYSTEM BUILT-IN FUNCTIONS

25
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
These are system pre-coded routine, which are normally built as part of the
language interpreter/compiler available in its library: common built in
functions that are for solving mathematical problems are as follows:

SQR (x): computes the non-negative square roots of X.


ABS (x): computes the absolute value (non-negative) of X
RND (x): generates a random number of X
SIN (x): computes the sine of X where X is expressed in radian.
COS (x): computes the cosine of X where x is expressed in radian.
TAN (x): computes the tangent of X where X is expressed in radian.
ATN (x): compute the arc tangent of X
LOG (x): computes the natural logarithm of x
EXP(x): computes the exponent of X
INT(x): returns the integer part of X
SPC (x): returns the number of blank spaces
TAB(x): returns output item to be displayed X + h column of all
printing section of the output screen

BUILT-IN STRING FUNCTION

LEN (TEXT): return the length of string Text in terms of the


number of data has the string. for example: LET A$= God
Morning

PRINT LEN (A$)

The two statements above will generate 12 as the output.

LEFT (TEXT, SIZE): use to get the out string of the leftmost
number of the character of a string argument: for example:

LET A$= Good Morning

PRINT LEFT$ (A$, s4)

These output will be good

RIGHT$(text, size): use to get the substring of the rightmost


number of character of the string argument. For example:

LET A$= Good afternoon

PRINT RIGHT $ (A$, 4)

26
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
The output is noon

MID $(Text, Starting Pont): returns a substring at the nth


position (starting point) of a string text to the end (last
character) of the string. For example:

LET A$= Good Morning

PRINT MID $ (A$, 6)

The output is: morning

VAL: The val function returns the numerical value of string of


digit. For example:

IF B$=576, then VAL (B$)= 576

STR$: This returns string constant of numeric digit. For


example: IF A=3.142, then STR$(A)=3.142
CHR$= This returns character equivalent to the ASCII value for
example: PRINT CHR$(65)

This will produce A as output.

ASC: This return the equivalent ASCII value of any given


character for example:

PRINT ASC (A)

This produces 65 as the output.

BASIC STATEMENTS

REM Statements: this is the statement use in BASIC to specify or


indicate comment or to give remark. Commenting in program allows
the programmer to describe the detailed description of operation
involved in the program or to give explanation about the program.

Syntax: nn REM Text/string/expression

Where nn (optional) line number

Examples:

27
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
I. 10 REM program to compute area of circle.
II. REM Welcome to BASIC environment
NB: REM statement can come anywhere in the program; beside an
apostrophe can be used in place of REM statement as in: 20 Program to
display circle area.

INPUT Statements: This statement is used to specify input in BASIC


program. Input statement is used to allow input data value to be
read / fed in at the point of execution of the program and placed into
the specified variables written in front of the input statement.

Syntax: nn INPUT prompt;/, variable list separated by comma or

Nn INPUT variable list separated by comma.

Examples:

I. 10 INPUT enter value for A:; A


II. 20 INPUT enter value for radius:, R
III. INPUT length, breadth, height.
IV. 15 INPUT enter number of entries in the array:; N

LET Statement: this is used to perform computational of expression,


copying the content of a variable to another, assign value to a
variable/constant, or to set initial value for a variable. It may also
refer to as ASSIGNMENT Statement, since the chief operator involved
is the assignment operator =.

Syntax: nn LET identifier= expression/values/variables or

Nn Identifier= expression/values/variable

Examples:

I. 5 LET area = length*breadth


II. 10 LET pie = 3.142
III. 15 LET c = A
IV. Volume= 4/3*pie*r^3

PRINT Statement: This is to display output data items on the screen


of the monitor/VDU at the point of execution of the written program.

28
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Syntax: nn PRINT string/values/variables/expression

Examples:

I. 05 PRINT welcome to CSC 102 class


II. 10 PRINT sum of two numbers=, sum
III. PRINT product of two number=; A*B
IV. PRINT Volume, area, height
V. 20 PRINT 54; *;7;=; 54*7

END Statements: this statement mark the terminating point for the
program. No executable statements should follow this statement since
execution of the main program ends at this statement.

Syntax: nn END

Examples:

I. 100 END
II. END

STOP Statement: this is use to indicate pause/halt in the execution


of the program. Executable statement can come after this statement
as this marks the temporary termination of the program

Syntax: nn STOP

Examples:

I. 20 STOP
II. STOP

PRINT USING Statement: allows printed output to be formatted thus


specifying the appearance and location of each data items

Syntax: nn PRINT USING format string; data items/expression

Examples:

I. 100 PRINT USING #,###.##; amount


With the above PRINT USING statement, assuming value placed
in the amount is 25421.7421, then the output to be statement
will be 25,421,74

29
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

PRINT TAB Statement: allows the programmer to have a greater


control over the display of the output data-items by providing
opportunity for the data items to be placed on a specified column
through which a table of output can be easily generated.

Syntax: nn PRINT data-item; TAB (m); data-item2

Where nn= line number, m= column number

Examples:

I. 10 PRINT ITEM; TAB(20); PRICE


II. 20 PRINT BOURNVITA; TAB(20); #600.00
III. 30 PRINT GOLDEN MORN; TAB(20); #450.00

Execution of the above 3 PRINT TAB statement will yield;

BOURNVITA #600.00
GOLDEN MORN #450.00

READ and DATA Statement: These two statements are used in pair
to allow input data items to be used in program. Unlike INPUT
statement, READ and DATA statement not only allow specification of
variable-list or data-item with READ but also gives room for the
provision of the corresponding data values for each of the specified
variables indicated by READ using the DATA statement written to
form part of the source code.

Syntax: nn READ variable-list separated by comma

nn DATA data-value-list separated by comma

Example:

I. 10 READ A,B,C,D

30 DATA 20,15, 7, 24.5

BASIC SAMPLE CODES

1. Write a BASIC program to display welcome message

30
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
SOLUTION

10 REM program to display a welcome message

20 PRINT welcome to CSC 102 Tutorial class

30 END

2. Design a BASIC program to compute Area of a circle

SOLUTION

5 REM program to compute area of a circle

10 LET pie = 3.142

20 LET Area = pie*r^2

25 PRINT area of a circle=; Area

30 END

3. Write a BASIC program to evaluate the following :


a. V= 4/3 r 3
b. A= (a+b)h
c. Area= /360 r 2

d. Perimeter= 2(L+b)

SOLUTION:

a. 10 REM program to compute the volume of sphere

20 LET PIE = 3.142

30 INPUT R

40 LET V = 4 / 3 * PIE * R ^ 3

50 PRINT V

60 END

b. REM program to compute the area of trapezium

INPUT Enter value for a,b,h; a, b, h

LET A = 1 / 2 * (a + b) * h

31
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT Area of trapezium=; A

END

c. REM program to solve the area of a sector

LET PIE = 3.142

INPUT obtain value for value r:; r

LET Area = tita / 360 * PIE * r ^ 2

PRINT area of sector=; Area

END

d. REM program to compute the perimeter of a rectangle


INPUT enter value for length:; L
INPUT enter value for breadth:; b
LET perimeter = 2 * (L + B)
PRINT perimeter of a rectangle is; perimeter
END
e. REM program to accept a student name and matric number
INPUT what is your name?; Name$
INPUT what is your matric number MatricNO$
PRINT: PRINT students name is:; Name$
PRINT Your matric number is:; MatricNo$
END

PROGRAM BRANCHING AND LOOPING

All the program we considered so far are sequential in nature,


however, it is the ability of the computer to ,make a logical decision and then
carry out an appropriate set of orders, based on the outcome of those
decision.

The branching control structure allows the programmer to select a set


of instructions for execution from group of instructions. Basically, there are
two types of branching viz:

I. Unconditional branching: this involves the transfer of control flow


or jump to a specific part of the program each time, an
unconditional branching statement is encountered in the course of
executing the program.
II. Conditional branching: this involve the performing an appropriate
set of logical operation based on the outcome of the tested logical

32
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
condition or expression specified by the designated conditional
branching statement

NB: branching may also be called SELECTION.

BASIC BRANCHING STATEMENT

1. IF-THEN Statement: this is a one way branching statement that


allows the execution of a set of instructions, if and only if the
prevailing condition are evaluated to be true.

Syntax: IF (logical expression) THEN

Statements

END IF

NB: logical expression is a Boolean expression containing logical


condition required to be evaluated to be true or false

Examples: IF (A > B) THEN

PRINT A is greater

END IF

NB: from the example above, the statement PRINT A is greater will
be executed only if value of A is greater than B and nothing
happens otherwise.

2. IF---THEN---ELSE Statement: this is a two way branching


statement that allow execution of a set instructions based on either
the prevailing condition is evaluated to be true or false.

Syntax: IF (logical expression) THEN

Statement A

ELSE

Statements B

END IF

33
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Example: IF (A > B) THEN

PRINT A is greater

ELSE

PRINT B is greater

END IF

NB: from the expression above, the statement PRINTA is greater


will be executed only if value A is greater than B, but if A is not
greater than B, this cause the statement PRINT B greater than A
to be executed.

3. IF---THEN---ELSEIF Statement: this is a multi way branching


statement that allows execution of a set of instructions based on
the result of evaluation of some tested prevailing conditions.

Syntax: IF (logical expression 1)THEN

Statement 1

ELSEIF (logical expression 2)THEN

Statement 2

ELSE IF( logical statement N) THEN

Statements N

ELSE

Statement N+1

END IF

Example: assuming we are given a table of score grade for CSC 102
as represented below:

SCORE GRADE POINT

70-100 A 5

60-69 B 4

34
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

50-59 C 3

45-49 D 2

40-44 E 1

BELOW 40 F 0

And we are about to design a BASIC program to generate the Grade


and Print for a student.

REM PROGRAM to test for score and generate grade, point for a
student

INPUT enter the student score in CSC 102; score

IF (score >=70 AND score <=100) THEN

LET GRADE$=A: LET POINT = 5

ELSE IF (score>=60 AND score <=69) THEN

LET GRADE$= B: LET POINT = 4

ELSE IF(score>=50 AND score<=59) THEN

LET GRADE$= C: LET POINT= 3

ELSE IF (score>=45 AND score <=49) THEN

LET GRADE$= D: LET POINT=2

ELSE IF(score>=40 AND score<=44) THEN

LET GRADE$= E: LET POINT= 1

ELSE

LET GRADE$= F

LET POINT= 0

END IF

PRINT GRADE is:; GRADE$

PRINT POINT is:; POINT

END

35
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
NB: this program above will allow any value between 0 and 100 to be read
and placed in variable score, test the value of score against the values
specified in each condition if the IFTHENELSEIF statement, then once
any of the condition evaluated to be true then the statement within that
block IF will be executed immediately; i.e. assuming we are given that score
= 53, this will allow the program to generate as output:

Grade is: C

Point is: 3

Since the condition: score>=50 AND score<=59 will be the only one
to evaluate to be true as the given score (53) lies between 50 and 59.

4. IF-Statement: This is a logical IF statement, which allows an


imperative statement that follows it to be executed strictly if and
only if the tested condition is evaluated to be true. Thais IF
statement has no ELSE nor END IF statement.

Syntax: IF (logical expression) THEN imperative statement

Example:

INPUT: enter any integer; I

IF (I MOD 2 = 0) THEN PRINT I; is an even number

END

NB: The above program will allow value to read into I, the value of I will be
use to divide by 2, then the integer remainder resulting from this
division process will be tested against zero, once there is a match
then the input will be: I is an EVEN number.

MOD: Integer Remainder Operator used to perform division and


return any whole number indicating the number i.e.

I MOD 2= I - (I \ 2) * 2

IF I = 15, then

15 MOD 2= 15 - (15 \ 2) * 2 = 5 7 * 2 = 15 14 = 1

36
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Therefore 15 MOD 2 = 1

5. GOTO Statement: this is an unconditional branching statement


that allows the control flow of the program to be transferred or
jumped to a specified label or line number in the program.

Syntax: nn GOTO label/line number

Example: 30 GOTO 70

70 END

NB: you should try to avoid unnecessary use of this statement has this
can cause indefinite/infinite execution of the program without end
(i.e. endless program execution): which in turn result into
damage/harm the processor and the memory of the system.

6. SELECT-CASE Statement: this is another form of multi-way


branching statement that allows execution of a set of instruction
only if there is a match after testing the value of an expression
specify by the SELECT CASE clause against the value indicated by
any of the CASE clause.

Syntax: SELECT CASE (expression)

CASE VALUE 1

Statements1

CASE Value 2

Statement 2

CASE Value n

Statement n

CASE ELSE

Statement n+1

END SELECT

37
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Example: write a BASIC program using SELECT CASE Statement to
examine the value of a numeric variable called TEMP and display one of
the following message; depending on the value assign to TEMP:

HOT if TEMP has the value 1.


WARM if TEMP has the value 2.
COLD if TEMP has the value 3.
VERY COLD if TEMP has the value 4.
OUT OF RANGE if TEMP has any other value.

REM program to demonstrate the operation of SELECT CASE

PRINT enter the value between 1 and 4

INPUT TEMP

SELECT CASE (TEMP)

CASE 1

PRINT HOT

CASE 2

PRINT WARM

CASE 3

PRINT COLD

CASE 4

PRINT OUT OF RANGE

END SELECT

END

BASIC LOOPING STATEMENT

LOOPING: refers to Iteration or repetition. Looping statement allow the


execution of a set of instructions for a specified number of times, or one or
more time until/while a particular condition is met. Basically, there are two
types of Looping:

38
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Counter control looping: this is involved of a portion of program
repeatedly, for a specified/definite numbers of times.
Sentinel- Control looping: this involves execution of portion of
program one or more time until/while a particular condition is
satisfied.

The following are BASIC looping statement:

1. FORNEXT Statement: this is most common and easiest counter-


control looping statement that allows definite number of the
execution of some portion of a program.

Syntax: FOR counter variable= initial value TO final value STEP


increment or decrement

Statement

NEXT counter variable

NB: for the execution to occur within the body of the FOR-NEXT loop, the
initial value must be less than or equal to final value (i.e. initial value
<= final value), with a STEP of increment value (i.e. positive whole
number), Also, when the initial value greater than the final value (i.e.
initial value > final value), there must be decrement (i.e. negative
whole number) specified for the STEP.

Besides, if there is no value specify for the STEP, the computer


will assume a default of value one or 1 for the STEP as an increment
for the execution to occur.

The number of execution for every FOR-NEXT statement is given


below:

Number of execution = (final value - initial value + STEP)/STEP

Examples:

i. write a BASIC to generate every integer between 1 and 100 inclusively

REM program generate every positive integer

39
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
FOR I = 1 TO 100

PRINT I

NEXT I

END

ii. write a BASIC program to generate odd numbers and compute their
sum between 1 and 1000

REM program to generate odd integer and compute sum

LET SUM = 0

FOR I = 1 TO 1000 STEP 2

PRINT I

LET SUM = SUM + I

NEXT I

PRINT SUM

END

2. WHILE-WEND Statement: this is sentinel control looping


statement that allow execution of portion of program one or more
times while a particular condition is satisfied

Syntax: WHILE

Statements

WEND

Example:

REM program to print even numbers and compute their sum


between 1 and 100

LET SUM = 0

LET I = 2

WHILE (I <= 100)

40
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT I

LET SUM = SUM + I

LET I = I + 2

WEND

PRINT SUM

END

3. DO WHILE/UNTIL Statement: this is similar to WHILE-WEND


Statement.

Syntax: DO WHILE/UNTIL (condition)

Statements

LOOP

NB: condition is tested before the execution of the statement in the


body of this loop. Also, execution may not take place if the
condition is not satisfied.

Examples:

I. REM program to generate odd number and their


products.

LET PRODUCT = 1

LET I= 1

DO WHILE (I <= 100)

PRINT I

LET PRODUCT = PRODUCT * I

LET I = I + 2

LOOP

PRINT PRODUCT

END

41
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
II. REM program to compute product of even number and
generate even numbers.
LET PRODUCT = 1
LET I = 2
DO UNTIL (I > 100)
PRINT I
LET PRODUCT = PRODUCT * I
LET I = I + 2
LOOP
PRINT PRODUCT OF EVEN=; PRODUCT
END

4. DO...LOOP WHILE/UNTIL Statement: this is another similar


sentinel control looping statement.

Syntax: DO

Statements

LOOP WHILE/UNTIL (condition)

NB: condition is tested after the execution of the statements that


form the body of the loop. Also, execution of statement will take
place at least once.

Examples:

I. REM program to generate odd numbers and products

LET PRODUCT = 1

LET I = 1

DO

PRINT I

LET PRODUCT = PRODUCT * I

LET I = I + 2

LOOP WHILE (I < 100)

PRINT PRODUCT OF ODD NUMBER=; PRODUCT

END

42
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
II. REM program to compute products of even &
generate even number

LET PRODUCT = 1

LET I = 2

DO

PRINT I

LET PRODUCT = PRODUCT * I

LET I = I + 2

LOOP UNTIL (I > 100)

PRINT product of even numbers=; PRODUCT

END

ARRAY

An array is a vector variable that holds a set of values at a time.


Arrays can be referred to as a collection of elements/data items of the same
type recognised, and identified by a name. Besides, an array can also be
viewed as a table containing a set of elements grouped into rows and
columns.

Basically, there are two types of array:

1. Linear array or one dimensional array: this can be in form of a row-


vector that may contain n-rows and 1 column or a column vector
that may contain 1 row and n-column.
e.g.

2 4 5 7 6 21

Table 1: A column-vector with one row and 6 columns

43
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

15

-1

50

74

Table 2: A row vector with 7 rows and 1 column

2. Multi-dimensional Array: this type of array has more than one


dimensional, which may contain n-rows and m-columns of
elements. The least kind of multi-dimensional array is two-
dimensional array which inform of a matrix that is a rectangular
table.

e.g.

2 4 54 32 667 331

13 -33 44 21 44 53

45 12 -509 304 423 45

Table 3: 2-dimensional array with 3 rows and 6 columns

The element in an array is refer to by the array name , with the


subscript or index position of this element enclosed in parenthesis
for example: given a table of numbers as follows:

2 4 7 3 20

TABLE A

To refer to the 2nd and 4th elements in the table above we say:

A(2) 2nd element in the table A i.e. 4

A(4) 4th element in the table A i.e. 3

44
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
i.e. Array name (index/subscript) A (2), A(4)

DIM STATEMENT: this is a statement use in BASIC to declare an array by


telling the BASIC interpreter that a particular variable is array with a size or
length specified in the declaration so as to allow the computer to prepare
enough memory location that will be able to contain all the element of this
particular array at all time.

Syntax: nn DIM Array name (size) for linear array

Nn DIM array name (row-length, column-length) for 2


dimensional array

Example:

DIM A(5) declares array A of 5 elements

DIM A(4,2) declares array L of 4 rows and 2 columns

1. Write a BASIC program that compute the sum and average (mean)
of N numbers

(HINT: 1 N 500 )

REM the program to compute the sum and average (mean)


of N numbers

DIM X(500)

INPUT enter value for N; N

IF (1 <= N AND N <= 500) THEN

LET SUM = 0

PRINT read in all elements in array X

FOR I = I TO N

INPUT X (I)

LET SUM = SUM + X(I)

NEXT I

LET AVG = SUM / N

45
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT SUM=; SUM

PRINT Average (mean) of numbers is; AVG

ELSE

PRINT Invalid Digit!

END IF

END

2. Write a BASIC program to evaluate the sum of 2 n x n matrices.

REM program to compute the sum of two 3 x 3 matrices

DIM A(3,3), B(3,3), C(3,3)

PRINT read in elements in matrices A and B

FOR I = 1 TO 3

FOR J = 1 TO 3

INPUT A(I,J), B(I,J)

NEXT J

NEXT I

to evaluate the sum of two matrices

FOR I = 1 TO 3

FOR J= 1 TO 3

C(I,J) = A(I,J) + B(I,J)

NEXT J

NEXT I

to print the result

FOR I = 1 TO 3

FOR J = 1 TO 3

PRINT C(I,J)

46
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
NEXT J

NEXT I

END

INTRODUCTION TO MS-DOS OPERATING SYSTEM

47
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
MS-DOS stands for Microsoft Disk Operating System, it is a single
user operating system that allows only one user to perform task at a time. It
is command-oriented operating system that allows operation to be
performed with the use of commands (instructions).

o MS-DOS COMMANDS

MS-DOS indicates the command line by displaying the command prompt.


For example: C:\> you type command at this prompt to specify the task you
want to perform. For example, type Ver then press the enter key; then MS-
DOS version number would be displayed.

PARTS OF COMMAND

A MS-DOS command has up to 3 parts; which are:

I. THE COMMAND NAME: this specifies the action you want MS-DOS
to carry out. For example: DEL, COPY, CLS
II. PARAMETERS: this defines the object you want MS-DOS to act on.
For example, the Del(Erase) command requires a parameter that is
name of the file you want to delete. i.e. Del CSC102.txt
III. SWITCH: is a forward slash (/) usually followed by a letter o
number

o STOP OR CANCELLING COMMAND

If you want to stop MS-DOS from completing a command; press ctrl + break
+ C. Your command is cancelled and the command prompt appears.

DESIGNATING A DISK DRIVE

The current drive appears as the first letter of the command prompt. On
most system if the letter is A or B, one of the floppy disk drive (51/4 or 31/2)
is the current drive.

To change the current drive, type the letter of the drive followed by a
colon. For example,

On C:\> type A: and press enter key.

TYPES OF COMMAND

48
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
1. INTERNAL COMMAND: these are commands loaded into memory,
when you start your system and are placed in a file called
COMMAND.COM. Examples are: Dir, Del, Date, Time and so on.
2. EXTERNAL COMMANDS: these are command that are placed in
files on a disk and transferred from disk into memory for use.
Examples are: Chkdsk, format, COPY, XCOPY, etc.

CLS (clear screen): this is use to clear the screen of the MS-DOS, so that it
will only display command prompt and cursor. E.g. type the cls at the
command prompt i.e.

C:\> CLS (type and press enter key)

CD (change directory): to refer to the name of the current directory or


switch to a parent directory or change to a specific directory indicated as the
parameter to this command.

Syntax:

i. CD.. : specifies that you want to change the immediate parent


directory of the current directory or subdirectory.
ii. CD\ : specifies that you want to change the current drive or switch to
command prompt, with no directory i.e. to have a direct access to the
content of the drive but not its content directories.
iii. CD Drive: paths : specifies the drive and directory you wish to switch
to.

Examples:

I. C:\USERS\WINDOWS> CD.. (type and press enter key )

This will produce C:\USERS>

II. C:\USERS\WINDOWS> CD\ (type and press enter key)

This will yield: C:\>

III. C:\USERS\WINDOWS> CD A:\BASIC\QB (type and press enter key)

This will result to: A:\BASIC\QB>

49
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
COPY: use to copy one or more files from one location (drive or
directory) to another

Syntax: COPY source destination

Or COPY drive: pathname1 drive: pathname2

SOURCE: specifies the location and the name of files from which you
want to copy. It may contain drive letter, colon followed by directory
name or filename

i.e. drive: pathname

DESTINATION: specifies the location and name of files to which you


want to copy. It may consist drive letter, colon, followed by pathname
(directory name or filename or combination)

i.e. drive: pathname

Examples:

I. C:\> COPY C:\*.* C:\All_files (type and press enter key)

This will allow all the files placed directly on drive C to move to a
directory name All_files on drive C

II. C:\> COPY C:\*.* A:\All_enteries (type and press the enter key)

This will move all the file placed/stored directly on drive C to a directory
called All entries on drive A.

III. C:\> COPY C:\BASIC\sample1.BAS C:\CSC 102 (type and press the
enter key)
This copy a title called sample1.BASfrom the directory named
BASIC on drive C to a directory called CSC 102 in drive C
IV. C:\> COPY C:\BASIC\*.BAS C:\CSC102 (type and press the enter
key)

This will move all the file with an extension .BAS from a directory
called BASIC on drive C to a directory known as CSC 102 on drive
C.

50
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
DIR: use to display a list of all files, directories or subdirectories that
are in the drive or directory specified.

Syntax: DIR or

DIR drive: pathname [/p][/w]

Examples:

I. C:\> DIR (type and press enter key)

This display all file, directories and subdirectories in the drive C. The
list items may include the disks volume label, serial number,
directory or file name per line, the file size in bytes, the date and time
the file last modified, total number of files; their commutative size, the
free space (in byte) remaining on the disk.

II. C:\> DIR C:\BASIC\*.BAS /W/P (type and press enter key)

This display in wide format a list of only file name of files with
extension .BAS in directory BASIC, and pause each time the screen
fills until you press enter key to continue.

/P: causes the directory (Dir) to display only to pause once the
screen is filled.

/W: to select a wide display and cause DOS to display only


filenames with no other information.

XCOPY: copies directories, their subdirectories, and files (except


hidden and system files).

Examples:

C:\>XCOPY a: b: /s copies all the files and subdirectories from disk


in drive A to the disk in drive B.

DISKCOPY: copies the content of one disk drive to a formatted or


unformatted disk in the target drive

Syntax: DISKCOPY source destination

51
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
DISKCOPY drive1: drive2:

Examples: DISKCOPY A: C: (type and press the enter key)

This copy the content of disk drive A and placed it disk drive C

DEL (ERASE): delete the file you specify.

Syntax: DEL pathname

Examples:

i. C:\> DEL CSC 102.txt- this delete the files called CSC102.txt
from disk on drive C
ii. C:\> DEL C:\test\CSC102.tmp- this deletes files: CSC102.tmp
from directory test on drive C
CHKDSK: check the status of a disk and display a status report such
as number of spaces used and free for use, check for error in disk.

Example: CHKDSK C: check the status of the disk drive C.

EXIT: use to quit the operation of a command interpreter


(command.com) of MS-DOS, returns to the program that started the
interpreter, if one exists.

To use it, just type EXIT and press enter key

FORMAT: specify to prepare or repair the disk for use. The FORMAT
command creates a new root directory and file allocation table for the
disk. It can also check for bad areas on the disk, and also delete all
the data on the disk.

Syntax: FORMAT drive: [/s][/v][/4]

/s copies the OS (generating system)files necessary to boot the


computer into the disk.

/v specifies the volume label to use

/4 this can be up to 11 characters long formats a S , 360k


double ended side in high capacity disk drive.

Example: C:\> format a: it format floppy disk in drive A.

52
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
MD(Make Directory): use to create new directory.

Syntax: MD directory Name

Example: C:\> MD CSC102 (type and press enter key)

This will create a directory named CSC102 on disk drive C

RD(Remove Directory): use to delete(remove) directory from its


container, before this can be done, all files and sub directories need to
be removed.

Syntax: RD Directory Name

Example: C:\> RD CSC102 (type and press enter key)

This will delete (remove) a directory named CSC102 from disk drive C.

TIME: displays the system time or set your computer internal clock.

Syntax: TIME [Time Format]

Example:

i. Just type TIME at the command prompt as in C:\> TIME, then


press enter key; eventually display the system time.
ii. C:\> TIME 04:09 pm (press enter)

This set the time to 04:09 pm

DATE: to display the system date and set your computer date.
Syntax: DATE (date format)
Example:
i. C:\> DATE (type and press enter key)

This results into the current system date.

ii. C:\> DATE 11/05/2013

This set the current system date to 11/05/2013

53
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

INTRODUCTION TO PROGRAMMING WITH VISUAL BASIC

ABOUT VISUAL BASIC (VB)

Visual basic provides the tools you need to create windows with familiar
elements like menus, text boxes, command button, option buttons, check
boxes, etc. Microsoft Windows uses a Graphical Users Interface (GUI).

Most traditional languages such as BASIC, C, COBOL, FORTRAN, and


Pascal are considered Procedural language. i.e. the program specifies the
exact sequence of all operations. VB is a newer programming-language,

54
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
which uses a different approach: Object Oriented Programming (OOP) and
event-driven programming. Microsoft refers to VB as an event-driven
programming language, which has many (but not all) elements of an object-
oriented programming language such as java.

In the event-driven model, programs are no longer procedural; they do


not follow a sequential logic. You, as the programmer do not take control and
determine the sequence of execution. Instead, the user can press keys and
click on various buttons and boxes in a window. Each user action can cause
an event to occur, while triggers a BASIC procedure that you have written.

TERMINOLOGIES IN VB
1. DESIGN TIME: this is the time at which VB application is being
developed.
2. BREAK TIME: this is the time when there is a pause in the execution
of the VB program.
3. RUN TIME: this is the time at which VB application developed is being
executed and tested.
4. FORM: this is a small windows or dialog representing a user interface
on which control are added in order to develop a VB application.
5. CONTROL: these are element or graphical representation of an object
added to a form in order to create VB application. Examples are:
labels, textboxes, checkboxes, option buttons, combo boxes, command
buttons etc.
6. OBJECT: this is the name used to refer combination of form and
control that make up the VB application.
7. PROPERTIES: these refer to attribute or behaviour or appearance of
an object. Examples are: Name, text, caption, back color, font, visible
etc. We can refer to a property of an object in a VB procedure as:
objectname.property= value e.g. text1.text = welcome!
8. METHOD: this refers to the action performed on object or action
performed by an object. Examples are: print, resize, show, hide, load,
unload etc. we can refer to a method of an object in a VB code as:
Object name. E.g. picture1.print welcome to FUTA
9. EVENT: These refer to what happen to an object when a user interacts
with the designed VB application. Examples are: click, load, activate,
unload, key press, mouse down, lost focus etc.

We refer to an event of a particular object by writing:

55
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Objectname_event

e.g. form_load(), text1_keypress (key ASCII as integer)

10. PROJECT: this is a collection of all files (such as forms,


designers, modules, class modules, etc) that make up the developed
VB application.

VERSIONS OF VB
Microsoft Visual BASIC for windows comes in a working model, a
learning edition, a professional edition. Anyone planning to do
professional application development that includes the advanced
features of database management should use the professional edition,
enterprise edition, or express edition with .NET framework facilities.

THE THREE-STEP PROCESS IN WRITING VB PROJECTS


I. DESIGN THE USER INTERFACE: you create user-interface by drawing
controls on VB forms that will represent the object that user will see
and interact with when running your project.
II. SETTING OF PROPERTIES: when setting properties, you give every
controls including the forms name, and set value to define their
properties such as caption for label, text for textboxes and the likes.
III. WRITING OF CODE: you will have to write a BASIC programming
statements (known as BASIC code) to carry out action needed by your
program.

THE THREE TYPES OF ERRORS IN VB


I. COMPILE ERRORS: errors due to violating the syntax rules of BASIC
statements.
II. RUN-TIME ERRORS: errors due to statements that cannot execute
properly.
III. LOGIC ERRORS: errors resulting into production of erroneous results.

INTRODUCING VB CONTROLS:
I. TEXT BOXES: we do use a text box control when we want the user to
type some input, to allow user to modify the content of any
information or message, to create a text editor window, and to display
an editable report. Some commonly used properties of text box are:

56
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
text, name, alignment, font, multi line, maxlength etc. the 3 letter
prefix for naming a textbox is txt. E.g. txtlenght
II. LABEL: we use a label control when we want the user to view some
output, to label; or name other control on form, to display any
information whose content cannot be modified, to generate non-
editable report. Some common properties of label are: caption, name,
font, backcolor, alignment etc.
The 3- letter prefix for naming a label is lbl e.g lblarea
III. FRAMES: frames are used as containers for other controls. Usually,
group o option buttons or check boxes are placed in frames. Using
frames to group controls make your forms easier to understand. Some
common properties include; caption, name etc. the 3- letter prefix for
naming a frame is fra. E.g. fracolor.
IV. CHECKBOXES: check boxes allow the user to select (or deselect) an
option. In any group of checkboxes, any number of them may be
selected. The value properties of a checkbox are set to 0 if unchecked,
1 if checked, 2 if greyed (disabled).

The 3- letter prefix for naming a checkbox is chk. E.g. chkbold.

V. OPTION BUTTONS: use option button when only one button of a


group may be selected. Any option buttons placed directly on the form
(not in a frame) function as group. A group of option buttons inside a
frame function together. The best method is to first create a frame and
then create each opton button inside the frame. The value property of
an option button is set to true if selected or if unselected. The3 letter
prefix for naming an option button is opt e.g. optred.

57
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM

SOLUTION TO CSC102 (PRACTICAL) QUESTIONS

1. CLS
REM PROGRAM TO COMPUTE THE FACTORIAL OF N POSITIVE INTEGERS
LET FACT = 1
INPUT ENTER ANY POSITIVE INTEGER N: ; N
IF(N < 0) THEN
PRINT INVALID INPUT! ENSURE YOU ENTER A POSITIVE NUMBER
ELSE
FOR I = N TO 1 STEP -1
LET FACT = FACT * I
NEXT I
PRINT FACTORIAL OF ; N; =;FACT
ENDIF
END

2. CLS
REM PROGRAM TO COMPUTE THE ROOTS OF A QUADRATIC EQUATION USING QUADRATIC
FORMULAE
INPUT ENTER VALUE FOR A; A
INPUT ENTER VALUE FOR B; B
INPUT ENTER VALUE FOR C; C
LET D = B ^ 2 (4 * A * C)
IF (D < 0) THEN
PRINT COMPLEX ROOTS
ELSEIF(D = 0)THEN
LET X1 = -B /(2 * A)
PRINT EQUAL ROOTS:;X1
ELSE
LET X1 = (-B + SQR(B ^ 2 4 * A * C))/(2 * A)
LET X1 = (-B - SQR(B ^ 2 4 * A * C))/(2 * A)
PRINT ROOT1 =; X1; ROOT2 =; X2
ENDIF
END

3. CLS
REM PROGRAM TO COMPUTE THE SUM OF THE SQUARE OF N NUMBERS
LET SUMSQ = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1 TO N
LET SUMSQ = SUMSQ + (I ^ 2)
NEXT I
PRINT THE SUM OF THE SQUARE OF N NUMBERS:; SUMSQ
END

4. CLS
REM PROGRAM TO GENERATE EVEN NUMBERS BETWEEN 1 AND 100 AND THEIR SUM
LET SUMEVEN = 0
PRINT EVEN NUMBERS
FOR I = 2 TO 100 STEP 2
PRINT I
LET SUMEVEN = SUMEVEN + I
NEXT I
PRINT SUM OF EVEN NUMBERS BETWEEN 1 AND 100 IS; SUMEVEN
END

5. CLS
REM PROGRAM TO GENERATE EVEN NUMBERS BETWEEN 1 AND 100 AND THEIR PRODUCTS

58
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
LET PRDTEVEN = 1
PRINT EVEN NUMBERS
FOR I = 2 TO 100 STEP 2
PRINT I
LET PRDTEVEN = PRDTEVEN * I
NEXT I
PRINT PRODUCT OF EVEN NUMBERS BETWEEN 1 AND 100 IS; PRDTEVEN
END

6. CLS
REM PROGRAM TO GENERATE ODD NUMBERS BETWEEN 1 AND 100 AND THEIR SUM
LET SUMODD = 0
PRINT ODD NUMBERS
FOR I = 1 TO 100 STEP 2
PRINT I
LET SUMODD = SUMODD + I
NEXT I
PRINT SUM OF ODD NUMBERS BETWEEN 1 AND 100 IS; SUMODD
END

7. CLS
REM PROGRAM TO GENERATE ODD NUMBERS BETWEEN 1 AND 100 AND THEIR PRODUCTS
LET PRDTODD = 1
PRINT ODD NUMBERS
FOR I = 1 TO 100 STEP 2
PRINT I
LET PRDTODD = PRDTODD * I
NEXT I
PRINT PRODUCT OF ODD NUMBERS BETWEEN 1 AND 100 IS; PRDTODD
END

8. CLS
REM PROGRAM TO GENERATE SUM OF ALL EVEN NUMBERS, SUM OF THE SQUARE OF EVEN
NUMBERS, REM AND PRODUCT OF THE SUM OF THE SQUARE AND SUM OF ALL EVEN
BETWEEN 1 AND 100
LET SUM = 0
LET SUMSQ = 0
PRINT EVEN NUMBERS; SQUARE OF EVEN NUMBERS
FOR I = 2 TO 100 STEP 2
PRINT I, I ^ 2
LET SUM = SUM + I
LET SUMSQ = SUMSQ + (I ^ 2)
NEXT I
LET PRODUCT = SUM * SUMSQ
PRINT THE SUM OF ALL EVEN NUMBERS BETWEEN 1 AND 100 =; SUM
PRINT THE SUM OF THE SQUARE OF EVEN NUMBERS BETWEEN 1 AND 100 =; SUMSQ
PRINT THE PRODUCT OF SUMS OF ALL EVEN NUMBERS BETWEEN 1 AND 100 =; PRODUCT
END

9. CLS
REM PROGRAM TO CONVERT DOLLARS TO NAIRA IF 1 DOLLAR = 200 NAIRA
INPUT ENTER THE AMOUNT IN DOLLARS:; AMT
LET NAMT = AMT * 200
PRINT AMT; IN DOLLAR IS; NAMT; NAIRA
END

10.
CLS
REM PROGRAM TO ACCEPT A STUDENT SURNAME, MIDDLE NAME, AND FIRST NAME, THEN
REM CONCANTENATE(JOIN) THEM INTO A VARIABLE CALLED NAME
INPUT READ IN YOUR SURNAME; SURNAME$
INPUT READ IN YOUR MIDDLE NAME; MIDDLENAME$
INPUT READ IN YOUR FIRST NAME; FIRSTNAME$
LET NAME$ = SURNAME$ + + MIDDLENAME$ + + FIRSTNAME$

59
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT YOUR FULL NAME IS ; NAME$
END
11.
CLS
REM PROGRAM TO GENERATE ALL THE FACTORS OF A GIVEN INTEGER NUMBER
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT FACTORS OF; N; ARE:
FOR I = 1 TO N
IF(N MOD I = 0) THEN
PRINT I
ENDIF
NEXT I
END
12.
CLS
REM PROGRAM TO GENERATE ALL THE FACTORS OF A GIVEN INTEGER NUMBER AND THEIR SUM
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT FACTORS OF; N; ARE:
FOR I = 1 TO N
IF(N MOD I = 0) THEN
PRINT I
LET SUM = SUM + I
ENDIF
NEXT I
PRINT THE SUM OF THE FACTORS OF; N; =; SUM
END
13.
CLS
REM PROGRAM TO GENERATE ALL THE FACTORS OF A GIVEN INTEGER NUMBER AND THEIR PRODUCT
LET PRODUCT = 1
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT FACTORS OF; N; ARE:
FOR I = 1 TO N
IF(N MOD I = 0) THEN
PRINT I
LET PRODUCT = PRODUCT * I
ENDIF
NEXT I
PRINT THE PRODUCT OF THE FACTORS OF; N; =; PRODUCT
END
14.
CLS
REM PROGRAM TO GENERATE ALL THE MULTIPLES OF A GIVEN INTEGER NUMBER BTW 1 AND 100
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT MULTIPLES OF; N; ARE:

60
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
FOR I = 1 TO 100
IF(I MOD N = 0) THEN
PRINT I
ENDIF
NEXT I
END
15.
CLS
REM PROGRAM TO COMPUTE THE SUM OF MULTIPLE OF A GIVEN INTEGER NUMBER BTW 1 AND 100
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT MULTIPLES OF; N; ARE:
FOR I = 1 TO 100
IF(I MOD N = 0) THEN
PRINT I
LET SUM = SUM + I
ENDIF
NEXT I
PRINT THE SUM OF THE MULTIPLES OF; N; =; SUM
END

16.
CLS
REM PROGRAM TO COMPUTE THE PRODUCT OF MULTIPLE OF A GIVEN INTEGER NUMBER BTW 1 -
100
LET PRODUCT = 1
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT MULTIPLES OF; N; ARE:
FOR I = 1 TO 100
IF (I MOD N = 0) THEN
PRINT I
LET PRODUCT = PRODUCT * I
ENDIF
NEXT I
PRINT THE PRODUCT OF THE MULTIPLES OF; N; =; PRODUCT
END
17.
REM PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100
PRINT PRIME NUMBERS ARE:
FOR I = 2 TO 100
FOR J = 2 TO I-1
IF (I MOD J = 0) THEN 60
NEXT J
PRINT I
60 NEXT I
END

61
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
18.
CLS
REM PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100 AND THEIR SUM
LET SUM = 0
PRINT PRIME NUMBERS ARE:
FOR I = 2 TO 100
FOR J = 2 TO I-1
IF (I MOD J = 0) THEN 60
NEXT J
PRINT I
LET SUM = SUM + I
60 NEXT I
PRINT THE SUM OF ALL PRIME NUMBERS BTW 1 AND 100 =; SUM
END
19.
CLS
REM PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100 AND THEIR PRODUCT
LET PRODUCT = 1
PRINT PRIME NUMBERS ARE:
FOR I = 2 TO 100
FOR J = 2 TO I-1
IF (I MOD J = 0) THEN 60
NEXT J
PRINT I
LET PRODUCT = PRODUCT * I
60 NEXT I
PRINT THE PRODUCT OF ALL PRIME NUMBERS BTW 1 AND 100 =; PRODUCT
END
20. SOLUTION TO ACTIVITY 4-1(PG. 38) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO DETERMINE WHETHER AN INTEGER NUMBER IS A PRIME OR COMPOSITE NUMBER
INPUT READ IN ANY INTEGER NUMBER N:; N
IF (N <= 1) THEN
PRINT NUMBER MUST BE POSITIVE!
ELSE
FOR J = 2 TO N-1
IF (N MOD J = 0) THEN 70
NEXT J
PRINT N; IS A PRIME NUMBER
GOTO 80
ENDIF
70 PRINT N; IS A COMPOSITE NUMBER
80 END
21.
CLS

62
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
REM PROGRAM TO DETERMINE WHETHER A NUMBER IS ODD NUMBER, EVEN NUMBER, OR PRIME
NUMBER
INPUT READ IN ANY INTEGER NUMBER N:; N
IF (N MOD 2 = 0) THEN
PRINT N; IS AN EVEN NUMBER
ELSE
PRINT N; IS AN ODD NUMBER
ENDIF
IF (N <= 1) THEN
PRINT NUMBER MUST BE POSITIVE!
ELSE
FOR J = 2 TO N-1
IF (N MOD J = 0) THEN 70
NEXT J
PRINT N; IS A PRIME NUMBER
GOTO 80
ENDIF
70 PRINT N; IS A COMPOSITE (NOT PRIME) NUMBER
80 END
22.
CLS
REM PROGRAM TO DETERMINE WHETHER A POSITIVE INTEGER NUMBER IS A PERFECT NUMBER
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1, N-1
IF (N MOD I = 0) THEN
LET SUM = SUM + I
PRINT FACTOR =; I
ENDIF
NEXT I
IF(SUM = N) THEN
PRINT N; IS A PERFECT NUMBER
ENDIF
END
23.
REM PROGRAM TO DETERMINE WHETHER A POSITIVE INTEGER NUMBER IS A DEFICIENCY NUMBER
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1, N-1
IF (N MOD I = 0) THEN
LET SUM = SUM + I
PRINT FACTOR =; I
ENDIF
NEXT I
IF (SUM < N) THEN
PRINT N; IS A DEFICIENCY NUMBER

63
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
ENDIF
END
24.
CLS
REM PROGRAM TO DETERMINE WHETHER A POSITIVE INTEGER NUMBER IS AN EXCESS/SURPLUS
NUMBER
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1, N-1
IF (N MOD I = 0) THEN
LET SUM = SUM + I
PRINT FACTOR =; I
ENDIF
NEXT I
IF (SUM > N) THEN
PRINT N; IS AN EXCESS NUMBER
ENDIF
END
25.
CLS
REM PROGRAM TO COMPUTE THE INVERSE/RECIPROCAL OF EVEN NOS BTW 130 AND THEIR
PRODUCT
LET PRODUCT = 1
FOR I = 2 TO 30 STEP 2
PRINT INVERSE OF; I; =; 1 / I
LET PRODUCT = PRODUCT * (1 / I)
NEXT I
PRINT PROUCT OF INVERSE =; PRODUCT
END
26.
CLS
REM PROGRAM TO DETERMINE EVEN NUMBERS BTW 1-50 THOSE THAT ARE MULTIPLE OF 3
FOR I = 2 TO 50 STEP 2
IF (I MOD 3 = 0) THEN
PRINT I
ENDIF
NEXT I
END
27.
CLS
REM PROGRAM TO GENERATE A FIBONACCI NUMBERS
LET F1 = 1
LET F2 = 1
INPUT ENTER ANY POSITIVE INTEGER GREATER THAN 2; N
IF (N < 3) THEN
PRINT F1, F2

64
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
ELSE
PRINT F1; F2;
FOR I = 3 TO N
LET FIB = F1 + F2
LET F1 = F2
LET F2 = FIB
PRINT FIB;
NEXT I
ENDIF
END
28.
CLS
REM PROGRAM TO READ IN A CHARACTER AND DETERMINE WHETHER CHARACTER IS ALPHABET,
REM DIGIT OR SYMBOLIC CHARACTER
INPUT PRESS IN ANY CHARACTER FROM THE KEYBOARD; C$
IF ((C$ >= A AND C$ <= Z) OR (C$ >= a AND C$ <= z)) THEN
PRINT C$; IS AN ALPHABET/LETTER
ELSEIF ((C$ >= 0 AND C$ <= 9)) THEN
PRINT C$; IS A DIGIT/NUMBER
ELSE
PRINT C$; IS A SYMBOLIC CHARACTER
ENDIF
END
29.
CLS
REM PROGRAM TO COMPUTE THE SUM AND AVERAGE(MEAN) OF N NUMBERS
DIM X(1000)
LET SUM = 0
INPUT READ IN ANY POSITIVE INTEGER NUMBER; N
FOR I = 1 TO N
INPUT X(I)
LET SUM = SUM + X(I)
NEXT I
LET MEAN = SUM / N
PRINT SUM OF THE GIVEN NUMBERS =; SUM
PRINT MEAN (AVERAGE) OF THE GIVEN NUMBERS =; MEAN
END
30.
CLS
REM PROGRAM THAT COMPUTE THE PERMUTATION OF NUMBERS
LET F1 = 1
LET F2 = 1
INPUT ENTER ANY POSITIVE INTEGER N:; N
INPUT ENTER ANY POSITIVE INTEGER R:; R
IF (R > N) THEN
PRINT R; MUST NOT BE GREATER THAN; R

65
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
ELSE
TO COMPUTE N FACTORIAL
FOR I = N TO 1 STEP -1
LET F1 = F1 * I
NEXT I
TO COMPUTE N-R FACTORIAL
FOR J = (N R) TO 1 STEP -1
LET F2 = F2 * J
NEXT J
LET PERM = F1 / F2
PRINT PERMUTATION OF NUMBER =; PERM
ENDIF
END
31.
CLS
REM PROGRAM THAT COMPUTE THE COMBINATION OF NUMBERS
LET F1 = 1
LET F2 = 1
LET F3 = 1
INPUT ENTER ANY POSITIVE INTEGER N:; N
INPUT ENTER ANY POSITIVE INTEGER R:; R
IF (R > N) THEN
PRINT R; MUST NOT BE GREATER THAN; R
ELSE
TO COMPUTE N FACTORIAL
FOR I = N TO 1 STEP -1
LET F1 = F1 * I
NEXT I
TO COMPUTE N-R FACTORIAL
FOR J = (N R) TO 1 STEP -1
LET F2 = F2 * J
NEXT J
TO COMPUTE R FACTORIAL
FOR K = R TO 1 STEP -1
LET F3 = F3 * K
NEXT K
LET COMB = F1 / (F2 * F3)
PRINT COMBINATION OF NUMBER =; COMB
ENDIF
END
32.
CLS
REM PROGRAM THAT GENERATE THE LARGEST (MAXIMUM) OF 10 DIFFERENT NUMBERS
DIM X(10)
PRINT READ IN 10 DIFFERENT NUMBERS
FOR I = 1 TO 10

66
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
INPUT X(I)
NEXT I
LARGEST = X(1)
FOR I = 2 TO 10
IF (LARGEST < X(I))THEN
LARGEST = X(I)
ENDIF
NEXT I
PRINT THE LARGEST (MAXIMUM) OF 10 NUMBERS =; LARGEST
END
33.
CLS
REM PROGRAM THAT GENERATE THE LEAST (MINIMUM) OF 10 DIFFERENT NUMBERS
DIM X(10)
PRINT READ IN 10 DIFFERENT NUMBERS
FOR I = 1 TO 10
INPUT X(I)
NEXT I
LEAST = X(1)
FOR I = 2 TO 10
IF (LEAST > X(I))THEN
LEAST = X(I)
ENDIF
NEXT I
PRINT THE LEAST (MINIMUM) OF 10 NUMBERS =; LEAST
END
34.
REM TO COMPUTE THE SUM OF 2 X 2 MATRICES
DIM A(2,2), B(2,2), C(2,2)
PRINT READ IN ELEMENTS IN MATRIX A:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT A(I,J)
NEXT J
NEXT I
PRINT READ IN ELEMENTS IN MATRIX B:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT B(I,J)
NEXT J
NEXT I
PRINT THE SUM OF ELEMENTS IN MATRIX A AND B ARE:
FOR I = 1 TO 2
FOR J = 1 TO 2
LET C(I,J) = A(I,J) + B(I,J)
PRINT C(I,J),

67
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
NEXT J
PRINT
NEXT I
END
35.
CLS
REM TO COMPUTE THE PRODUCT OF 2 X 2 MATRICES A AND B
DIM A(2,2), B(2,2), C(2,2)
PRINT READ IN ELEMENTS IN MATRIX A:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT A(I,J)
NEXT J
NEXT I
PRINT READ IN ELEMENTS IN MATRIX B:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT B(I,J)
NEXT J
NEXT I
PRINT THE PRODUCT OF ELEMENTS IN MATRIX A AND B ARE:
FOR I = 1 TO 2
FOR J = 1 TO 2
LET C(I,J) = 0
FOR K = 1 TO 2
LET C(I,J) = C(I,J) +(A(I,K) * B(K,J))
NEXT K
PRINT C(I,J),
NEXT J
PRINT
NEXT I
END
36.
CLS
REM PROGRAM TO COMPUTE THE ARITHMETIC MEAN, HARMONIC MEAN, GEOMETRIC MEAN OF 3 NOS
INPUT ENTER VALUE FOR X:; X
INPUT ENTER VALUE FOR Y:; Y
INPUT ENTER VALUE FOR Z:; Z
LET ARITH_MEAN = 1 / 3 * (X + Y + Z)
LET GEOM_MEAN = (X * Y * Z) ^ (1 / 3)
LET HARM_MEAN = 3 / ((1 / X) + (1 / Y) + (1 / Z))
PRINT THE ARITHMETIC MEAN =; ARITH_MEAN
PRINT THE GEOMETRIC MEAN =; GEOM_MEAN
PRINT THE HARMONIC MEAN =; HARM_MEAN
END
37.

68
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
CLS
REM PROGRAM TO COMPUTE THE AREA OF TRIANGLE USING HEROES FORMULAE
INPUT ENTER VALUE FOR A:; A
INPUT ENTER VALUE FOR B:; B
INPUT ENTER VALUE FOR C:; C
LET S = (A + B + C) / 2
LET AR = S * (S A) * (S B) * (S C)
IF (AR <= 0) THEN
PRINT AREA HAS COMPLEX ROOT OR ZERO ROOT = 0
ELSE
LET AREA = SQR(AR)
PRINT AREA OF TRIANGLE =; AR
ENDIF
END
38.
CLS
REM PROGRAM TO CONVERT METERS TO INCHES, AND YARD
INPUT ENTER THE VALUE IN METERS; M
LET INCH = 39.37 * M
LET YARD = INCH / 36
PRINT INCHES =; INCH; YARD =; YARD
END
39.
CLS
REM PROGRAM TO CONVERT TIME IN SECONDS TO HOURS AND MINUTES EQUIVALENT
INPUT READ IN TIME IN SECONDS; SECS
LET HRS = SECS \ 3600
LET SECS = SECS MOD (HRS * 3600)
LET MINS = SECS \ 60
PRINT THE EQUIVALENT TIME IS; HRS; HOURS :; MINS; MINUTES
END
40.
CLS
REM PROGRAM THAT GENERATE ALL INTEGERS BTW 1-50 AND SKIP THOSE THAT MULTIPLE OF 5
FOR I = 1 TO 50
IF (I MOD 5 = 0) THEN 30
PRINT I
30 NEXT I
END
41. SOLUTION TO ACTIVITY 4-3(PG. 39) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO FIND THE SUM OF AND AVERAGE OF ALL THE MULTIPLE OF 5 BETWEEN 1 AND
100
LET COUNT = 0
LET SUM = 0
FOR I = 1 TO 100

69
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
IF (I MOD 5 = 0) THEN
PRINT I;
LET SUM = SUM + I
LET COUNT = COUNT + 1
ENDIF
NEXT I
LET AVERAGE = SUM / COUNT
PRINT THE SUM OF ALL THE MULTIPLE OF 5 BTW 1 AND 100 =; SUM
PRINT THE AVERAGE OF ALL THE MULTIPLE OF 5 BTW 1 AND 100 =; AVERAGE
END
42. SOLUTION TO ACTIVITY 5-2(PG. 41) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO PRODUCE THE EIGHT TRIPLES OF 0 AND 1 SUCH AS 000, 001, 010,
FOR I = 0 TO 1
FOR J = 0 TO 1
FOR K = 0 TO 1
PRINT I; J; K
NEXT K
NEXT J
NEXT I
END
43. SOLUTION TO ACTIVITY 5-3(PG. 41) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO COMPUTE THE INNER PRODUCT OF VECTOR HAVING 10 COMPONENTS SUCH AS
(3,5,4,6,4,3,5,4,3,5) AND (4,4,5,6,7,4,5,4,3,5)
DIM VECTOR1(10), VECTOR2(10)
LET SUM = 0
PRINT READ IN ELEMENTS OF VECTOR 1:
FOR I = 1 TO 10
INPUT VECTOR1(I)
NEXT I
PRINT READ IN ELEMENTS OF VECTOR 2:
FOR I = 1 TO 10
INPUT VECTOR2(I)
NEXT I
FOR I = 1 TO 10
LET SUM = SUM + (VECTOR1(I) * VECTOR2(I))
NEXT I
PRINT THE INNER PRODUCT OF 2 VECTORS IS:; SUM
END
44. SOLUTION TO ACTIVITY 5-5(PG. 41) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO SORT A GIVEN SET NUMBERS IN ASCENDING AND DESCENDING ORDER
DIM SET(100)
30 INPUT READ IN THE NUMBER OF ELEMENTS IN THE SET:; N
IF(N <= 1 OR N > 100) THEN

70
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT NUMER MUST BE BETWEEN 2 AND 100: TRY AGAIN WITH CORRECT VALUE
GOTO 30
ELSE
PRINT READ IN ALL ELEMENTS IN THE SET:

FOR I = 1 TO N
INPUT SET(I)
NEXT I
FOR I = 1 TO N - 1
FOR J = I + 1 TO N
IF(SET(J-1) > SET(J)) THEN
TEMP = SET(J-1)
SET(J-1) = SET(J)
SET(J) = TEMP
ENDIF
NEXT J
NEXT I
PRINT SET OF NUMBERS IN ASCENDING ORDER IS:
FOR I = 1 TO N
PRINT SET(I);
NEXT I
PRINT: PRINT SET OF NUMBERS IN DESCENDING ORDER IS:
FOR I = N TO 1 STEP -1
PRINT SET(I);
NEXT I
ENDIF
END
45. SOLUTION TO ACTIVITY 6-2(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO CHECK ENTERED LETTER IF IT IS CAPITAL(UPPERCASE) OR SMALL(LOWERCASE)
INPUT PRESS IN ANY ALPHABETICAL CHARACTER FROM THE KEYBOARD; C$
IF (C$ >= A AND C$ <= Z) THEN
PRINT C$; IS A CAPITAL(UPPERCASE) ALPHABET/LETTER
ELSE IF (C$ >= a AND C$ <= z) THEN
PRINT C$; IS A SMALL(LOWERCASE) ALPHABET/LETTER
ELSE
PRINT C$; IS NOT A LETTER/ALPHABET
ENDIF
END
46. SOLUTION TO ACTIVITY 6-3(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO REVERSE A GIVEN STRING
INPUT READ IN ANY STRING; TEXT$
FOR I = LEN(TEXT$) TO 1 STEP -1
REVTEXT$ = REVTEXT$ + MID$(TEXT$, I, 1)
NEXT I

71
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT THE REVERSE OF STRING:;TEXT$; IS:; REVTEXT$
END
47. SOLUTION TO ACTIVITY 6-4(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO GENERATE A TRIANGLE OF A STRING OF 5 NUMBERS (e.g. 12345)
INPUT READ IN ANY STRING OF NUMBERS; TEXT$
PRINT THE TRIANGULAR FORM OF STRING:
FOR I = LEN(TEXT$) TO 1 STEP -1
PRINT MID$(TEXT$, 1, I)
NEXT I
END
48. SOLUTION TO ACTIVITY 6-1(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO READ A PERSONS FIRST, MIDDLE AND LAST NAMES AND EXTRACT THEIR
INITIALS
INPUT ENTER A PERSONS FIRST NAME:; FIRST$
INPUT ENTER A PERSONS MIDDLE NAME:; MIDDLE$
INPUT ENTER A PERSONS LAST NAME:; LAST$
PRINT THE INITIALS OF A PERSONS NAME ARE:
PRINT LEFT$(FIRST$,1); LEFT$(MIDDLE$,1); LEFT$(LAST$,1)
END
49. SOLUTION TO ACTIVITY 8-9(PG. 46) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO CHECK WHETHER A GIVEN STRING OF NUMBER IS A PALINDROME OR NOT
INPUT READ IN ANY STRING OF NUMBER; NUMB$
FOR I = LEN(NUMB$) TO 1 STEP -1
REVNUMB$ = REVNUMB$ + MID$(NUMB$, I, 1)
NEXT I
IF (REVNUMB$ = NUMB$) THEN
PRINT THE STRING OF NUMBER:; NUMB$; IS A PALINDROME
ELSE
PRINT THE STRING OF NUMBER:; NUMB$; IS NOT A PALINDROME
ENDIF
END
50. SOLUTION TO ACTIVITY 5-1(PG. 40) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM USING FOR NEXT LOOP TO CALCULATE THE SUM OF EVERY THIRD INTEGER
BEGINNING WITH I = 2 (I.E. CALCULATE THE SUM 2+5+7+8+11+13+14+ )FOR ALL VALUES OF
I < 100
LET SUM = 0
LET K = 3
LET I = 2
FOR J = 2 TO 99
IF (I >= 100) THEN GOTO 50
PRINT I;
LET SUM = SUM + I

72
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
LET I = I + K
LET K = K 1
IF (K < 1) THEN K = 3
NEXT J
50 PRINT SUM OF THE SERIES =; SUM
END

51. SOLUTION TO ACTIVITY 5-1(PG. 40) IN THE PRACTICAL MANUAL


CLS
REM PROGRAM USING DO WHLE LOOP TO CALCULATE THE SUM OF EVERY THIRD INTEGER
BEGINNING WITH I = 2 (I.E. CALCULATE THE SUM 2+5+7+8+11+13+14+.)FOR ALL VALUES OF
I < 100
LET SUM = 0
LET K = 3
LET I = 2
DO WHILE(I < 100)
PRINT I;
LET SUM = SUM + I
LET I = I + K
LET K = K 1
IF (K < 1) THEN K = 3
LOOP
PRINT SUM OF THE SERIES =; SUM
END
52. SOLUTION TO ACTIVITY 5-1(PG. 40) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM USING DO UNTIL LOOP TO CALCULATE THE SUM OF EVERY THIRD INTEGER
BEGINNING WITH I = 2 (I.E. CALCULATE THE SUM 2+5+7+8+11+13+14+.)FOR ALL VALUES OF
I < 100
LET SUM = 0
LET K = 3
LET I = 2
DO UNTIL(I >= 100)
PRINT I;
LET SUM = SUM + I
LET I = I + K
LET K = K 1
IF (K < 1) THEN K = 3
LOOP
PRINT SUM OF THE SERIES =; SUM
END

* KEYNOTES

73
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
READ YOUR BOOK VERY WELL
BE FOCUS AND AIM HIGH
SUPPLICATE TO ALLAH(SWT)
BE CLOSE TO YOUR CREATOR AND MOVE AWAY FROM SINS
FEAR ALLAH MOST

************************* BARAKA LLOHU IHI ***********************************

74

You might also like