CSC 102 Slides
CSC 102 Slides
Speed: The computer can manipulate large data at incredible speed and response time
can be very fast.
Accuracy: Its accuracy is very high and its consistency can be relied upon. Errors
committed in computing are mostly due to human rather than technological weakness.
There are in-built error detecting schemes in the computer.
Storage: It has both internal and external storage facilities for holding data and
instructions. This capacity varies from one machine to the other. Memories are built up
in K(Kilo) modules where K = 1024 memory locations.
Automatic: Once a program is in the computer’s memory, it can run automatically each
time it is opened. The individual has little or no instruction to give again.
Reliability: Being a machine, a computer does not suffer human traits of tiredness and
lack of concentration. It will perform the last job with the same speed and accuracy as
the first job every time even if ten million jobs are involved.
Flexibility: It can perform any type of task once it can be reduced to logical steps.
Modern computers can be used to perform a variety of functions like on-line processing,
multi-programming, real time processing etc.
HISTORICAL OVERVIEW OF THE COMPUTER
The second generation saw several important developments at all levels of computer
system design, from the technology used to build the basic circuits to the
programming languages used to write scientific applications.
transistorized airborne digital computer
Electronic switches in this era were based on discrete diode and transistor
technology with a switching time of approximately 0.3 microseconds. The first
machines to be built with this technology include TRADIC at Bell Laboratories in 1954
and TX-0 at MIT’s Lincoln Laboratory. Memory technology was based on magnetic
cores which could be accessed in random order, as opposed to mercury delay lines, in
which data was stored as an acoustic wave that passed sequentially through the
medium and could be accessed only when the data moved by the I/O interface.
Second Generation of Computers
Important innovations in computer architecture included index registers for
controlling loops and floating point units for calculations based on real numbers.
Prior to this accessing successive elements in an array was quite tedious and often
involved writing self-modifying code (programs which modified themselves as they
ran; at the time viewed as a powerful application of the principle that programs and
data were fundamentally the same, this practice is now frowned upon as extremely
hard to debug and is impossible in most high level languages). Floating point
operations were performed by libraries of software routines in early computers, but
were done in hardware in second generation machines.
During this second generation many high level programming languages were
introduced, including FORTRAN (1956), ALGOL (1958), and COBOL (1959). Important
commercial machines of this era include the IBM 704 and 7094. Theylatter
introduced I/O processors for better throughput between I/O devices and main
memory.
Second Generation of Computers
The second generation also saw the first two supercomputers designed specifically
for numeric processing in scientific applications. The term “supercomputer” is
generally reserved for a machine that is an order of magnitude more powerful than
other machines of its era.
Two machines of the 1950s deserve this title. The Livermore Atomic Research
Computer (LARC) and the IBM 7030 (aka Stretch) were early examples of machines
that overlapped memory operations with processor operations and had primitive
forms of parallel processing.
Third Generation Computers
IBM 360/91
IBM 360-195
ILLIAC IV
Programming Languages of Third Generation Computers
Cambridge and the University of London cooperated in the development of CPL
(Combined Programming Language, 1963). CPL was, according to its authors, an
attempt to capture only the important features of the complicated and
sophisticated ALGOL. However, the ALGOL, CPL was large with many features
that were hard to learn. In an attempt at further simplification, Martin Richards
of Cambridge developed a subset of CPL called BCPL (Basic Computer
Programming Language, 1967).
Third Generation Computers
Two important events marked the early part of the third generation: the
development of the C programming language and the UNIX operating system,
both at Bell Labs. In 1972, Dennis Ritchie, seeking to meet the design goals of CPL
and generalize Thompson’s B, developed the C language. Thompson and Ritchie
then used C to write a version of UNIX for the DEC PDP-11. This C-based UNIX was
soon ported to many different computers, relieving users from having to learn a
new operating system each time they change computer hardware. UNIX or a
derivative of UNIX is now a de facto standard on virtually every computer system.
Fourth Generation (1972 – 1984)
The next generation of computer systems saw the use of large scale integration
(LSI – 1000 devices per chip) and very large scale integration (VLSI – 100,000
devices per chip) in the construction of computing elements. At this scale entire
processors will fit onto a single chip, and for simple systems the entire computer
(processor, main memory, and I/O controllers) can fit on one chip. Gate delays
dropped to about Ins per gate.
Semiconductor memories replaced core memories as the main memory in most
systems; until this time the use of semiconductor memory in most systems was
limited to registers and cache. During this period, high speed vector processors,
such as the CRAY 1, CRAY X-MP and CYBER 205 dominated the high performance
computing scene. Computers with large main memory, such as the CRAY 2,
began to emerge. A variety of parallel architectures began to appear; however,
during this period the parallel computing efforts were of a mostly experimental
nature and most computational science was carried out on vector processors.
Microcomputers and workstations were introduced and saw wide use as
alternatives to time-shared mainframe computers.
Developments in software include very high level languages such as FP
(functional programming) and Prolog (programming in logic). These languages
tend to use a declarative programming style as opposed to the imperative style of
Pascal, C. FORTRAN, et al. In a declarative style, a programmer gives a
mathematical specification of what should be computed, leaving many details of
how it should be computed to the compiler and/or runtime system. These
languages are not yet in wide use, but are very promising as notations for
programs that will run on massively parallel computers (systems with over 1,000
processors). Compilers for established languages started to use sophisticated
optimization techniques to improve code, and compilers for vector processors
were able to vectorize simple loops (turn loops into single instructions that would
initiate an operation over an entire vector).
An important event in the development of computational science was the
publication of the Lax report. In 1982, the US Department of Defense (DOD) and
National Science Foundation (NSF) sponsored a panel on Large Scale Computing
in Science and Engineering, chaired by Peter D. Lax. The Lax Report stated that
aggressive and focused foreign initiatives in high performance computing,
especially in Japan, were in sharp contrast to the absence of coordinated national
attention in the United States. The report noted that university researchers had
inadequate access to high performance computers. One of the first and most
visible of the responses to the Lax report was the establishment of the NSF
supercomputing centers. Phase I on this NSF program was designed to
encourage the use of high performance computing at American universities by
making cycles and training on three (and later six) existing supercomputers
immediately available. Following this Phase I stage, in 1984 – 1985 NSF provided
funding for the establishment of five Phase II supercomputing centers.
General Overview of Computer
Fifth Generation (1984 – 1990)
The development of the next generation of computer systems is characterized
mainly by the acceptance of parallel processing. Until this time, parallelism was
limited to pipelining and vector processing, or at most to a few processors
sharing jobs. The fifth generation saw the introduction of machines with
hundreds of processors that could all be working on different parts of a single
program. The scale of integration in semiconductors continued at an incredible
pace, by 1990 it was possible to build chips with a million components – and
semiconductor memories became standard on all computers.
Other new developments were the widespread use of computer networks and
the increasing use of single-user workstations. Prior to 1985, large scale parallel
processing was viewed as a research goal, but two systems introduced around
this time are typical of the first commercial products to be based on parallel
processing. The Sequent Balance 8000 connected up to 20 processors to a single
shared memory module (but each processor had its own local cache).
The Intel iPSC -1, nicknamed “the hypercube”, took a different approach.
Instead of using one memory module, Intel connected each processor to its
own memory and used a network interface to connect processors. This
distributed memory architecture meant memory was no longer a bottleneck
and large systems (using more processors) could be built. The largest iPSC-1
had 128 processors. Toward the end of this period, a third type of parallel
processor was introduced to the market. In this style of machine, known as a
data-parallel or SIMD, there are several thousand very simple processors. All
processors work under the direction of a single control unit; i.e. if the control
unit says “add a to b” then all processors find their local copy of a and add it
to their local copy of b. Machines in this class include the Connection Machine
from Thinking Machines, Inc., and the MP-1 from MasPar, Inc.
Scientific computing in this period was still dominated by vector processing. Most
manufacturers of vector processors introduced parallel models, but there were
very few (two to eight) processors in these parallel machines. In the area of
computer networking, both wide area network (WAN) and local area network
(LAN) technology developed at a rapid pace, stimulating a transition from the
traditional mainframe computing environment towards a distributed computing
environment in which each user has their own workstation for relatively simple
tasks (editing and compiling programs, reading mail) but sharing large, expensive
resources such as file servers and supercomputers. RISC technology (a style of
internal organization of the CPU) and plummeting costs for RAM brought
tremendous gains in computational power of relatively low cost workstations and
servers. This period also saw a marked increase in both the quality and quantity of
scientific visualization.
Sixth Generation (1990 to date )
This generation is beginning with many gains in parallel computing, both in the
hardware area and in improved understanding of how to develop algorithms to
exploit diverse, massively parallel architectures. Parallel systems now compete
with vector processors in terms of total computing power and most especially
parallel systems to dominate the future.
Combinations of parallel/vector architectures are well established, and one
corporation (Fujitsu) has announced plans to build a system with over 200 of its
high and vector processors.
Workstation technology has continued to improve, with processor designs now
using a combination of RISC, pipelining, and parallel processing. As a result it is
now possible to procure a desktop workstation that has the same overall
computing power (100 megaflops) as fourth generation supercomputers. This
development has sparked an interest in heterogeneous computing: a program
started on one workstation can find idle workstations elsewhere in the local
network to run parallel subtasks.
One of the most dramatic changes in the sixth generation is the explosive
growth of --------------------------------------
wide area networking. Network bandwidth has expanded
tremendously in the last few years and will continue to improve for the next
several years. T1 transmission rates are now standard for regional networks,
and the national “backbone” that interconnects regional networks uses T3.
networking technology is becoming more widespread than its original strong
base in universities and government laboratories as it is rapidly finding
application in K-12 education, community networks and private industry. A
little over a decade after the warning voiced in the Lax report, the future of a
strong computational science infrastructure is bright.
Computers can be classified based on three key parameters;
1. Signal Types
2. Purpose
3. Capacity
Signal Types
Digital Computer
Represent its variable in the form of digits. It counts the data it deals with,
whether representing numbers, letters or other symbols, are converted into
binary form on input to the computer. The data undergoes a processing after
which the binary digits are converted back to alpha numeric form for output for
human use. Because of the fact that business applications like inventory control,
invoicing and payroll deal with discrete values, they are beset processed with
digital computers. As a result of this, digital computers are mostly used in
commercial and business places today.
Analog Computer
It measures rather than counts. This type of computer sets up a model of a
system. Common type represents it variables in terms of electrical voltage and
sets up circuit analog to the equation connecting the variables. The answer can
be either by using a voltmeter to read the value of the variable required, or by
feeding the voltage into a plotting device. They hold data in the form of physical
variables rather than numerical quantities.
Signal Types what is a digitizer?-- it is a conversion element that accepts analog inputs and output digital value
Hybrid Computer
In some cases, the user may wish to obtain the output from an analog computer
as processed by a digital computer or vice versa. To achieve this, he set up a
hybrid machine where the two are connected and the analog computer may be
regarded as a peripheral of the digital computer. In such a situation, a hybrid
system attempts to gain the advantage of both the digital and the analog
elements in the same machine. This kind of machine is usually a special-purpose
device which is built for a specific task. It needs a conversion element which
accepts analog inputs, and output digital value. Such converters are called
digitizers. There is need for a converter from analog to digital also. It has the
advantage of giving real-time response on a continuous basis. Complex
calculations can be dealt with by the digital elements, thereby requiring a large
memory, and giving accurate results after programming. They are mainly used in
aerospace and process control applications.
Classification By Purpose
Special Purpose Computers
A special purpose computer is one that is designed to solve a restricted class of
problems. Such computers may even be designed and built to handle only one
job. In such machines, the steps or operations that the computer follows may be
built into the hardware. Most of the computers used for military purposes fall
into this class. Other example of special purpose computers include:
Computers designed specifically to solve navigational problems.
Computers designed for tracking airplane or missiles.
Computers used for process control applications in industries such as oil refinery,
chemical manufacture, steel processing and power generation.
General Attributes of Special Purpose Computers
Special purpose computer are usually very efficient for the tasks for which they
are specially designed.
They are very much less complex than the General-Purpose Computers. The
simplicity of the circuiting stems from the fact that provision is made only for
limited facilities.
They are very much cheaper than the General-Purpose type since they involve less
components and are less complex.
Classification By Purpose
General-Purpose Computers
General-Purpose computers are computers designed to handle wide range of
problems. Theoretically, a general-purpose computer can be adequate by means
of some easily alterable instructions to handle any problems that can be solved by
computation. In practice however, there are limitations imposed by memory size,
speed and the type of input/output devices. Examples of areas where the general
purpose are employed include the following:
Payroll, Banking, Billing, Sales analysis, Cost accounting ,Manufacturing scheduling
Inventory control
General Attributes of General-Purpose Computers
General-Purpose computers are more flexible than special purpose computers.
They can handle a wide spectrum of problems.
They are less efficient than the special-purpose computers due to such problems
as;
Inadequate storage;
Low operating speed;
Coordination of the various tasks and subsection may take time.
General Purpose Computers are more complex than the special purpose ones.
Classification by Capacity
The volume of work that a given computer handles is closely tied to the cost and
to the memory size of computer. Therefore, most authorities today accept the
price of rental price as the standard for ranking computers.
Here, both memory size and cost shall be used to rank (classify) computer into
three main categories as follows:
(i)Microcomputers
(ii)Medium/Mini/Small Computers
(iii)Large Computer/Main Frames.
(i)Micro Computers
Microcomputers, also known as single board computers, are the cheapest class of
computers. In the microcomputer, we do not have a Central Processing Unit (CPU)
as we have in the larger computers rather we have a microprocessor chip as the
main data processing unit. They are the cheapest smallest and can operate under
normal office condition. Examples are IBM, APPLE, COMPAQ, Hewlett Packard
(HP), Dell Toshiba.
Different Types of Personal Computers (Micro Computers)
Laptop Computers
Notebook Computer
Palmtop Computer
(ii) Mini Computers
The Mini Computers have memory capacity in the range 128K bytes to 256 Kbytes
and are also not expensive but reliable and smaller in size compare to mainframe.
It was first introduced in 1965; when DEC (Digital Equipment Corporation) built
the PDP – 8. Other Mini Computer includes WANG VS.
(iii) Mainframe
The Main Frame Computers often called number crunches have memory capacity
of the order of 4 Kbytes and they are very expensive. They can execute up to
100MIPS (Meanwhile Instructions Per Second). They have large systems and are
used by many people for a variety of purpose.
Computer Hardware Subsystem
The computer hardware comprises the ---------------------------
input unit, the ---------------------------------------
processing unit and the
output unit.
--------------------------------
The input unit comprises those media through which data is fed into the computer.
Examples include the -----------------------
keyboard, mouse, joystick, trackball,
---------------- ------------------- scanner etc.
--------------------- ---------------------
unit and the main memory. The main memory also known as the primary memory
----------------------------------
Key Lock
Turbo button
Lights
Reset Button
Power On/Off
Fan Housing
Serial Port
Sound Jacks
Keyboard Port
Network Adapter
Monitor Port
Figure showing the back side of a Computer System
Inside of a System Unit Consist of the following;
Battery
Disk Drive Controller Card
Display Adapter Card
Expansion Slots
ROM Chips
RAM Chips
Empty Ram Chip Slots
Central Processing Unit
CPU support Chips
Math Coprocessor Slot
CPU Fan
Power Supply Unit
Hard Disk Drive
Mother Board
Assignment: Identify the comprehensive function of each of the above listed
components.
Figure showing the inside of a computer system unit
The Computer Motherboard
All the electronic components in a PC are mounted on a piece of fiberglass called the
motherboard. Fiberglass cannot conduct electricity, so each component is insulated from
all the others. Thin lines of metal on the surface of the fiberglass connect pins from one
component to another, forming the computer’s electrical circuits.
System Software
This is refers to the suits of programs that facilitates the optimal use of the hardware
systems and/or provide a suitable environment for the writing, editing, debugging,
testing and running of User Programs. Usually, every computer system comes with
collection of these suits of programs, which are provided by the Hardware
Manufacturer.
Computer System Software can be divided into three groups which are;
Operating System
Language Translator
Utility Software
OPERATING SYSTEMS
An operating system is a program that acts as an interface between a user of a
computer and the computer hardware. The purpose of an operating system is to
provide an environment in which a user may execute programs.
Systems programs are programs written for direct execution on computer hardware
in order to make the power of the computer fully and efficiently accessible to
applications programmers and other computer users. Systems programming is
different from application programming because the requires an intimate
knowledge of the computer hardware as well as the end users’ needs. Moreover,
systems programs are often large and more complex than application programs,
although that is not always the case. Since systems programs provide the
foundation upon which application programs are built, it is most important that
systems programs are reliable, efficient and correct.
OPERATING SYSTEMS
In a computer system the hardware provides the basic computing resources. The
applications programs define the way in which these resources are used to solve the
computing problems of the users. The operating system controls and coordinates
the use of the hardware among the various systems programs and application
programs for the various users
The basic resources of a computer system are provided by its hardware, software
and data. The operating system provides the means for the proper use of these
resources in the operation of the computer system. It simply provides an
environment within which other programs can do useful work.
We can view an operating system as a resource allocator. A computer system has
many resources ( hardware and software) that may be required to solve a problem:
CPU time, memory space, file storage space, input/output devices etc.
The operating system acts as the manager of these resources and allocates them to
specific programs and users as necessary for their tasks. Since there may be many,
possibly conflicting, requests for resources, the operating system must decide which
requests are allocated resources to operate the computer system fairly and
efficiently. An operating system is a control program.
OPERATING SYSTEMS
This program controls the execution of user programs to prevent errors and
improper use of the computer.
Operating systems exist because they are a reasonable way to solve the problem of
creating a usable computing system. The fundamental goal of a computer system is
to execute user programs and solve user problems.
The primary goal of an operating system is a convenience for the user. Operating
systems exit because they are supposed to make it easier to compute with an
operating system than without an operating system. This is particularly clear when
you look at operating system for small personal computers.
A secondary goal is the efficient operation of an computer system. This goal is
particularly important for large, shared multi-user systems. Operating systems can
solve this goal. It is known that sometimes these two goals, convenience and
efficiency, are contradictory.
OPERATING SYSTEMS
A computer’s operating system ( OS ) is a group of programs designed to serve two basic
purposes:
To control the allocation and use of the computing system’s resources among the
various users and tasks, and.
To provide an interface between the computer hardware and the programmer that
simplifies and makes feasible the creation, coding, debugging, and maintenance of
application programs.
Specifically, we can imagine that an effective operating system should accomplish all of the
following:
Facilitate creation and modification of program and data files through an editor
program,
Provide access to compilers to translate programs from high-level languages to
machine language,
Provide a loader program to move the complied program code to the computer’s
memory for execution,
Provide routines that handle the intricate details of I/O programming,
Assure that when there are several active processes in the computer, each will get fair
and non interfering access to the central processing unit for execution,
Take care of storage and device allocation,
TYPES OPERATING SYSTEMS
Assignment: Discuss in details the operations of each of the above listed operating
systems
Components of an Operating System
Process Management
Memory Management
I/O System
File Management
Protection System
Networking
Language Machine
Source program
Translator Language
(object program)
Language Translator
Three examples of classes of language translators are Assemblers, Interpreters and
Compilers.
Assemblers: An Assembler is a computer program that accepts a source program in
assembly language program reads and translates the entire program into an equivalent
program in machine language called the object program or object code. Each machine has
its own assembly language, meaning that the assembly language of one machine cannot
run on another machine.
Interpreter: An Interpreter is a program that accepts program fin a source language,
reads, translates and executes it, line by lone into machine language.
Compilers: A Compiler is a computer program that accepts a source program in one high-
level language, reads and translates the entire user’s program into an equivalent program
in machine language, called the object program or object code.
The stages in compilation include:
•Lexical analysis
•Syntax analysis
•Semantic analysis
•Code generation
Utility Software
This is a set of commonly used programs in data processing departments also called
service or general-purpose programs.
They perform the following operations.
File Conversion: This covers data transfer from any medium to another, making an exact
copy or simultaneously editing and validating. For example, copying from a hard disk to a
diskette.
File Copy: It makes an exact copy of a file from one medium to another or from an area of
a medium to another area of the same medium.
Housekeeping Operations: These include programs to clear areas of storage, writing file
labels and updating common data.
They are not involved in solving the problem at hand. They are operations that must be
performed before and after actual processing.
Application software
Application software is a set of programs designed to solve problems of a specific nature.
It could either be supplied by the computer manufacturer or in some cases, the users
produce their own application program called USER PROGRAMS. Hence, an application
software could be subdivided into two classes, namely; Generalized and User-defined
Software.
Under the Generalized software, we have as examples: Word Processing Programs e.g.
Word Perfect, Word Star, Microsoft word. Also, Desktop Publishing e.g. Ventura,
PageMaker, CorelDraw likewise the Spreadsheet program e.g. LOTUS 1,2,3, Excel, Super-Q
while under the User-defined, we could have some User-defined packages for a particular
company or organization, for accounting, payroll or some other specialized purposes.
Examples Of Generalized Applicationsoftware
Word Processor: A Word Processor is used to create, edit, save and print reports. It
affords the opportunity to make amendments before printing is done. E.g Microsoft
Word.
Spreadsheet: Is an application mainly designed for numerical figures and reports.
Examples are: LOTUS 123, Supercalc, MS Multiplan, MS-excel, VP Planner etc.
Integrated Packages: They are programs or packages that perform a variety of
different processing operations using data that is compatible with whatever
operation is being carried out. They perform a number of operations like Word
Processing, Data-base Management and Spread sheeting. Examples are: Office
writer, Logistic Symphony, Framework, Enable, Ability, Smart ware II, Microsoft Work
V2.
Graphic Packages: These are packages that enable you to bring out images, diagrams
and pictures. Examples are PM, PM Plus, Graphic Writer, Photoshop.
Database Packages: It is software for designing, setting up and subsequently
managing a database. (A database is an organized collection of data that allows for
modification taking care of different users view). Examples are Dbase II, III, IV,
FoxBASE, Rbase Data Perfect, Paradox III, Revelation Advanced and MS-Access.
Examples Of Generalized Application Software
Statistical Packages: These are packages that can be used to solve statistical
problems, e.g. Stat graphical, SPSS (Statistical Packages for Social Scientists).
Desktop Publishing: These are packages that can be used to produce books and
documents in standard form. Examples are PageMaker, Ventura, Publishers, Paints
Brush, Xerox Form Base, News Master II, Dbase Publisher.
Game Packages: These are packages that contain a lot of games for children and
adults. Examples are Chess, Scrabble, Monopoly, Tune Trivia, Star Trek 2, California
Game, Soccer Game, War Game, Spy Catcher Dracula in London.
Communication Packages: Examples are Carbon Plus, Data talk V3.3, Cross talk, SAGE
Chit Chat, Data Soft.
User Programs
This is a suit of programs written by programmers for computer users. They are
required for the operation of their individual business or tasks. Example is a
payroll package developed for salary operation of a particular company.
Computer Programming Languages
Overview of Computer Programming Language
Basically, human beings cannot speak or write in computer language, and since
computers cannot speak or write in human language, an intermediate language had to
be devised to allow people to communicate with the computers. These intermediate
languages, known as programming languages, allow a computer programmer to direct
the activities of the computer. These languages are structured around unique set of
rules that dictate exactly how a programmer should direct the computer to perform a
specific task. With the powers of reasoning and logic of human beings, there is the
capability to accept an instruction and understand it in many different forms. Since a
computer must be programmed to respond to specific instructions, instructions cannot
be given in just any form.
Overview of Computer Programming Language
The rules of a particular language tell the programmer how the individual instructions
must be structured and what sequence of words and symbols must be used to form an
instruction.
The operation code tells the computer what to do such as add, subtract, multiply and
divide. The operands tell the computer the data items involved in the operations. The
operands in an instruction may consist of the actual data that the computer may use to
perform an operation, or the storage address of data.
Example A = B+ 2
The operation codes are ‘=‘ and ‘+’
The operands are A, B and 2
A and B are storage devices while 2 is the
actual data.
Overview of Computer Programming Language
Some computers use many types of operation codes in their instruction format and may
provide several methods for doing the same thing. Other computers use fewer
operation codes, but have the capacity to perform more than one operation with a single
instruction. There are four basic types of instructions namely:
input-output instructions;
arithmetic instructions;
branching instructions;
logic instructions.
An input instruction directs the computer to accept data from a specific input device and
store it in a specific location in the store.
An output instruction tells the computer to move a piece of data from a computer
storage location and record it on the output medium.
All of the basic arithmetic operations can be performed by the computer. Since
arithmetic operations involve at least two numbers, an arithmetic operation must
include at least two operands.
Overview of Computer Programming Language
Branch instructions cause the computer to alter the sequence of execution of instruction
within the program. There are two basic types of branch instructions; namely
unconditional branch instruction and conditional branch instruction. An unconditional
branch instruction or statement will cause the computer to branch to a statement
regardless of the existing conditions. A conditional branch statement will cause the
computer to branch to a statement only when certain conditions exist.
Machine language
Assembly language
A 4GL offers the user an English-like set of commands and simple control structures in
which to specify general data processing or numerical operations. A program is
translated into a conventional high-level language such as Cobol, which is passed to a
compiler. A 4GL is, therefore, a non-procedural language. The program flows are not
designed by the programmer but by the fourth generation software itself. Each user
request is for a result rather than a procedure to obtain the result. The conceptual
diagram of the translation process of very high level language to machine language is
given in the diagram below.
Basic Principles of Computer Programming
Principles of good Programming
It is generally accepted that a good Computer program should have the
characteristics shown below:
Accuracy: The Program must do what it is supposed to do correctly and must
meet the criteria laid down in its specification.
Reliability: The Program must always do what it is supposed to do, and never
crash.
Efficiency: Optimal utilization of resources is essential. The program must use
the available storage space and other resources in such as way that the system
speed is not wasted.
Robustness: The Program should cope with invalid data and not stop without an
indication of the cause of the source of error.
Usability: The Program must be easy enough to use and be well documented.
Maintainability: The Program must be easy to amend having good structuring
and documentation.
Readability: The Code of a program must be well laid out and explained with
comments.
Stages of Programming
The preparation of a computer program involves a set of procedure.
These steps can be classified into eight major stages, viz
Problem Definition
Devising the method of solution
Developing the method using suitable aids, e.g. pseudo code or flowchart.
Writing the instructions in a programming language
Transcribing the instructions into “machine sensible” form
Debugging the program
Testing the program
Documenting all the work involved in producing the program.
Problem definition
The first stage requires a good understand of the problem. The programmer (i.e.
the person writing the program) needs to thoroughly understand what is
required of a problem. A complete and precise unambiguous statement of the
problem to be solved must be stated. This will entail the detailed specification
which lays down the input, processes and output-required.
Program debugging
A program seldom executes successfully the first time. It normally contains a few
errors (bugs). Debugging is the process of locating and correcting errors.
The following are documentations that should be done for each program:
Problem Definition Step
Planning the Solution Step
Program source coding sheet
User’s manual to aid persons who are not familiar with the program.
Operator’s manual to assist the computer operator.
Highlight and discuss into details the content of a good program documentation
and its advantages.
Flowcharts
A Flowchart is a graphical representation of the major steps of work in process. It
displays in separate boxes the essential steps of the program and shows by
means of arrows the directions of information flow. The boxes most often
referred to as illustrative symbols may represent documents, machines or actions
taken during the process. The area of concentration is on where or who does
what, rather than on how it is done. A flowchart can also be said to be a
graphical representation of an algorithm, that is, it is visual picture which gives
the steps of an algorithm and also the flow of control between the various steps.
Flowcharts Symbols
Flowcharts are drawn with the help of symbols. The following are the most
commonly used flowchart symbols and their functions:
Used to show the START or STOP point.
Examples
Write an algorithm to read values for three variables. U, V, and W and find a value for
RESULT from the formula: RESULT = U + V2/W. Draw the flowchart.
Solution:
Algorithm
Input values for U, V, and W
Computer value for result
Print value of result
Stop
Pseudocode
Pseudocode is a program design aid that serves the function of a flowchart in expressing
the detailed logic of a program. Sometimes a program flowchart might be inadequate for
expressing the control flow and logic of a program. By using Pseudocode, program
algorithm can be expressed as English-language statements. These statements can be
used both as a guide when coding the program in specific language and as
documentation for review by others. Because there is no rigid rule for constructing
pseudocodes, the logic of the program can be expressed in a manner without confronting
to any particular programming language. A series of structured words is used to express
the major program functions. These structured words are the basis for writing programs
using a technical term called “structure programming”.
Example: Construct Pseudocode for the problem in the example above.
BEGIN
STORE 0 TO SUM
STORE 1 TO COUNT
DO WHILE COUNT not greater than 10
ADD COUNT to SUM
INCREMENT COUNT by 1
ENDWILE
END
Decision Tables
Decision tables are used to analyze a problem. The conditions applying in the problem
are set out and the actions to be taken, as a result of any combination of the conditions
arising are shown. They are prepared in conjunction with or in place of flowcharts.
Decision tables are a simple yet powerful and unambiguous way of showing the actions to
be taken when a given set of conditions occur. Moreover, they can be used to verify that
all conditions have been properly catered for. In this way they can reduce the possibility
that rare or unforeseen combinations of conditions will result in confusion about the
actions to be taken.
Decision tables have standardized format and comprise of four sections.
Conditions Stub: This section contains a list of all possible conditions which could apply
in a particular problem.
Condition Entry: This section contains the different combination of the conditions each
combination being given a number termed a ‘Rule’:
Action Stub: This section contains a list of the possible actions which could apply for ay
given combinations of conditions.
Action Entry: This section shows the actions to be taken for each combination of
conditions.
BASIC Programming Language
BASIC PROGRAMMING LANGUAGE
BASIC?....the basis?..or sound like one of these languages?!
BEGINNER’S ALL-PURPOSE SYMBOLIC INSTRUCTION
CODE.
High level programming languages ,user-friendly and
general-purpose language.
A STRING variable must end with a dollar sign ($). This is a way of
differentiating between a string variable and a numeric variable.
Examples of valid string variable. A$ , SUM$, NAME$, N22$ , REG$ etc.
NOTE:A number can be preceded with a plus (+) or minus (-) sign. The number is
understood to be positive if no sign precedes it.
Number can be up to eight or nine significant figure.
The magnitude of a number can be as large as 1038 and as small as 10-38 (this
depends on the version of BASIC you are using).
Comma cannot appear anywhere in a number.
No other special character is allowed to be used with number, except dot (.)
Examples below are invalid numeric constants: 12,526, N1000, 035-1234566 etc
OPERATORS
An operator defines the action to be performed on the
operand(s) to obtain the result. An operand simply
means item in an operation from which the result is
obtained by means of defined action(s). Operand consists
constants and variables.
There are basically three types of operators in BASIC
programming. These are:
•Arithmetic operators
•Relational operators
•Logical operators
ARITHMETIC OPERATORS
As the name suggests, arithmetic operators are used for arithmetic
operations. The various types of operators are their corresponding
functions are given below
* Multiplication 2*2 4
/ Division 12/4 3
\ Integer division 14\3 4
MOD Integer remainder 14 MOD 3 2
+ Addition 5+2 7
- Subtraction 10-4 6
RELATIONAL OPERATORS
Relational operators are used for comparison operations.
Mostly, they are used to compare two strings or two numeric
expressions so as to obtained specific result. The result
returns either a true or false.
VARIABLES
•Numeric Variable
•String variable.
CONSTANTS
SUMMARY
OPERATORS
•Arithmetic operators
•Relational operators
•Logical operators
Example: SUM = ( R + 10 ) / ( J – 3 )
The only slight different between the two is that apostrophe ( ’ ) can be
placed at the front of a BASIC statement so as to introduce remark which
explains the function of the expression
CLS: This is simply used to clear the screen during program execution
Basic Keywords Contd.
LET STATEMENT
This is otherwise known as the Assignment Statement.
It is used to assign value (constant) to a variable.
It can also be used to assign a variable to another variable provided the
variable to be assigned has been declared/defined.
It can also be used to assign an expression to a variable.
DATA STATEMENT
This store numeric or string or combination of numeric and string
value used by READ statement. Unlike the READ statement, DATA
statement can be included in a program segment without the READ
statement.
Basic Keywords Contd.
EXAMPLE ON READ & DATA STATEMENT
Example:
READ A,B,C
DATA 2 , 3 , 5
SUM = A + B + C
Example:
INPUT A, B , C
SUM = A + B + C
Example
Syntax:
PRINT [”Prompting String”] [; or ,] variable list
Example
PRINT A,B,C OR PRINT A;B;C
PRINT ”THE AREA OF TRIANGLE = ”; A
Syntax
PRINT USING format-string ; expression list
Examples: RESULT
Syntax:
LOCATE(row,column)
Example:
CLS
LOCATE 5,10: INPUT ”Enter your Name :”;N$
LOCATE 7,10: PRINT N$ ; ” I love you so much.Can we be friend
?”
Basic Keywords Contd.
TAB STATEMENT
This statement is used in conjunction with PRINT or
LPRINT statement. It moves the cursor to specific column on
the screen.
Example
Example
CLS
READ A,B,C
DATA 2,3,5
RESTORE
READ D,E,F
PRINT ”A =”; A, ” B =”; B, ” C = ”; C, ”D =”; D, ”E =”;E, ”F =”;F
END STATEMENT
This is used to terminate the execution of a
program, procedure, or a block permanently. Great
care should be taken when using this statement
Control Statements
TRANSFER OF CONTROL
Normally, a BASIC program is executed in a
sequential order as the statements follow one
another. However, sometimes, it is necessary to
jump to some lines of the program. Thus, altering
the normal sequence of execution.
--Unconditional transfer
--Conditional transfer
Control Statements Contd.
Syntax:
GOTO Line Number
Example GOTO 10
this causes the computer to transfer control to statement with
line number 10 during program execution.
Example 2a
INPUT A
IF A > 10 THEN
PRINT ”THEN NUMBER YOU ENTERED IS GREATER THAN 10”
ELSE
PRINT ”THE NUMBER YOU ENTERED IS LESS THAN OR EQUAL TO 10”
END IF
Control Statements Contd.
Example 2b
INPUT A , B
IF A > B THEN PRINT ”The value of A is greater than B” : END
IF B > A THEN PRINT ”The value of B is greater than A” : END
IF A = B THEN PRINT ”The value of A is equal to B” : END
Example 2c
INPUT A , B
IF A > B THEN
PRINT ”The value of A is greater than B”
ELSEIF B > A THEN
PRINT ”The value of B is greater than A”
ELSE
PRINT ”The value of A is equal to B”
END IF
Loop Statements
LOOP STATEMENTS
This is another operation that is often required in programming. This
involves repeating certain portion of the program for specific number of
times or until particular condition(s) is/are satisfied.
Loop is basically divided into two
--Unconditional loop
--Conditional loop
Syntax
FOR Counter = Start TO End [STEP Increment]
[Statement block]
NEXT Counter
TRANSFER OF CONTROL
•Unconditional transfer
•Conditional transfer
SUMMARY
GOTO
IF..THEN..ELSE
LOOP STATEMENTS
•Unconditional loop
•Conditional loop
•FOR NEXT
•DO LOOP
•WHILE ..WEND
Syntax1:
DO WHILE condition DO
[statement] OR [statement]
LOOP LOOP WHILE condition
The only difference between the two syntax above is that, in the
first loop the condition is tested and if the condition is true, then
the loop is executed. The second one will execute the statement
within the loop for the first time before testing for the condition.
Loop Statements Contd
The examples below explain the two better.
K=5 K=5
DO WHILE K< = 4 DO
PRINT ”The condition is satisfied” PRINT ”The condition is
satisfied”
PRINT K PRINT K
K=K+1 K=K+1
LOOP LOOP WHILE K< = 4
Syntax2:
DO UNTIL condition DO
[statement] OR [statement]
LOOP LOOP UNTIL condition
The only difference between the two examples above is that, in the first loop the
condition is tested and if the condition is true, then the loop is executed. The
second one will execute the statement within the loop for the first time before
testing for the condition. The example below explains the two better.
Loop Statements Contd
EXAMPLE
K=5 K=5
DO UNTIL K > 4 DO
PRINT ”The condition is satisfied” PRINT ”The condition is satisfied”
PRINT K PRINT K
K=K+1 K=K+1
LOOP LOOP UNTIL K > 4
Arrays and Matrix
ARRAY & MATRIX
An array simply means collection of data items(elements) arranged in
a specific order each identified by a key or subscript.
A matrix, the data items are arranged in rows and columns.
A matrix with one row or one column is regarded as a LIST.
A variable valued by an expression in parenthesis is called a
SUBSCRIPTED VARIABLE.
A subscripted variable is used to designate and individual storage
space in the matrix.
NOTE: It is possible to deal with matrices with more than one row and
one column. For example X(2,3) is a matrix of two rows and three
columns, X(3,2) is a matrix of three rows and two columns etc.
Arrays and Matrix
DIM STATEMENT is used in dealing with array/matrix. This allows you
to declare one or more variables as well as allocate storage spaces for
them on the disk.
Example:
DIM A(10) declares a numeric variable A, and then allocates ten spaces
to it, DIM NAME$(5) declares a string variable NAME$, and then
allocates five spaces to it,
DIM A(2,3) declares a numeric variable allocates six spaces (two rows
and three columns) to it etc.
Example:
’ Program to read in any ten numeric values from the keyboard an then store them
into ’ a numeric array NUM and then display the values on the screen.
CLS
DIM NUM(10) ’This allocates ten spaces to numeric variable NUM
FOR K = 1 TO 10 ’ Reading any ten numeric values from the keyboard to
INPUT NUM(K) ’ to the spaces allocated to variable NUM
NEXT K
Library Functions
LIBRARY FUNCTIONS
These functions have predefined meaning to BASIC programming language.
They perform special set of operations that might be difficult by mere writing a
set of program code.
Some of these functions are described below.
SIN(x) This is a math function the returns the sine of angle x in radians.
Example PRINT SIN(40) displays 0.7451131
COS(x) This is a math function the returns the cosine of angle x in radians.
Example PRINT COS(40) displays -.6669381
TAN(x) This is a math function the returns the tangent of angle x in radians.
Example PRINT TAN(40) displays -1.117215
Library Functions Contd.
LOG(x)This is a math function the returns the natural logarithm of x.
Note x must be a numeric expression. Example PRINT LOG(2) displays
.6931472
NOTE : There is no special function for computing the base-10 logarithm
of number, but there is a method of doing this. Simply divide the natural
logarithm of the number by the natural logarithm of 10.
Example to display the base-10 logarithm of 2, simply type PRINT
LOG(2)/LOG(10) displays 0.30103
SQR(x) This is a math function the returns the square root of numeric
expression x
Example PRINT SQR(4) displays 2
ASC This is the opposite of CHR$. It is also a string processing function that returns
numeric value of an ASCII code. Example PRINT ASC(”A”) displays 65.
LEFT$ This is a string processing function that returns a string consisting of the
leftmost n characters of a given string. n is a numeric value.
Example PRINT LEFT$(”KAYODE”,3) displays ”KAY”.
RIGHT$ This is a string processing function that returns a string consisting of the
rightmost n characters of a given string. n is a numeric value.
Exampel PRINT RIGHT$(”KAYODE”,3) displays ”ODE”.
MID$ This is a string processing function that returns a substring of a string. The
syntax is MID$(string,start,length) where start is a numeric expression that defines
the starting character position of the substring and length is length of the substring.
Although, the length can be omitted if you want all the characters to the right.
Example PRINT MID$(”KAYODE”,2,3) displays AYO
BASIC Programming Language
Sample Programs
SAMPLE PROGRAMS
Write a program to find the area of a triangle using the Hero’s formula. That is:
AREA = s (s – a)(s – b)(s – c) where s = ( a + b + c ) / 2
Solution:
1 CLS
2 INPUT ”Enter the value of the side a: ” , a
3 INPUT ”Enter the value of the side b: ” , b
4 INPUT ”Enter the value of the side c: ” , c
5 s = (a + b + c) / 2
6 AREA = ABS(SQR(s*(s – a)*(s – b)*(s – c)))
7 PRINT ”The Area of the Triangle = ”; AREA
Sample Programs Contd.
Write a program that find the sum and average of all even numbers between 1
and 30.
Solution:
1 CLS
2 SUM = 0
3 COUNT = 0
4 FOR K=1 TO 30
5 IF (K MOD 2) = 0 THEN ’to detect even number
6 PRINT K
7 SUM = SUM + K
8 COUNT = COUNT + 1
9 END IF
10 NEXT K
11 PRINT ” SUM = ”; SUM
12 PRINT ”AVERAGE = ”; SUM / COUNT
Sample Programs Contd.
Write a program that will print the sine, cosine, and tangent of angles from 10 to
30. The sine, cosine, and the tangent of each angle should be in degrees Celsius,
not in radians. Besides, the output should be in tabular form
Solution:
1 CLS
2 PRINT ”ANGLE SINE_OF_ANGLE
3 COSINE_OF_ANGLE TANGENT_OF_ANGLE”
4 PRINT
5 FOR ANGLE = 10 TO 30
6 S = SIN ( (3.142 / 180) * ANGLE)
7 C = COS ( (3.142 / 180) * ANGLE)
8 T = TAN ( (3.142 / 180) * ANGLE)
9 PRINT ANGLE; TAB(10);
10 PRINT USING “#.####”;S; TAB(27);
11 PRINT USING “#.####”;C; TAB(46);
12 PRINT USING “#.####”;T
13 NEXT ANGLE
Sample Programs Contd.
Given the following set of numbers: 4, 1, 2, 3, 6, 8, -4, and 9. Write a program that
finds the smallest and the largest out of the numbers.
Solution: 1 CLS
2 DIM NUM(8)
3 FOR K = 1 TO 8
4 READ NUM(K)
5 NEXT K
6 DATA 4,1,2,3,6,8,-4,9
7 TEST=NUM(8)
8 FOR K = 1 TO 8
9 IF TEST > = NUM(K) THEN
10 TEST = NUM(K)
11 END IF
12 NEXT K
13 PRINT ”The smallest number = ”; TEST
14 FOR K = 1 TO 8
15 IF TEST < = NUM(K) THEN
16 TEST = NUM(K)
17 END IF
18 NEXT K
19 PRINT ”The largest number = ”; TEST
Sample Programs Contd.
A number is said to be perfect if it is equal to the sum of its divisors, it is said to
be deficient if it is less than the sum of its divisors, and it is said to be abundant
if it is greater than the sum of its divisor. Write a program that detects perfect,
deficient, and abundant numbers between 1 and 30.
1 CLS
Solution: 2 FOR J = 1 TO 30
3 SUM = 0
4
5
FOR K = 1 TO (J – 1)
6 IF (J MOD K) = 0 THEN
7 SUM = SUM + K
8 ENDIF
9 NEXT K
10 IF J = SUM THEN
11 PRINT J, ” is a perfect number”
12
13
ELSEIF J < SUM THEN
14 PRINT J, ” is a deficient number”
15 ELSE
16 PRINT J, ” is an abundant number”
17 END IF
18 NEXT J
Sample Programs Contd.
Write a program the sum of the first 15 odd numbers between 1 and 50
Solution:
1 CLS
2 SUM =0
3 COUNT = 0
4 FOR N=1 TO 50 STEP 2
5 PRINT N
6 SUM = SUM + N
7 COUNT = COUNT + 1
8 IF COUNT = 15 THEN
9 PRINT ”SUM = ”;SUM
10 END
11 END IF
12 NEXT N
Sample Programs Contd.
Write a program that displays all the ASCII codes between 1 and 100
Solution:
1 CLS FOR CODE=1 TO 100
2 PRINT CHR$(CODE),
3 NEXT CODE
Given that A=10, B=15, and C=5. Write a program that assigns the value of A to B,
the value of B to C and the value of C to A (i.e the result becomes A=5, B=10 and
C=15)
Solution:
1 CLS
2 A = 10 : B = 15 : C =5
3 ’Assigning the values
4 TEMP = B
5 B = A : A = C : C = TEMP
6 PRINT ”A = ”; A, ”B =”;B, ”C =”;C
Sample Programs Contd.
A triangle is said to be equilateral if all its sides are equal, it is said to be isosceles if two of its sides are
equal, and it is said to be scalene if all its sides are different. Write a program that will implement this
condition. 1 CLS
2 INPUT ”Enter the value of side a: ”, a
Solution: 3 INPUT ”Enter the value of side b: ”, b
4 INPUT ”Enter the value of side c: ”, c
5 IF (a=b) AND (b=c) THEN
6 PRINT ”The triangle is equilateral”
7 PRINT ”REASON: All its sides are equal”
8 ELSEIF (a=b) OR (a=c) OR (b=c) THEN
9 PRINT ”The triangle is isosceles”
10 PRINT ”REASON: Two of its sides are equal”
11 ELSE
12 PRINT ”The triangle is scale”
13 PRINT ”REASON: All its sides are different”
14 END IF
Write a program to input and output the name, sex, and age of 10 people.
1 DIM NAME$(10), SEX$(10),AGE(10)
Solution: 2 FOR K = 1 TO 10
3 INPUT ”Enter the Name :”, NAME$(K)
4 INPUT ”Enter the Sex :”, SEX$(K)
5 INPUT ”Enter the Age :”, AGE(K)
6 NEXT K
7 PRINT ”NAME SEX AGE”
8 FOR K= 1 TO 10
9 PRINT NAME$(K);TAB(5);SEX$;TAB(5);AGE(K)
10 NEXT K
VISUAL BASIC Programming Language
VISUAL BASIC PROGRAMMING LANGUAGE
VISUAL BASIC
NOTE: Simply drag and drop a tool from the toolbar to the form panel,and don’t forget to
save your project,your lecturer will teach you that as we might not remember to mention
this gain as we move on)
VISUAL BASIC: Getting Started
In Visual Basic we have the
The design panel and
The coding panel
when you double-click the design panel you get the coding panel
The design panel is the output of the code ran in the coding panel, even though if
the design is first created always be sure that the code has been automatically
generated. You can run your code by simply pressing F5 or go to the MenuBar
VISUAL BASIC: Getting Started
DESIGN PANEL
The design panel has the TOOLBAR,FORM PANEL , THE PROPERTIES WINDOWS and
THE MENUBAR
VISUAL BASIC: Getting Started
TOOLS
Now lets take a look at the Tools
Don’t forget you can change the features of each tool in its property window which is at the
right hand side of Microsoft Visual Studios 6
NOTE: the NAME of each tool is VERY IMPORTANT!, because each tool will be referenced by
its name, so be careful and always give your tools good and distinct names
Suggestion of good names are : LblAddress will be good for a label carrying the address of a
client, BtnAddCompute—for button that computes Addition etc
Knowing this, I guess we can proceed to the programming part, I hope you will catch up as
we move further.
VISUAL BASIC Programming Language
VISUAL BASIC: Getting Started
Example 3a
Design a form to compute the addition of two numbers.
Hint..this will need three LABELS,TEXTBOXES,AND A BUTTON and don’t
forget to clear the text on the Textboxes(simply clear the ‘Text’ property of
the textboxes but for Labels and Buttons ----goto the ‘Caption’ property)
Solution
VISUAL BASIC: Getting Started
Example 3b
Write the code for the addition for Example 3a above
Solution
Guess you didn't forget we have to declare our variable we use ‘DIM’ for that
NOTE: DIM is different in BASIC and VISUAL BASIC
VISUAL BASIC: Getting Started
If your code has an error,endeavour to look back and check for error ..now that’s
DEBUGGING !! (Simply the act of correcting the errors in a program code)
Now if your code is error-free or you’ve finished debugging, then Lets run our
program..just press F5 or click on “Run” or simply click the symbollic “PLAY”
button