CIT 215 Intro To Programming Languages - 1 PDF
CIT 215 Intro To Programming Languages - 1 PDF
Abuja Office
No. 5 Dar es Salaam Street
Off Aminu Kano Crescent
Wuse II, Abuja
Nigeria
e-mail: [email protected]
URL: www.nou.edu.ng
ISBN: 978-058-266-5
For
National Open University of Nigeria
TABLE OF CONTENTS PAGE
Module 1 .............................................................................. 1
Module 2 .............................................................................. 56
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Types of Computer Programming 3.2 Basic Principles of
Programming
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
In this unit you are going to be introduced to the principles of computer
programming. As you know, a Computer is not a useful device as an
entity without a programming force driving its operations.
Generally, a complete a computer system is made up of the following:
• Hardware
• Operating System Software
• Application Software
In fact, a better way of illustrating the above is as follows:
USERS
APPLICATION
SOFTWARE Programming Interface
OPERATING SYSTEM
HARDWARE
As you can see above, programming plays a very essential role in the
usefulness of a computer system, forming the interface link between
human users and the computer machinery. This unit will therefore take
you through the fundamentals of computer programming
2.0 OBJECTIVES
• System Programming
• Application Programming
You will now study the features of the above two types of programming
System Programming.
Operating System
There are two types Of programs that make up the Operating System:-
• Control Programs
• Processing Programs
Control Programs
Processing Programs
• Language Translators
• Linkage Editor
• Library Programs
• Utility Programs
Full discussions on each of the above programs are beyond the scope of
this course. You will learn more of them when you take full course on
OS. All that have been said so far are on system programming. As a
reminder, take a break and attempt the following exercise.
i. What is a program?
Define system programs
But before concluding on the brief review of OS, the following are
some common examples of operating systems:
• Disk Operating System (DOS) — Microsoft original OS.
• Microsoft Windows Operating Systems (Window s 95, 98.
2000)
• Microsoft Windows NT
• Microsoft Windows XP
• Unix
• Linux
• Novel Netware
The above are found on most Personal Computers (PCs). However, we
equally have the:
• Macintosh Operating System - which runs only on the Apple
Macintosh machines.
• Palm OS — which runs on Handheld computers, PC Phones or
Palmtops.
• Windows CE — a slimmed version of Windows that runs on
handheld PCs.
• Symbian OS that runs on PDAs or Mobile phones like Nokia
9300/9500
Application Programming
• Reliability
• Maintainability
• Portability
• Readability
• Performance
• Memory Saving
Reliability
By reliability, we mean that you should be able to depend on the
program to always do what it has been designed to do.
Maintainability
By this, we mean that you should be able to modify the program when
the need arises.
Portability
The concept of portability in programming is that a program should be
capable of being transferable to a different computer platforms with a
minimum modification, if any at all.
Readability
A program should be easy for other programmers to read and
understand. For example, a readable program is easier to maintain.
Performance
A program that doesn't carry out the expected tasks quickly and
efficiently has lost the performance aim. Therefore, a major aim in
program design is that the program should execute quickly and
efficiently too.
Memory Saving
What is meant here is simply that a program should not be unnecessarily
too long and requiring excessive large memory to execute.
Having gone through the aims underlying the designs of programs, you
will now see below the different stages involved in program
development:
• Problem Definition
• Solution Design
• Program Coding or Writing
• Program Testing
• Program Documentation and Maintenance The above will be
explained further as follows:
Problem Definition
Solution Design
After the definition of the problem is completed, the design of the
solution is the next step and this may take the form of one or more
programs.
By detailed logic, we mean each of the boxes in the above chart should
be described in clear terms. In detailed logic description, you will
definitely need to use such tools as Flowcharts and Pseudocode which
will be treated later in this course.
Program Testing
After the coding or writing of a program, it is submitted to the computer
for testing. Generally, testing involves the following:
• Debugging
• Compiling
• Testing (in stages)
Debugging
Errors in programs are usually called bugs and the processing of
removing errors in your programs is called debugging.
Compiling
Though you will be taught in detail the process of program compilation
in unit 8, but you should know that your program has to be translated
before the computer can execute it. Compiling is one way of translating
your program. The other is by using Interpreters, which will be treated
ahead in unit 8.
Testing
Usually, for a large program that has been developed using modular
metho I, there are various stages of testing as follows
• Unit Testing
• Integration Testing
• System Testing
• User Testing
4.0 CONCLUSION
In this unit, you have been introduced to the two main types of
programming, namely, System programming and Application
Programming. As you have learned in the unit, system programming
facilitates the use of the Computer hardware and the running of the
application programs. The application programs are simply those that
solve the users' problems. The unit has equally taken you through the
basic stages involved in programming.
5.0 SUMMARY
This unit has shown you that the computer machine is simply an
electronic device which only becomes a useful tool through its
programming. According to what you have learned in the unit, every
computer program is designed to solve a specific problem or perform a
particular task. Hence the art of programming starts by defining your
problem and then followed by the designing of the solution. A very vital
aspect of programming from what you have learned in this unit is the
documentation of your program and this should be an ongoing process
for a program that is regularly modified to keep pace with the changing
needs of its user.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Classification of Languages
3.2 High Level Languages
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
Historically, instructions for Computer processing in the early days of
the Computer had to be either wired on control panels and plugged into
the machine at the start of a job processing or had to be read from
punched cards in distinct steps of the job processing. Any of these
methods was very slow since the computer had to wait for these
instructions to be fed in by a human operator.
In this unit, the above short history will be built upon to introduce you to
computer programming languages and their classifications. Your study
objectives for this unit will therefore be as follows:
2.0 OBJECTIVES
Low-Level Language
Machine Language is generally called the lowest- level language and it
was the first language available to computer programmers. It is very fast
since the language needs no translation because its instructions are made
up of zeros and ones (O's and I 's). Thus Machine Language is merely
data to the computer and the program can modify itself during
execution.
State the problem associated with machine dependency of ML, and AL.
-
Now, remember that under introduction to this unit, it was stated that
languages can be broadly categorised into two as Low-Level and High-
Level languages. However, there are various ways of categorising
computer programming languages. One way of doing this is to classify
them by the following:
• Level
• Purpose
• Orientation
• Structure
• Translation Method
Level Classification
You have already seen this above as low- level and high- level
languages. High- Level Languages will be treated in the next section of
this unit.
Purpose Classification
Orientation Classification
In this classification, you have the following:
• Procedure — Oriented Languages
• Problem — Oriented Languages
In using A procedure-oriented language, you have to specify how to
solve a problem by indicating the procedures the computer will follow
step by step. However, in a problem-oriented language, you simply
specify what to obtain as your results while the development of the
procedures is left to the language.
• Interpreter
• Compiler
• Assembler
Interpreter
Some languages are interpreted by converting the "source program"
into machine language as the program is being executed. Interpreters
translate code line-by- line which therefore makes them run slowly than
other translators. For example, sonic BASIC language versions only
interpret programs instead of compiling them. However in Turbo Basic,
KBASIC or BASIC 4GL you can compile the BASIC source code into
an executable code.
Compiler
Unlike an Interpreter, a Compiler translates an entire program into
machine language before the execution of the program. A Compiler
usually translates the SOURCE program into another program called
the OBJECT program which is the machine language version of the
source code. With the object program created by your compiler, you
will never use the source program again except when you want to
modify it. Generally, a compiled program runs faster than an interpreted
program.
Assembler
You have already been introduced to the Assembly Language which is
neither compiled nor interpreted. For the language, it is simply
assembled. Since the assembly language is already close to the machine
language, assembling a program is therefore less time-consuming than
compilation.
In the previous section, you have learnt about the Low-Level language
which is fundamentally machine-dependent. In contrast to machine-
dependence of low- level language, High-Level Languages (HLL's) are
machine- independent.
You will recall that the above two classes of languages were mentioned
under orientation classification of languages in the last section. High-
Level Languages can further be classified again as follows,
remembering that there are many ways of classifying computer
programming languages:
• Scientific-Oriented Languages
• Business-Oriented Languages
• Multi-Purpose Languages
• Education-Oriented languages
• Natural Languages
-
It is good for you to know that a language can have any of the above
characteristics with one of the two earlier features, that is, problem-
oriented or procedure-oriented feature. This should not confuse you.
Now, it is time to introduce you to some common high- level languages.
Detailed features of some of these languages will be treated in other
units in this course.
FORTRAN
You are starting with Fortran because it is generally referred to as the
first high- level language. The name is the short for "FORmula
TRANslator. Fortran is a scientific-oriented and problem-oriented
language. Since early computer users were scientists and engineers, it
was not therefore surprising that the first high- level language was
designed to solve scientific problems. The language was developed by
an IBM (International Business Machines) group led by John Backus in
1957, though its first appearance was in 1956 according to some
authors. There have been various versions of the language as follows:
• Fortran II in 1959
• Fortran IV in 1966
• Fortran 77 in 1977
• Fortran 90/95 — the latest version.
You will learn more about the language in unit 10 of this course. BASIC
BASIC is the acronym for "Beginner's All-purpose Symbolic Instruction
Code and it is the most popular programming language. It is an
Education-oriented language developed in 1965 for use by Colleges and
Universities for instructional purposes. It is also a general-purpose and
procedure-oriented language. BASIC can be interpreted and also
compiled. You will learn more about BASIC in this course. Today, we
have a number of BASIC language versions which you can use to
develop beautifully designed software packages.
PASCAL
Pascal language was designed in 1971 like BASIC as a teaching
language. The language was named after Blaise Pascal who was a
French Mathematician and Philosopher and the inventor of the first
mechanical adding machine. You are going to learn about the
fundamentals of the language in unit 12 of this course.
C or C++
The C language was developed as an improvement of the earlier
versions, A and B which were developed by Bell Laboratories. C
language was developed in conjunction with the UNIX operating
system; in fact it is the language of the Unix operating system. The
language is lower in level than a language like Pascal but higher than
assembly language. Presently, we have the C++ and Visual C++
languages which are the later versions of the original C language.
COBOL
COBOL stands for "COmmon Business Oriented Language" and was
developed in 1960 as a language suitable for business applications.
Except for some big organisations which are unwilling to rewrite their
programs using one of the modern languages, COBOL is almost totally
abandoned by programmers today.
4.0 CONCLUSION
In this unit, you have been introduced to the general classification of
computer programming languages, namely, low- level and high-level
languages. The two low-level languages are the machine language and
the assembly language, the former being the lowest.
The machine language, as you have learnt in this unit is the only
language understood by the Computer and all other languages have to be
translated into the language for the Computer to execute their
instructions.
5.0 SUMMARY
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Problem Theory and Algorithms
3.2 Basic Features of Algorithms
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
OBJECTIVES
• Initial Assertion
• Final Assertion
• Invariant Assertion
• Pre-condition
• Post-condition.
Initial Assertion
This is the declaration or statement that precedes the first step of an
algorithm and it simply describes the initial problem state before the
execution of the associated algorithm.
Final Assertion
This is the assertion following the last step of an algorithm which
describes that goal state of the associated problem, that is, after the
associated algorithm has been executed.
Invariant Assertion
This is an assertion that is true under the execution of a step in an
algorithm irrespective of the number of times the step is repeated (both
before and after the execution of the step).
Pre-condition
A precondition is the assertion preceding a step of an algorithm. By this
definition, you will see that Initial Assertion is a precondition.
Post condition
A post condition is the assertion following an algorithm step and by this
definition, it also means that Final Assertion is a post-condition.
Generally, precondition and post-condition are called Intermediate
Assertions and they generalize Initial and Final Assertions respectively.
Definition (Algorithm)
An Algorithm is a prescribed set of well-defined rules or instructions for
the solution of a problem in a finite number of steps. On the other hand,
you can define an algorithm to be a sequence of well-defined, finite
steps, ordered sequentially to accomplish a task.
In fact, most recipes for dishes are simply algorithms, however, with the
avoidance of a statement such as "Add Salt to taste". Why? The reason
is that an algorithm step should not contain such an ambiguous
statement.
Algorithm Criteria
Every algorithm is expected to satisfy the following criteria:
• Input Criterion
• Output Criterion
• Precision Criterion
• Finiteness Criterion
• Efficiency or Effectiveness Criterion.
The above five criteria will now be discussed below. Input Criterion
There should be zero or more values which are externally supplied to
the algorithm.
Output Criterion
An algorithm should provide an output of implementation or
experimentation. This is very essential to check the correctness of the
algorithm.
Precision Criterion
Each step of an algorithm must be clear without any ambiguity or any
inherent assumptions.
Finiteness Criterion
An algorithm must terminate after a finite number of steps. There
should also be a stopping criterion to terminate an algorithm in a case of
a step with repeated execution.
Efficiency Criterion
Each step of an algorithm must be sufficiently basic that it can be
carried out in principle. That is, each step must be feasible (in addition
to being definite or precise). There must never be an impossible task
included in algorithm steps. In actual programming, an example of
impossible tasks is when a quantity is being divided by zero.
Algorithm Complexity
What is meant by algorithm complexity here is simply the difficulty of
solving computational problems, measured in terms of some resources
employed during the computational process. This is described below.
Algorithm Representation
• Pseudocode
• Flowcharts
• Formulae.
There are other forms of representing algorithms which you may not
bother about for now at this level. Some of these forms are:
• Decision Trees
• Nassi-Shneidermann Structured
• Flow Diagrams (NSSF)
• Warnier-Or Diagrams.
Apart from the first three forms listed above, the last three are seldom
used today despite some of their merits, especially the NSSF diagrams.
You will be introduced to flowcharts in the next unit. However you will
see the definition of Pseudocode below.
Definition (PSEUDOCODE)
ALGORITHM name
DECLARE
definitions and declarations
EXECUTE
statements to be executed
END name.
• Algorithm Name
• Declarations
• Executable Statements
• End of algorithm.
ALGORITHM average
DECLARE
a, b, c : REAL
EXECUTE
INPUT a, b
c ? (a+ b)/2
OUTPUT ‘c=’, c
END average.
The above example finds the average of two numbers. You can see
below how the above Pseudocode can be transformed easily into a
Pascal code.
END.
variable ? expression.
Instruction Execution
The instructions in an algorithm are usually executed one after the other
as they appear in the algorithm steps.
Algorithm Completion
Generally, an algorithm is completed with the execution of the last
instruction. However, an algorithm can be terminated at any
intermediate state by using the exit instruction.
4.0 CONCLUSION
In this unit, you have learnt the basic concepts of problem theory and
how they are related to algorithm development. The unit has also shown
you the essential criteria that characterize ever algorithm. If you
remember, they are:
• Input
• Output
• Precision
• Finiteness
• Efficiency.
Finally, in this unit, you have been introduced to some various forms
of representing algorithms.
5.0 SUMMARY
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Types of Flowcharts and Symbols
3.2 Applications of Flowcharts
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
2.0 OBJECTIVES
or
The arrows ? represent the flow of data and they are usually
accompanied by comments to indicate the flowing data. There is what is
called SANDWICH PRINCIPLE which states that "Every bubble falls
between at least two data flow arrows".
System Flowcharts
While Data Flow Diagrams focus on the flow of data and the general
operations in using data to obtain results, system flowcharts perform the
same role but in addition specify the data processing techniques to be
used. Since system flowcharts provide more details, they are therefore
referred to as "Device-Specific" _, especially when automated
processing methods are employed.
Forms Flowcharts
The DFDs and system flowcharts already considered give no any
indication of the units of an organization that perform the data
processing task and which units use the information. However, Forms
Flowcharts are simply employed to supply this information of how
documents and forms flow among the organizational units. They don't
indicate how data are processed.
Program Flowcharts
You have already seen three types of charts above that provide the
overview of the flow of data and the assignments of functions among the
agents in a system. When all the agents are human, you call the system a
MANUAL SYSTEM. But when computers are employed to perform
some procedures, the system is called a COMPUTERISED SYSTEM.
Flowchart Symbols
Flowcharts generally make use of symbols that are assigned specific
meanings. The common symbols are as follows, in the table below:
Table 1 ANSI Flowchart Symbols
There are yet some few other symbols not included in the above table
that are among the symbols adopted by ANSI and also ISO
(International Standards Organisation).
Now, you can draw these symbols easily by using drawing tools
available in some software packages such as Flowcharter or Microsoft
Word Autoshapes. You will be given examples associated with the use
of the above flowchart symbols in the next section.
• Macro Flowchart
• Micro Flowchart.
A macro flowchart is the flowchart that outlines the general flow and
major segments of a program. It is also called the "Modular program
flowchart" where the major segments of the program are called the
modules. Specifically, macro flowcharts are those called Block
Diagrams as earlier mentioned.
Now, you remember that you were being introduced to various types of
flowcharts and you are yet to treat structure and HIPO charts before it
was seen to be getting a bit late to introduce the flowchart symbols.
Now, see the brief descriptions of the remaining two types below:
Hierarchy or Structure Charts
Structure charts are diagrams that depict the procedures of an operation
in a hierarchical form. A typical example of a hierarchical chart is the
one showing the organizational structure of an organization. Structure
charts are usually read from top to bottom and left to right and they
concentrate majorly on those procedures that should be executed to
perform the job or each module. This is referred to as "Top-Down
analysis".
HIPO Charts
HIPO (pronounced "hypo") as you have already learnt stands for
Hierarchy plus Input-Processing-Output. HIPO charts have design
approach similar to that of structure charts and they are more concerned
with WHAT is done than with HOW it is done. Since the emphasis in
this unit is more concerned with flowcharts that directly provide aids to
programming, you will therefore presently not be bothered with detail
description of HIPO charts.
Answer
Program flowcharts and system flowcharts, but more specifically the
former (i.e. program flowcharts).
However, remember you used Pascal Pseudocode for the above example
in unit 3. Before drawing the simple flowchart for the problem, modify
the Pseudocode as follows:
Start
read: a, b
set c = (a + b)/2
if c <0 then
write: "Average is negative"
re-start
else
end if write: c
End.
The flowchart for the above problem is as follows:
Example 1
The above flowchart uses the most commonly used symbols, namely: •
Terminals
• Input/Output
• Processing
• Decision,
The original problem was deliberately modified for you to use the
Decision box in the flowchart.
Now your exercise below
SELF ASSESSMENT EXERCISE 2
Reconstruct the above flowchart for the same problem with manual
input and a print output.
Answer
The new flowchart is as follows:
Example 2
START
DOWHILE staff number ? 0
READ: staff weekly work record
IF work is hourly THEN
CALCULATE gross pay
ELSE
Pay = (annual salary)/52
ENDIF
Update payroll file
ENDDO
END.
In the above Pseudocode, the calculation of the gross pay is taken to be
a pre-defined process. The flowchart is as follows in an unbroken form:
As you have already learnt in the previous section of this unit, the
predefined process box is representing a module of the program, which
in the above example is the segment of the program that computes the
Gross Pay.
Later in your course of study, you will definitely came across more
complex problems that will demand the use of more of the flowchart
symbols you have already been introduced to in this unit. You will now
round up the unit.
4.0 CONCLUSION
In this unit, you were taken through the general types of flowcharts
employed in system analysis and design with special emphasis on
program flowcharts.
As you learnt in the unit, program flowcharts can be divided into two:
Macro flowcharts and Micro flowcharts. While the former focus on the
major segments of a program, the latter show the logic of the
programming in full detail. There are standard symbols approved by
ANSI and ISO as presented in Table 1 in the unit. You need to get used
to the symbols since flowcharting provides a very good way of
documenting your program.
5.0 SUMMARY
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Basic Logical Structures
3.2 Structured Programming Methods
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
2.0 OBJECTIVES
Before you go into the three types of logical patterns that characterize
structured programming you need to understand the benefits of this
method of programming. To start with, you need to know that without a
standardized method of solving a problem, a programmer may spend
more time than expected in finding an appropriate solution method and
in the development of the associated program. Structured programming
gives room for well-thought-out program logic and provides an attempt
to keep programs as simple and straight forward as possible.
Basically, structured programming employs Modular Approach and
Top-Down Principle, the concepts which you have come across in the
previous units. Now, the fundamental objectives of structured
programming are as follows:
• Sequence Structure
• Selection Structure
• Iterative Structure.
Sequence Structure
In sequential structure or what you can also call sequential logic, the
steps are executed one after another as serial operations. This can be
illustrated by the following flowchart:
Process A
Process B
Process C
Selection Structure
The selection structure uses conditions and based on the decision taken
by the computer after comparison of data, one of the available
alternatives is selected. For this reason, it is also called Alternation
structure or Conditional structure. You can also call it the IF structure.
The selection structures can be categorized as follows:
• Single Alternation
• Double Alternation
• Multiple Alternation.
Single Alternation
This is described by the following flowchart:
Double Alternation
The structure is illustrated below:
You will do the following exercise now.
As you can see in the above flowchart, if the condition is satisfied, then
the instruction(s) in the THEN process box is/are executed, otherwise
the instruction(s) in the ELSE process box is/are executed.
Multiple Alternation
The structure is seen in the following flowchart using three conditions:
THEN
Process - I
THEN
Process - 2
THEN
Process - 3
THEN
Process -4
ELSE Process
Looking at the above flowchart, you will see that if none of the four
conditions is satisfied, then the process in the ELSE box will be
executed.
Iterative Structure
Iterative Structure is of the following two forms generally
• WHILE Loop
• DO-UNTIL Loop.
WHILE Loop
To start with, an iterative structure is also called the Loop or Repetition
structure. Now the WHILE loop which you can also call the DO-
WHILE structure is illustrated below:
FALSE
Condition
TRUE
Condition
WHILE condition DO
statement(s)
ENDWHILE.
When using the WHILE loop, the following points are essential:
Now, see the other type of loop structure in the following illustrative
flowchart.
DO-UNTIL Loop
You can also call the above structure the REPEAT-UNTIL structure. A
Pseudocode for this logical structure is therefore as follows:
REPEAT
Statement(s) UNTIL
Condition
For Loop
This is illustrated below, using the following flowchart:
FOR I = j TO k by s DO
Process
FOR I = j TO by s DO
Statement(s)
ENDFOR.
i . index variable
J . initial value
k . final value
s . step size.
Essentially, the index variable i controls the loop while the step size
can either be negative (to implement decrement) or positive (to
implement increment). When the step size is not stated, the default
step size is taken to be 1.
• Level programming
• Path programming.
Level Programming
Programming by level is also called Top-down programming technique
and it is characterized by writing all the program modules on level one
or top-most level before programming the modules on level two. In the
same vein, the modules on level two are programmed before the
modules on level three, and so on.
An illustration is as follows:
Then, look at the second technique illustrated below:
Path Programming
This is a method where all modules along a logical path in the program
are developed in sequence. See the illustration below:
The Path Programming is also called Backtracking programming. The
method helps the programmer to backtracks to the first unwritten
module that is directly connected to the path being developed, until all
modules are developed.
Before you round up this unit, remember you have been taught in the
unit that in structured programming, each module should have only one
entry point and one exit point. Do you remember what we call a
program characterized by one entry point and one exit point? It is
called a Proper Program. The modules are usually linked together by
DRIVER PROGRAMS. A driver program simply directs the computer
to ENTER the appropriate module, and when the computer EXITS the
module, control is returned to the driver program. You will now round
up the unit.
4.0 CONCLUSION
In this unit, you have been introduced to the basic logical structures
that characterize structured programming. A very major objective of
structured programming as you have learnt in this unit is to increase
program clarity by reducing complexity. This is the fundamental
principle behind the use of modular approach and top-down technique
in structured programming.
5.0 SUMMARY
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 BASIC Variables and Characters
3.2 Reserved Words or Keywords in BASIC 4.0
Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
Versions like BASICA and GW BASIC are already taken over by other
versions listed above. Visual BASIC is a version of the language
specially designed for Windows platforms and is today one of the
programming tools with very high preference among programmers.
However, it is interesting to know that BASIC language remains one of
the best programming tools gaining wide acceptance even in the face of
rapid developments of various computing platforms.
2.0 OBJECTIVES
The BASIC Interpreter or Compiler (since you can compile your BASIC
program with Turbo BASIC, KBASIC, MediaBASIC and others, for
Example) handles variables as names of memory locations. Memory
can just be visualised as a litn2.e Post Office with its Post Office
boxes as memory locations or cells. You know that each Post Office
box has an address to identify it. The contents of the box can change
from time to time but the address remains uniquely unchanged. The
same occurs in the computer memory. Now, in addition to identifying
memory locations, variable names are also used to identify the types
of data being stored in the computer memory. Though there are
several types of data, in this unit on BASIC, you will only be
introduced to two, and hence two types of variables, namely:
• Numeric Variables
• String Variables
NUMERIC VARIABLES
Generally in BASIC, variable names must start with a letter and can be
followed with numbers or other letters, For example, a variable name
can be as long as 40 characters (as in MS QBasic). So, examples of
variables names are Al, B3, AB4, JONH, REJ2, Y5, and so on.
STRING VARIABLES
Variable names are also employed to represent character data in
memGry. Character variable names are similar to numeric variable
names, but they refer to memory locations containing character
strings, where collections of characters are called String Variables.
To specifically distinguish a string variable, the dollar symbol $ is used
at the end of the variable name. Examples of string variable names are
therefore as follows:
A$, JOHN$, B2$, REJ$, etc
It is good for you to also know that the dollar sign $ also appears at the
end of almost every BASIC reserved word that deals with strings.
Now, while the values of numeric variables are simply numbers, the
values of string variables are given as characters enclosed between
double quotes, such as "NAME", "OK", etc. the space character can
also be made as part of the string.
You may find the following points very helpful as you choose your
variable names:
i. ADA
ii. $x
iii. TAX
iv. 8BIG
v. W.3
Answers
i. Acceptable
ii. Unacceptable — the dollar sign ($) must be placed after the
name.
i i i . Acceptable
iv. Unacceptable — a letter must begin the name and not a
number.
v. Unacceptable (for common versions) — only letters and
numbers are allowed in the name.
Below, you will now see the meanings of some characters or symbols
used in BASIC language.
ALPHABETIC CHARACTERS
a — z or A — Z
NUMERIC CHARACTERS
DATA-TYPE SUFFIXES
$ String
! Single Precision
# Double Precision
% Integer
& Long Integer
MATHEMATICAL OPERATORS
+ Addition
* Multiplication
- Subtraction
= Relational symbol or Assignment symbol
< Less than
> Greater than
. Decimal point
∧ Exponentiation
<> Not equal to
/ Division
<= Less than or equal to
>= Greater than or equal to
\ Integer division
You will see the use of some of the above symbols and characters in
subsequent units on BASIC in this course. In the next section, you will
now be introduced to some keywords or reserved words in BASIC
Just as words have their meanings in the natural language, the same
thing applies in programming languages, reserved words generally
describe the operations to be performed by the computer. If your
reserved words are wrongly coded, you will definitely receive syntax
error message during the running of the program. As a vital
programming rule, it is essential to avoid using any of the reserved
words as a variable name to avoid program errors during execution.
Now, for your understanding, the BASIC reserved words are grouped
below according to their programming tasks.
What a long list! Yes, but you may not use most of the above keywords
in your programming lifetime!. Some programmers don't even know that
some of the above keywords exist in BASIC since their program
demands do not necessitate their use.
The above list of keywords simply shows you that BASIC is a very rich
language in terms of programming tools. Getting grounded in BASIC
will help you a lot in studying other object oriented versions BASIC
such as Visual Basic.
Some of the reserved words as seen above appear under more than one
programming task. In the subsequent units, you will see the use of some
of the commonly used keywords in some examples.
4.0 CONCLUSION
This unit has introduced you to the two common types of variables used
in BASIC programming, namely:
• Numeric Variable
• String Variable
The unit also shows you the various types of characters generally
employed in BASIC. As in natural language and in other programming
languages, there are specific meanings to keywords in BASIC and the
unit has provided you a very extensive list of reserved words used in
BASIC.
5.0 SUMMARY
BASIC language is still today a good language with its wide range of
programming tools for the development of a wide range of
applications. It's basic knowledge is very essential for programmers
who want to quickly understand for example other object oriented
versions of BASIC such as Visual Basic, KBASIC, etc.
3. State three reserved words in BASIC that can be used under more
than one programming task.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Commonly Used BASIC Statements
3.2 BASIC Programming Environment Limits
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
As already learnt in the last unit, BASIC programming has its peculiar
features. For example, you have learnt that a variable name can be as
long as forty (40) characters in BASIC programming. That simply
suggests to you that BASIC Programming language has its own
environment bounds. This unit will therefore also introduce you to the
limits that characterize BASIC Programming environment before you
go into in-depth programming using the language.
2.0 OBJECTIVES
Figure 1
As you can observe from the above figure, the environment is also
menu-driven but with available option to compile the source program
into an EXEcutable file. This is shown in the next figure below:
Figure 3
The editing window changes to the window when you are ready to type
your BASIC source code:
Figure 4
Before you see the forms of the above BASIC statements, it is good to
state that a BASIC statement has the following general form:
REM Statement
The above code has a REM statement broken into two lines. In line 20,
the single quote character is used in place of the reserved word REM.
You may have a REM statement without any comment just to create an
empty line within the code for good readability. Thus you may have
REM statements that look like the following:
40 REM
50 REM ***************
The assignment or what is also called the LET statement is simply used
to assign values to variables. The general format is as follows:
In BASIC, the equality (=) sign is the assignment symbol. In the above
general format, the expression on the right hand side can be any of the
following:
• A constant
• An Arithmetic formula
• A variable.
As you can see in the above general format, some versions of BASIC
(such as MS-Quick BASIC and Turbo Basic) do not require the
reserved word LET in an assignment statement. Hence it is optional.
Examples of assignment statements are as follows:
10 X = 25 B$ = "NOUN"
20 Y=X^2 + 3*X-4
30 N$ = B$
40 T = Y
Line 10:
25 - Numeric constant
"NOUN" - String constant.
Line 20: X A 2 + 3*X — 4 - A formula
Line 30: B$ - String variable
Line 40: Y - Numeric variable.
For your observation, line 10 has two statements combined into one
line by using the colon (:) symbol as already introduced to you in the
last Unit.
INPUT Statement
SCORE =?
The question mark (?) simply indicates that the program is requesting
for an input from the keyboard.
PRINT Statement
Very central to the output phase of any BASIC program is the PRINT
statement. This is used to display the results of computer processing.
To send an output to a printer, you use LPRINT instead of the PRINT
statement.
• Variables
• Arithmetic expressions
• Literals
• Combination of the above three types.
10 PRINT X : PRINT
20 PRINT A, B
30 ? C; D
40 PRINT “VALUE=”, V
50 PRINT 3* A — B
60 PRINT T$
70 PRINT "THE SOLUTION IS"
80 LPRINT W
In line 10, the second PRINT statement prints an empty line. This is
necessary to provide a good space between output lines. In line 30, the
question mark (?) is used in place of the reserved word PRINT. In
QuickBasic, the symbol is automatically changed to the word PRINT
when you move out of the line to the next. When line 80 is executed,
the value of the numeric variable W is sent to the printer.
Now, you will observe that semicolon (;) is used in the PRINT
statement instead of the comma (,) symbol. These two characters give
different formats to the result output of a PRINT statement. Assuming
that the values of A,B,C and D are as follows: A = 2, B = 1, C = 23, D
= 0. When line 20 is executed, you will have an output like this:
2 1
23 0
You will observe that the values of C and D are printed immediately
after the other while the values of A and B are printed with spaces
between them, specifically, there will be 14 spaces between them.
Generally, BASIC divides your output screen into what are called
PRINT ZONES. There are five (5) of them, the first starting at column
1, the second at 15, the third at 29, the fourth at 43, the fifth at 57.
Using semicolon in your PRINT statement is a way of giving enough
space between the printed values. However, a more flexible way to
format your output is to use the TAB function which will be introduced
to you in the next unit.
GOTO Statement
Very often, when you use an IF ... THEN statement, one condition
causes the computer to execute the next line of BASIC code whit?
another condition requires it to execute some code somewhere else if
the program. Therefore, in order to move or branch to the code that
doesn't follow the IF... THEN statement, you need an unconditional
branch statement, which is the GOTO statement. That means that,
every time the computer encounters a GOTO statement, it branches to
the specified program line irrespective of any condition in the program.
As you will remember, you have learnt in this course that structured
programming discourages GOTO statements.
10 CLS : INPUT A
20 IF A <3 THEN GOTO 40
30 ? : PRINT
40 END
This statement works just like IF ... THEN statement used in the above
BASIC code, except that the ELSE part is executed if the condition is
not satisfied.
An example is as follows:
10 CLS
20 INPUT X
30 IF X> 0 THEN PRINT "POSITIVE" ELSE? X
40 END
END Statement
Study the following flowchart and provide the equivalent BASIC code:
Answer
• Names
• Strings
• Numbers
• Arrays
• Procedures
• Files
Name, String and Numbers
In this unit, you have been introduced to the common statements you are
going to frequently use in BASIC programming. The most common
BASIC Interpreters today are the Microsoft QuickBasic and Turbo
BASIC Interpreters with the latter having a menu facility to compile
your BASIC code into an executable file. Remember that in Unit 1
Module 2, you were introduced to many other versions of BASIC
Interpreters and Compilers.
The Unit has introduced to you the various limits that characterize the
BASIC programming environment.
5.0 SUMMARY
As you have learnt in this unit, there are same programming limits in
BASIC associated with the following:
• Names
• Strings
• Numbers
• Arrays
• Procedures
• Files
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Data Entry Statements
3.2 Using Loops in BASIC
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
In the previous two units, you have been introduced to how to get started
with BASIC programming. Definitely, as you have seen under the
reserved words in BASIC, there is so much to learn about BASIC
statements that cannot be covered in this course since you are expected
to learn some fundamental concepts in other programming languages as
well.
2.0 OBJECTIVES
In BASIC, there are three commonly used methods of entering data into
BASIC programs. The three methods use the following BASIC
statements:
• INPUT Statement
• LET or Assignment Statement
• READ/DATA Statement.
Good enough, you have been introduced to the first two types of
statements in the last unit. You will therefore be taught in this unit the
use of the READ/DATA statement as another way of entering data into
your BASIC program. Before then, see below the general guidelines on
using the three statements given above.
The READ and DATA statements always work together because values
contained in the DATA statements are usually assigned to variables
listed in the READ statements. The general format for the READ and
DATA statements is as follows:
10 READ B, C, D$
20 READ X, Y
.
.
.
60 DATA 20, 40.2, "DAY"
70 DATA 60, 32.
Generally, the READ statement tells the computer to search through the
BASIC program to locate the first DATA statement. The computer then
assigns your data values consecutively to the variables in the READ
statement. You will therefore see the reason why the third value in line
60 in the above code is a string constant, because the third variable in
line 10 is a string variable.
BASIC maintains what is called Data Pointer. The pointer simply keeps
track of the next data element to be read. Thus if a READ statement is
attempted after the data list has been exhausted, a message is going to
alert you that the end of the data list has been reached. The BASIC
Interpreter or Compiler takes all the data items in all the DATA
statements and forms one combined data list, ordering the DATA
statements from lowest line number to the highest and then using the
data from left to right.
Now, though you have already been told that DATA statements may
appear anywhere in a program, however it is a common programming
practice to group them together either at the beginning or the end of a
program. Such a practice makes program debugging easier.
10 CLS
20 READ DS, ER, B$
30 PRINT TAB (2); DS; TAB (4); ER; TAB (8); B$
40 DATA 23, 45.5, BIRTH =
50 END
Do you notice any error(s) in the above code? There is no any error at
all. The interesting thing about DATA statement is that it is the only
place where character strings do not have to be enclosed within
quotation marks as used in line 40 above for the string variable (B$)
value.
In the above code, attempt has been deliberately made to introduce you
to the TAB function which is normally used with PRINT statement to
provide flexibility in your output format. The general format for the
TAB function statement is as follows:
TAB (expression)
where the expression in the parentheses may be a numeric constant,
numeric variable or arithmetic expression, to tell the computer the
column at which printing is to start. For example in the above code, the
computer is to tab to column 2 before printing the value for variable DS.
The semi colon after the TAB function simply instructs the computer to
start printing at the next column, i.e. column 3.
What happens if comma (,) is used in place of semicolon (;) after the
TAB function?
Answer
The printing will be done in the pre-defined Print Zones, ignoring the
columns specified in the TAB function expression.
line # (optional) FOR loop variable initial value TO terminal value STEP step value
.
.
.# (optional) NEXT loop variable.
In the above general format, the loop variable is also called the INDEX
variable. The STEP statement is optional but only necessary when step
value is different from the default value 1. As you have already learnt in
unit 5, the step size can indicate increment or decrement.
An example of FOR ... NEXT statement is seen below:
10 PRINT
20 FOR X = 1 TO 3 STEP 0.5
30 Y = SQR (X)
40 W = INT (X)
50 PRINT Y, W
60 NEXT X
70 END
1 1 1
1.5 1.224745 1
2 1.414214 2
2.5 1.581139 2
3 1.732051 3
Again, the above program has included two BASIC Library functions:
What other expression can you use in place of the SQR function?
Answer
SQR(X) = X ^ 0.5
There are cases when you can have nested loops. That is, all of one loop
can be within another loop. See an example below:
10 FOR 1 = 1 TO 4
20 FOR J = 1 TO 9
30 PRINT I; J
40 NEXT J
50 NEXT 1
It is interesting for you to also know here that FOR... NEXT loops
equally help you to enter successive data items into a program instead of
using the INPUT statements.
Now, below are very essential rules you should remember when using
FOR... NEXT loops.
i) -The initial value must be less than or equal to the terminal value
when using a positive step value, i.e. when implementing an
increment.
ii) When implementing a decrement, i.e. when the step value is
negative, the initial value must be greater than or equal to the
terminal value.
iii) The step value should never be o, since this would result in an
endless loop.
iv) Transfer can be made from one statement to another within a
loop. However, you cannot make a transfer from a statement
within a loop to the FOR statement.
v) The value of the index (or loop) variable should not be modified
by program statements within the loop.
vi) The initial, terminal and step expressions can be made up of any
numeric variable, constant or arithmetic expression (or formula).
vii) Each FOR statement must have an associated NEXT statement.
viii) FOR and NEXT loops can be nested. However, the NEXT
statement of the inner loop must precede the NEXT statement of
the outer loop.
Answer
Line # DIM variable I (limit 1), variable 2 (limit 2), variable 3 (limit 3),
...
The variables are the array names while each limit is an integer constant
that represents the maximum number of memory locations required for a
particular array. You don't actually require a DIM statement for arrays
of ten or fewer elements.
Answer
As you can see above, the subscript of an array variable can be:
• a Number
• a Numeric variable
c
• an Arithmetic expression.
10 FOR T = 1 TO 9 STEP 2
20 Y (T) T + 3
30 Y (T+1) T * 3
40 NEXT
From the above code, you have the following results of processing:
10 DIM N$ (20)
20 FOR J = 1 TO 3
30 READ P(J)
40 N$(J) = "PRICE"
50 PRINT N$(J); J, P(J)
60 NEXT J : GOSUB 200
70 DATA 2.23, 4.5, 6.3
80 END
200 REM Below is a SUBROUTINE
210 PRINT "PRICES INSUFFICIENT"
220 PRINT
230 RETURN.
PRICE 1 2.23
PRICE 2 4.5
PRICE 3 6.3
PRICE INSUFFICIENT
In the above program code, you have been introduced again to another
statement, namely, the GOSUB statement which is a special case of the
GOTO statement. The GOSUB statement is specifically used to transfer
control to a program SUBROUTINE, which is a block of code that
performs one task each time it is executed. When you divide your
BASIC program into sections such as subroutines, you are using a form
of structured programming which you already know is called Modular
Programming. Usually, you end a subroutine with a RETURN
statement while it is a good custom to begin your subroutine block with
a REM statement as seen in the above code.
4.0 CONCLUSION
In this unit, you have been taken through additional BASIC statements
such as:
• READ/DATA statements
• FOR.. .NEXT statements
• DIM statements.
• GOSUB...RETURN statements
• Some library function statements.
The unit has explored different ways of using some of the statements to
enter data into your program apart from the INPUT and the assignment
statements treated in the previous unit.
This unit, apart from introducing you to more BASIC statements has
equally treated the fundamental concept of an ARRAY and how it is
treated in BASIC. Though the examples shown focused mainly on One-
Dimensional arrays, you can equally encounter Two-Dimensional
arrays such as matrices in your programming assignments. Two-
Dimensional arrays are simply represented as follows:
You have already learnt in this unit that the DIM statement is normally
used to specify the number of array elements. The unit has also
introduced you to the GOSUB statement which is a special case of
GOTO statement.
With this unit, being the third unit dedicated to BASIC programming,
you can now get started with BASIC programming problems while the
table of reserved words in unit 6 will help you to develop yourself in
BASIC programming beyond what you have covered in this course.
1. State the various types of BASIC statements you can use to enter
data into your program.
2. State an important rule to be followed when using nested loops in
BASIC.
3. Identify the error(s) in the following program:
10 PRINT
20 FOR I = I TO 4 STEP -2
30 PRINT 2 *1
40 FOR J = I TO 5
50 PRINT J
60 NEXT I
70 NEXT J
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Getting Started with Fortran Programming
3.2 Fortran Variables and Constants
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
• Fortran II - in 1958
• Fortran IV - in 1962
• Fortran 66- in 1966
• Fortran 77 - in 1978
• Fortran 90/95 - in the 90s.
To start with, this unit will give you a snapshot of Fortran language
features, especially, some rules guiding its program coding before
introducing you to descriptions of variables and constants in Fortran.
Your study objectives are as follows:
2.0 OBJECTIVES
• Microsoft Fortran 77
• FORTE — Fortran Environment
• Fortransoft
• ProFortran
• WATFOR 77— Interpretive Fortran Version.
Each line of Fortran code can be typed using any ASCII (text) editor
such as Microsoft Notepad editor. However, the code lines must be
entered according to the following rules:
It is good to state here that Fortran 90 allows free form source coding,
that is, there is no restriction on where Fortran statements are to be
located as specified in the above Fortran 77 rules. Moreover, a
comment can be placed at the end of a statement provided an
exclamation mark (!) precedes the comment.
Before you get introduced to the Fortran variables and constants, below
are the common characters recognized by Fortran language:
Remember that the above list depends on the Fortran compilers. You
can also see immediately below the operators employed by Fortran.
Fortran Operators
• Arithmetic Operators
• Relational Operators
• Logical Operators.
Arithmetic Operators
+ - Addition
- - Subtraction
* - Multiplication
/ - Division
** - Exponentiation
= - Assignment.
Relational Operators
(Please, take note of the dots (.) before and after the two characters)
Logical Operators
You will start with the variables since a great deal of flexibility is
gained when you allow a quantity to be referred to by a name rather
than a constant value. Generally, the major aim of any computation is
to find unknown values from known ones.
• REAL
• NTEGER
• OUBLE PRECISION
• OGICAL
• COMPLEX
• CHARACTER
Among all the types of Fortran variables, the most common two are the
REAL and INTEGER types. A very peculiar characteristic of Fortran
is that it assumes that the type of a variable is implied by its spelling.
The integer and real variables are identified as follows:
For example, the following are not valid variable names in Fortran
INTEGER X, Y, ZERO
REAL 12, JOS, NUM.
B = (3/5) * (F — 32)
NUM = R *J/3
The above two Fortran assignment statements will definitely give you
errors when executed. The errors can be corrected as seen in the
modified expressions below:
From what you can see above, it is always advisable to use decimal
points in real numbers to avoid mixed-type errors.
Explain the roles of the REAL and NT functions used in the second
Fortran statement above.
Answer
By writing:
R *REAL (J)/3.0
the expression on the right hand side can now be assigned to NUM,
which is an integer. Another way of carrying out the conversion on the
right hand side is by writing the whole assignment as follows:
NUM = INT(R)* J/3
This last form of expression is simpler and may still yield the same
result like the other one but INT function is a Truncator.
Just as there are several types of variables apart from the real and
integer variables, there are also other constants allowed in Fortran in
addition to the real and integer constants. For example, in Fortran, you
also have the following types of constants (to be treated later in other
units):
• Complex Constants
• Logical Constants
• String Constants.
Answers
i. Variables: The variable names SAB and 62A are not Fortran
valid variable names while X4+2 is containing an operator.
ii. Assignments:
a. A = X**2 + REAL (J) **2
b. No any error
c. NAT = TNT (REAL (I) **2 I- 4.5 * REAL (J).
4.0 CONCLUSION
In this unit, you have been taken through the fundamental rules guiding
Fortran programming and coding. As you have learnt in this unit there
are some rules to be followed while coding your Fortran source
programs. For example, column 1 is specially reserved for character
"C" to enter. your comment. This is analogous to using REM in BASIC
language. Your Fortran statements are to be entered between columns 7
and 72. However, the column rules that exist in Fortran 77 are rather
non-existent in the Fortran 90 version whose compiler is not yet widely
available.
This unit has equally shown you the types of variables and constants
employed by Fortran. While emphasis has been laid on the most
commonly used types, that is, the real and integer types, you will be
introduced to the other types later in the course.
5.0 SUMMARY
As you have learnt in this unit, Fortran is very quick to assume the type
of your variable by the first letter of the variable. Every variable name
that starts with I, J, K, L, M and N is assumed to be an integer unless
you change the presumed type by using the declaration statement
keyword REAL or its form of intrinsic function. Starting a variable
name with other letters is assumed that the variable is real by Fortran.
Remember that the unit also introduced you to the types of operators
used in Fortran language programming. These operators will be used in
some examples in the subsequent units. With all that you have learnt in
this unit, you are now ready to start using some simple statements in the
next unit.
1. From what you have learnt about Fortran 77 in this unit, state the
two main areas of strict compliance with Fortran rules .............
2. State types of variables and constants available in Fortran
programming ..........................................................................
3. Rewrite the following expressions to correct the errors:
(a) J2 = K**2.0 + 3 *M4
(b) REJU = I - 4*B**3
(c) NAME = J/3 + 4 * R.
7.0 REFERENCES/FURTHER READINGS
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Fortran Reserved Words and Library Functions
3.2 Using READ, WRITE and FORMAT Statements
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
2.0 OBJECTIVES
The Fortran reserved words are listed below with the general format of
using them, as supported by most Fortran compilers.
Below, you are also introduced to the Fortran Generic Intrinsic
functions with their meanings, caution should be taken in using Fortran
library functions since specific names are given to the functions
according to the type of value expected from processing, that is,
whether real, integer, complex or double precision value.
Now, study the table below:
In the above table, the fourth column is to guide you on what data type
to expect when any of the intrinsic functions is evaluated on different
types of arguments. For example, "C ? R" shows that the function -
CABS" produces a real number, taking a complex expression or value as
the argument. Some of the above functions will be used in some
examples in this course.
Now, get started with learning the most frequently used Fortran
Statements in the next section.
READ * [, list]
Please, you should remember that the square brackets are not part of
Fortran but simply denote an optional item. That is, the comma and the
list are optional.
READ*, X, Y, Z
causes the computer to request for real value data inputs from the
keyboard, that is, the STANDARD INPUT DEVICE. Remember that X,
Y. 7 are assumed to represent real numbers by Fortran. So, when
entering the values, they must contain decimal points.
Another way of using the READ statement is as follows:
READ(*, *) [, list]
This form of READ statement requests for input data list from the
keyboard, giving you no specified data format. A more general form of
this variant of READ statement is as follows:
where 'unit' identifies the INPUT device from which the data list is to
be read. The parameter `f" indicates format description which is usually
a number that locates the FORMAT statement to be used. The 'unit'
parameter is also a number specified
specified in an OPEN statement where the
path and the name of the input data file is specified. Before you see
some examples, see the general forms of WRITE or PRINT statements
also below:
In the above forms of output statements, the `*' parameter denotes the
STANDARD OUTPUT DEVICE, that is, the MONITOR. This is when
'unit' = `*' in the WRITE statement.
Now, look at the following example as shown in the two figures below,
using the WATFOR77 interpretive environment. The WATFOR 77 acts
like an Interpreter and helps you to receive immediate results of
executing your Fortran program.
Figure 1
By typing 'run' or 'RUN' at the command prompt, the program gives you
an input prompt of blinking cursor
cursor to enter your data. In the above
program, two real values are requested whose sum of squares is to be
assigned to Z. Entering:
X = 12.4
Y = 45.78
the result yields Z = 2249.5680000
Figure 2
Below, you will now see the use of FORMAT statement, which is
usually used to add flexibility to READ and WRITE statements.
See this in the Fortran program code below, using the WATFOR 77
program editor and interpreter.
Figure 3
In the above program, There are three output statements: the first prints
the string:
The second prints an empty line while the third prints the values of X,
Y and Z, using a FORMAT statement in line number 2. The FORMAT
statement directs the computer to print 1 blank space before printing
the first real or what is also called Floating Point number X. The
number should be of length 5 and 2 decimal places. Usually the
decimal point is part of the length. The specification is given by
"F5.2".
You will observe that even though the value of X is read into the
program as 12.4, but it is finally printed as 12.40 to obey the FORMAT
statement specification. You will also see that though the value of Y is
read in as 45.78, it is finally printed as 45.8 because of the specification
"F5.1" in the FORMAT statement. The value of Y is to be printed after
2 blank spaces as specified by 2X in the statement.
Below is the general format for the FORMAT specification for each of
the variable types allowed in Fortran:
State the Fortran equivalent keyword or symbol for the follow BASIC
language keywords and symbols:
i. REM
ii. INPUT
iii. SQR (iv) ^ (v) PRINT
Answers
i) C — in the first column
ii) READ
iii) SQRT
iv) **
v) PRINT or WRITE.
INTEGER A, B
C Program To Calculate Average of Two Numbers
READ *, A, B
MEAN = (A +B)/2
WRITE (*,*)
PRINT 5, A,B, MEAN
5 FORMAT (11Cl2,13,14)
END.
The above program converts A and B into integer variables from their
presumed real type. Here you see that the PRINT statement is used with
the FORMAT statement with line label 5. In the FORMAT statement,
A is to be printed as an integer of length 2, B of length 3 and MEAN of
length 4. To take care of the length specification, Fortran adds blank
spaces behind the values to make up for the number of spaces.
You will now round up this unit after this exercise below:
Answer
5 FORMAT (IX, 3I4).
4.0 CONCLUSION
In this unit, you have been introduced to the reserved words in Fortran
and the generic intrinsic functions. Just like BASIC language, you need
to be acquainted with the Fortran keywords to be able to use the rich
resources of its programming features.
And you have seen in the list of library functions, Fortran somehow
"discriminates" between the types of the functions according to their
data type. Like in variable names, the first letter of the function name
specified the type of value you should expect when using the function.
Fortran is very unique in its way of accepting input data and producing
the output of results. FORMAT statement is usually employed in
conjunction with the READ and WRITE statements to provide
flexibility.
5.0 SUMMARY
In this unit, you have really got started with Fortran programming with
the introduction to the reserved words and library functions. Get
acquainted with the common keywords to start with and you will soon
discover that Fortran is not difficult to learn.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 The Fortran DO Loop
3.2 Using IF... THEN... ELSE Statements
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
The unit will also show you how to handle alternation or selection in
Fortran through the use of IF ... THEN ... ELSE statements. This will
therefore afford you the opportunity of seeing how relational operators
are used in Fortran language. In the process of going through some
examples in this unit, you will be introduced to some additional Fortran
statements. Your study objectives for the unit are as follows.
2.0 OBJECTIVES
On the other hand, you can also express the general DO statement as
follows:
DO 10 J = 1.40
.
.
.
BODY OF LOOP
.
.
.
10 CONTINUE.
The above example simply directs the computer to repeat 40 times the
statements between the DO and CONTINUE statements. The block of
statements which constitutes the body of the loop is also called the
RANGE of the DO statement (including the terminating statement).
You learn how to program by studying program examples. So, study the
following program closely because it consists of additional features in
Fortran to be explained shortly:
PROGRAM ITER
REAL X, T, FF
C BELOW IS A USER-DEFINED FUNCTION
F(X) = X**2 +3.0
OPEN (7, FILE = 'C:\NOU\OUT.DAT',
$ STATUS = 'NEW')
WRITE (7,10)
10 FORMAT (2X, 'T' 10X, 'FCT))
DO 20 T = 0, 4, 0.5
FF = F(T)
WRITE (7,*) T, FF
20 CONTINUE
END
Definitely, you will observe that a few keywords have been added in the
above program. In brief, below are some additional features beyond
what you have learnt on Fortran in this course:
FILE =
STATUS =
ACCESS =
Others are:
IOSTAT =
ERR=
FORM =
RECL =
BLANK =
As you can see in the example above, two specifiers were used in the
OPEN statement, namely, "FILE =" and "STATUS =".
The STATUS specifier simply directs the computer to create the file
during the program execution, hence its status type is "NEW". Other
types of STATUS identifiers are:
• OLD
• SCRATCH
• UNKNOWN
As you can see from the output above, the file "OUT.DAT" can be
opened by you by any ASCII editor such as "Notepad".
In your DO ... CONTINUE statement, if the step size is not given, the
Fortran compiler takes the step size as 1, just like the BASIC language
interpreter.
There was a statement in the above example that was not necessary.
What is the statement and why?
Answer
The statement is
REAL X, T, FF
It is good to state here that the use of IF ... THEN ... ELSE statement is
very important in Fortran because it enable s Fortran programs to be
written in a way more harmonious with structured programming.
The simple IF ... THEN statement has the following form:
READ (*,*) X, Y
IF (X+Y . EQ. 0.0) THEN
WRITE(*,*) 'X = -Y'
STOP
ELSE
Z = (X+Y) + 2.0
PRINT *, X, YZ
END IF
In the above program, take note that the relational operator .EQ. is used
and not the equality (—) sign.
Give the IF statement version for the above program for checking the
following conditions:
i. X>Y
ii. X=Y
Answers
i. IF (X .GT. Y) THEN
or
IF (X-Y .GT. 0.0) THEN
ii. IF (X .LE. Y) THEN
or
IF (X-Y .LE. 0.0) THEN.
Before you round up this unit, see below the various forms of IF
statements:
• The logical IF
• The block IF
• The ELSE IF
Logical IF
IF (logical expression) statement
An example is as follows:
IF (J .GT. 4) GO TO 40
Block IF
IF (logical expression) THEN
ELSE IF
ELSE IF (logical expression) THEN.
4.0 CONCLUSION
5.0 SUMMARY
Fortran is very easy to learn as you have seen in this unit and the last
two units. This unit has extended the use of Fortran statements to the
basic features of structured programming available in the language.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Getting Started with Pascal Programming
3.2 Pascal Keywords and Operators
3.3 Pascal Standard Functions and Procedures
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
This unit will introduce you to the third language in this course,
namely, the PASCAL Language. In this unit, you will be discovering
for the first time what was never necessary in the first two languages
you have studied. Pascal has its own unique way of code development
as you will remember in Unit 3 of this course when studying some
basic elements of algorithms. You will remember that Pascal was said
to have its own specific form of pseudocode that you can easily
transform into Pascal code.
2.0 OBJECTIVES
Pascal allows variables of any length, although only the first six
characters have meaning to the computer and it is more English- like
than the Fortran language. Generally, Pascal has been observed to have
poor input and output (I/O) capabilities, however, it has very good
graphic capabilities unlike BASIC and Fortran.
Figure 1
• HEADING
• BODY.
Answer
ALGORITHM Circumference
DECLARE
Pi = 3.14159
radius, circum : REAL
EXECUTE
INPUT radius
Circum ? 2 * Pi * radius
Output 'circumference =', circum, MORE
END circumference.
Now, closely looking at the above program example, you will observe
that a Pascal program can be said to consist of the following sequences:
• Definitions
• Declarations
• Statements
• Optional Remarks.
When you divide a Pascal program into two major parts: Heading and
Body, the heading identifies the program name and it is better and
conventional to use an identifier that suggests what the program is
expected to do. The name of the program is followed by (INPUT,
OUTPUT) which indicates to the computer that the program will receive
data from its standard input device and also transmit data to its standard
output device. The words INPUT and OUTPUT are in this context
called the Program Parameters.
• CONST
• VAR.
The word symbol CONST indicates that the following data items will
define the CONSTANTS to be used by your program. The word symbol
VAR also indicates the beginning of the declarations of the names or
identifiers to be used for VARIABLE data.
The body of the program starts with the word symbol BEGIN and
terminates with the word END. Remember that the END statement is
followed by a full stop (.) as an essential part of the program code. END
statements in subprograms end with semicolons. From what you have
seen above, a Pascal program is punctuation — sensitive.
Before you are introduced to the Pascal keywords and operators, you
will observe in the above program example that the assignment operator
in Pascal is made up of a combination of two single symbols (:=).
• PROGRAM
• CONST
• VAR
• BEGIN
• REAL
• READ
• WRITE
• END
• INPUT
• OUTPUT.
Arithmetic Operators
+ : Addition
- - Subtraction
* - Multiplication
/ - Division
:= - Assignment
Relational Operators
Boolean Operators
• Arithmetic Functions
• Transfer Functions
• Boolean Functions
• Procedures.
Arithmetic Functions
SQR (X) : Square of X (i.e. X2)
SQRT (X) : Square Root of X (i.e. √X)
ABS (X) : Absolute Value of X (i.e. |X|)
EXP (X) : Exponential Function of X (eX)
LN (X) : Natural Logarithm of X (logeX)
SIN (X) : Sine of X
COS (X) : Cosine of X
ARCTAN (X) : Arctangent of X (tan-1(X))
Transfer
Boolean Functions
Answer
You will now round up this unit, having been introduced to the basic
knowledge of Pascal to get you started with the programming language.
4.0 CONCLUSION
In this unit, you have been introduced to the general features of the
Pascal language.
Something unique with PAS as you have seen in this unit is the peculiar
punctuation marks that are essential in its code unlike in BASIC and
Fortran that you have studied in this course.
The unit has also introduced you to the commonly used reserved words
and operators with the language library functions.
5.0 SUMMARY
In this unit, you have seen that as good as the Pascal language is, being
developed to be compatible with structured programming features, yet
the language has few demerits.
For example, there are no direct ways of expressing exponentiation and
tangent function as in other languages.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Iterative Structures in Pascal
3.2 IF — THEN Statements in Pascal 4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
• Sequence Structure
• Selection Structure
• Iterative Structure.
2.0 OBJECTIVES
Example 1
0 1.2400000000E+00
1 6.2000000000E+00
2 3.1000000000E+01
3 1.5500000000E+02
4 7.7500000000E+02
5 3.8750000000E+03
Example 2
From the program above, the WHILE statement will be repeated until
the value of 'number' becomes so small beyond what your computer can
recognize as zero.
Example 3
Answer
simply states that the value of "totalPrice" should be printed with length
38 and 2 decimal places. You will now be introduced to the next
structure to be treated in this unit.
As already learnt in the previous two languages you have studied, that
is, BASIC and Fortran, the IF-THEN statement is meant for performing
an alternation process on fulfillment of a condition.
The usage is seen in the following example before you round up this
unit.
Example 4
IF <expression> THEN
IF <expression> THEN <statement>
ELSE <statement>
ELSE <statement>.
In brief, the rule is that, an ELSE is paired with the nearest preceding
otherwise unpaired THEN.
In the above program, you will notice that if the input is a digit, your
output will be
"digiterror"
Answer
The first four statements after the BEGIN word symbol should be as
follows:
READ (ch);
IF (ch > = '0’) AND (ch < '9’) THEN
WRITE (digit);
ELSE IF (ch >= ‘A’) AND (ch <= ‘Z’) THEN.
The above program has introduced you also to the use of the Boolean
operators and of course a variable type CHAR.
With all that you have learnt in this unit and the last unit, you have
actually started with Pascal programming. These two units are just
intended to do that. A complete course on Pascal Programming will let
you dig deeper into the usage of the good features of Pascal
programming.
4.0 CONCLUSION
This unit has taken you through the features of structured programming
embedded in Pascal programming language. The iterative structure can
be carried out with either the FOR, WHILE or REPEAT statement as
you have seen in this unit.
The selection structure is implemented in Pascal the same way as in
other languages. The unit has shown you the careful manner the ELSE
statements should be paired with IF statements.
5.0 SUMMARY
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 An Overview of C++ Language 3.2 C++ Keywords and
Operators 4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
One of the attractive features of C++ is that the language offers good
facilities for Object-Oriented Programming (00P). In brief; the C++
language is a better C language since there are some facilities available
in C-H- which are not available in the original C. This unit will simply
give you an overview of the C++ language with its keywords and
operators. Now, look at your study objectives below.
2.0 OBJECTIVES
In this unit, you will be using the Turbo C-1-1- compiler to run the few
programs you will encounter in the study. The compiler offers you the
flexibility of compiling both your C and C++ programs. Just simply
remember to save your source program with extension C or CPP for the
original C or C++, respectively.
Now, you can only develop programs when you are familiar with
the grammar rules governing the language just as you have in other
languages. For now, C++ programs can be said to majorly consist of the
following:
• Comments
• Header Files
• Identifiers
• Statements
• Functions.
// <comments> ...
# include <header file>
.
.
.
# include <header file>
main (<parameters>)
{<identifiers and statements> ;
.
.
.
}
You will now see the explanation on the above general form as
follows:
Comments
Include Lines
The include lines are used to "include" the header files. The header
files, usually with extension .h, are files employed by C++ to declare
functions and to define macros. They serve in reducing the amount of
source code or program lines. Thus logically, an include line is used to
include the contents of a header file.
#include
The above files are STANDARD header files residing in the INCLUDE
subfolder of your main Turbo C++ directory. You can also write your
own header files.
Functions
Being a structured programming language, C++ program contains one
or more functions, one of which is called "main" as used in the above
general form.
main (<parameters>).
As seen in the general construction, you do not need the term "function"
to designate it. A function in C++ simply denotes a concrete program
segment. In C++, your functions may or may not have parameters. Thus
you can simply have something like this:
Main ( )
{
.
.
.
}
It should be noted that the body of every function in C++ is embedded
between braces { ...}. The two braces can be written on the same line or
in the same vertical column.
Statements
Before you are introduced to a simple C++ program, you need to know
of the C++ variable types.
Variable Types
Variables in C++ are of the following types with their fixed sizes in
memory:
Now, see your first C++ program below, being a program which reads
two real numbers from the keyboard to compute their average:
The above program uses the 'iostream.h' header file in its include line
because of the standard input and output streams 'cin' and 'cout used in
the program. In the original or traditional C language, you can use the
standard functions 'scanf" and 'printf" which are contained in the
`stdio.h' header file.
The statement:
cin >> x >>y;
reads two values from the standard input stream (i.e. from the keyboard)
and stores them into the variable x and y. The operator used here
appears like an arrow head which sends the values from 'cm' to x and y.
It is called a "Shift Operator".
uses the standard output stream 'cue which sends the characters between
the double quotes to the video screen.
As you can see in the above program, variables x and y are declared to
be floating numbers. The declaration of the variable 'mean' is done with
the assignment.
The use of "endl" in the program simply specifies that you are at the
end of the line. Instead of using "endl", you can also use
‘\n’ or “\n”.
Now, when the above program is compiled, your output will look like
this:
Enter Two Numbers: 2.4 4.6
Average = 3.5
Below are two window screens of Turbo C++ compiler. The "Message"
window is meant to display error messages or compilation messages.
The final output of your program can be viewed by selecting "Output"
from the "Window" menu as shown in the figure below:
Figure 1
Already, in the above example you considered in the last section, you
have seen some of the C++ keywords and operators.
Keywords
By keywords, the reserved words are also included in the list below:
C++ Operators
Generally, C++ has many operators and the language treats as operators
things that other programming languages do not. This is what makes
some people to see the C++ language as seemingly difficult. However,
the language is not as difficult from the little you have seen in this unit
already.
• Arithmetic Operators •
• Binary Operators.
• Additive Operators
• Multiplicative Operators
• Shift Operators
• Bitwise Operators
• Logical Operators
• Assignment Operators
• Relational Operators
• Equality Operators.
There are other operators too that may not be appropriate to classify
under the above groups. The language has many operators as you have
been told. It is an operator-driven and function-driven language.
Additive Operators
+ : Addition
- - Subtraction.
Multiplicative Operators
* : Multiplication
/ : Division
% : Remainder.
Shift Operators
<< : Shift Left
>> Shift Right
Bitwise Operators
Logical Operators
Assignment Operators
= : Assignment
*= : Assign Product
/= : Assign Quotient
% : Assign Remainder
+= : Assign Sum
-= : Assign Difference
<< : Assign Left Shift
>> : Assign Right Shift
&= : Assign Bitwise AND
∧= : Assign Bitwise XOR
|= : Assign Bitwise OR
Relational Operators
Less than
Greater than
Less than or equal to Greater than or Equal to
Equality Operators
== : Equal to
!= Not equal to
Printers in C++
Now, C++ uses the unary operator "" to designate a pointer variable.
Thus a declaration such as follows:
float *r;
it simply means "the contents of". From all the explanations above, if
you have for example:
Answer
The operator is the first of the two listed below. The second is its
inverse:
++ : Increment
-- : Decrement.
The output of the above program will give you the following:
Instead of using the "endl" keyword, the program uses "\n" alternative
to end the output line.
You will round up this unit now since all about C++ cannot be
exhaustively covered in this course. The course is meant to give you a
broad view of programming tools available in programming languages.
4.0 CONCLUSION
The unit has shown you the richness of C++ in terms of operators. The
same thing holds for usage of functions. A complete course on C++
language will help you to understand more of the language which has
been classified as a Middle-Level language because of its immense
capabilities, especially for developing operating systems.
5.0 SUMMARY
The header files used in the include lines can either be selected among
the standard files kept in the INCLUDE subfolder of your Turbo C++
Directory or be personally developed by you and kept in the INCLUDE
subdirectory or your current directory.
This unit will be the only unit devoted to C++ language just to give you
an introduction to the language. However, it should be noted that a good
knowledge of C++ will help you to easily and quickly understand the
JAVA language. The next unit will also take you further into another
language.
# include <iostream.h>
void f(int n)
{ if (n > 0)
{ f(n-2); cout << n <<"”; f(n-1);
}
{
main ( )
{ int k;
cout << "Enter k: "; cin >> k;
cout << "Output: \n";
a) How many functions are in the above program?
b) What is the function that calls itself in the program?
Ammeraal, L; C++ For Programmers, John Wiley & Sons Ltd., 1991
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Fundamentals of Web Pages 3.2 Text and Tags in HTML
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
The first concepts to fully understand in HTML are tags and text
formatting. This unit will get you started with the knowledge of these
fundamental aspects of HTML. Now, look at your study objectives for
this unit.
2.0 OBJECTIVES
By now, you are expected to have the basic idea of what is called the
INTERNET, which is the network of sub-networks of computers across
the world. Today, HTML pages are the standard interface to the
Internet. The inter-linked HTML pages were named the World Wide
Web (www) while the special programs written to view web pages are
called Web Browsers. Examples of Web Browsers are the Microsoft
Internet Explorer, Mozilla Firefox, Netscape Navigator, etc.
Basically, Hypertext means text stored in electronic form with cross-
reference links between pages. However, HTML or web pages today
may include the following:
• Text
• Sound
• Video
• Animated Graphics
• Interactive Programs.
The world wide web is the unique part of the Internet that relies on
HTML, but there are other services of the Internet and an example is
the E-mail service.
Apart from what are listed above that can be included on Web Pages,
you can also have the following as parts of the contents:
• Links
• Forms
• Frames
• Image Maps
• Java Applets
• Counters.
Text
Text is usually said to travel quickly over the Net (short for Internet).
Generally, you have lots of control over text, such as its font size,
colour, alignment and other properties.
Graphics
Generally, you should expect vie wing delays of web pages since most
of them are located on some other computers different from your own. If
web pages have many graphics, expect to spend some time waiting for
them to fully be downloaded on your computer. As a website developer
or programmer, learn how to include graphics that are worth seeing and
small for easy retrieval. Graphics can be animated on web pages.
Multimedia
With video and sound files included on web pages, you must have
suitable software to view or listen to them.
Links
No good web page without some vital links to direct visitors to other
pages. These links are generally called "hyperlinks".
Forms
To get feedback from web pages, the best way is to use forms. A form
consists of a set of slots into which website visitors can enter some
required information. However, your Internet Service Provider (ISP)
must rim software that can collect data submitted by your website
visitors and pass them to you.
Frames
Frames are used to divide your website into a set of separate areas, each
of which can display a different file and be changed independently.
They are employed to enhance the look and the usability of your website
or web pages (- a website is a collection of web pages).
Image Maps
Java Applets
Java applets are little programs you can embed into your web pages to
be downloaded or run within the browsers of the page visitors.
From the list above, you can see that web pages are simply "Assemblies
of Elements" and most of the elements are located in many different
computer files which may also be stored in different computers
anywhere in the world.
You will now see the use of tags and text formatting in HTML to create
web pages.
You have already seen in the list unit how web pages work, with an
example of a web page.
Just have a look at part of the HTML source code of a sample web page
(of the Course Developer):
Figure 2
As seen above, you can develop your HTML program code using any
ASCII editor such as the Microsoft Notepad. You only need to save the
document file with extension .html or .htm for the Web browser to
identify it.
Below are the HTML tags every HTML page or document must have:
• <HTML>
• <HEAD>
• <TITLE> ... </TITLE>
• </HEAD>
• <BODY>
…
• </BODY>
• <HTML>.
As you can see from the above list of common tags, they are classified
into:
• Opening Tag
• Closing Tag.
In the HTML code in the above figure, do you see the above tags? Yes,
however, you need to scroll down the document to see some of the
closing tags.
Having seen the tags every HTML document must have, below are a set
of tags that can be used to define headings for a range of sizes. The
heading tags generally start with <H... followed by a number between 1
and 6. You will demonstrate these as seen below:
HTML>
<H1> National Open University </H1>
<H2> School of Science and Technology </H2>
<H3> Department of Computer Science </H3>
<H4> Rivers State Study Centre </H4>
<H5> Dr. Sunday A. Reju </H5>
<H6> Visiting Lecturer </H6>
This is a Test Page
<HTML>
Type the above into an HTML document and open the file with a
browser.
Answer
Figure 3
In terms of sizes, the heading tags have the following points:
<H1> : 24 point
<H2> : 18 point
<H3> : 14 point
<H4> : 12 point
<H5> : 10 point
<H6> : 7 point
Note that the text "This is a Test Page", is a normal body text in the
above web page. Closely associated with the <H...> tags are the <FONT
SIZE = ...> tags which help you to have more control over the size of
heading text. Using the <FONT SIZE = ...> tag, there are six values the
size can take as stated below:
<HTML>
<TITLE> National Open University of Nigeria
</TITLE>
<FONT SIZE = 4> National <FONT SIZE = 7>
Open </FONT> University
</HTML>
Figure 4
You will see in the above figure that the text within the <TITLE> ...
<TITLE> tags is the title of the web page itself.
This unit will be rounded up now while you will be privileged to see
more tags in the next unit.
4.0 CONCLUSION
This unit has introduced you to the dynamics of web pages and how
they are created by using the HTML (i.e. HyperText Markup Language)
which was developed by the Physicist Tim Berners-Lee, as a way to
easily cross-reference text on the Internet through hypertext links
The unit has specifically shown you the roles of TAGS in HTML
document and a few tags that are used to format text on web pages.
5.0 SUMMARY
• Text
• Graphics
• Multimedia clips such as video and sound
• Links
• Forms
• Frames
• Image Maps
• Java Applets.
The use of tags in HTML document has been discussed in this unit with
the most common tags being identified.
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Additional Tags for Text Formatting
3.2 Links within HTML Document 4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
In the last unit, you were introduced to some essential tags used in
HTML document. More specifically, the tags every HTML document
must have were studied. However, there are more tags beyond those
already considered in the last unit. You will therefore be using
additional tags in this unit. The unit will also introduce you to special
tags that help you to move from one web page to another. Now, look at
your study objectives for this unit.
2.0 OBJECTIVES
<P>:
The tag for setting up a paragraph is the <P> tag. The tag marks the
beginning of a new paragraph and places a blank line before it. The
<P> tag can be placed at the end of a piece of text, at the start of the
next or in between.
<BR>:
The above is the line BREAK tag and marks the start of a new line.
<HR>:
The tag <HR> stands for Horizontal Rule and this is used to separate
paragraphs by drawing a line between them. The line is usually a thin
line with a shaded effect and extends through the width of the window.
Text Alignment
To align text, HTML uses the keyword ALIGN inside the <H...> or
<P> tag followed by "Center", "Left" or "Right". Body text and
headings are usually aligned left, hence the left alignment is optional.
The above tags are 'classified as PHYSICAL TAGS, meaning that they
only work if the web page visitor's browser can display bold, italic and
courier fonts. However, see the next tag.
<STRONG> ... </STRONG>: To set text to bold, like <B>
Text Colour
You can set the colour of the background and of the text by including
either or both phrases in the <BODY ... >tag as follows:
The colours are usually set by using what look like 6-digit hexadecimal
numbers. The numbers are meant to set set the brightness of the RED,
GREEN and BLUE components of a colour. Using a 24-bit colour
display, each of the numbers can be between '00' and 'FF'. However,
practically, the light values are taken as follows:
00 : for off
80 : for dipped colour
FF : for full beam colour.
Below is a table that summarises major colour values for the RGB
components
For example, look at the following HTML code line:
To set the colour for a section of text use the keyword "COLOR ="
inside a <FONT...> tag like the one below:
This is just used to make the colour values to be easily seen, but neither
# nor the quotes are necessary.
Answer
• hypertext
• graphics.
The word stands for Hypertext REFerence and it identifies the target
page or point within a page. But you cannot use HREF alone, you need
to ANCHOR it to a piece of text or a graphic so that there is a web page
element to click on to activate the link. The ANCHOR TAGS are:
The above link uses a file (NOU15.html) stored in the same directory
while the text 'NOUN Courses' is the text that will be underlined when
viewed in your browser and can be clicked to link you to the web page
(NOU15.html).
This link connects you to the Home Page of the Yahoo! Directory, while
'Yahoo!' will be the word underlined as the link. Your computer must
have an Internet connection to be able to connect to such a website page.
What about linking an image?
<IMG SRC> stands for "Image SouRCe" and the tag will place your
image against the left edge of your page, directly after any text, and with
later text starting to its right. To change the positioning of the image,
you need to use the tag with ALIGN. An example is as follows:
• TOP
• MIDDLE
• BOTTOM
The CENTER position can also be used for image positioning in the
following form:
<HTML>
<TITLE>
NOU Home Page
</TITLE>
<HI> National Open University </HI>
<HR>
<I> School of Science and Tech </I>
<A HREF = "Programs.htmln”> Programs </A>
<HTML>
Figure 1
When the mouse pointer is on the link, the target is shown on the status
bar at the bottom of the window as seen in the above figure.
4.0 CONCLUSION
This unit has shown you additional tags for formatting text and also for
linking web pages and images.
As seen in this unit, the web page background colour and the colour of
a text can also be set by using appropriate tags. To set colours, you need
to know the colour values for various combinations of RGB (RED,
GREEN and BLUE) components. With all that you have learnt in this
unit in addition to what was covered in the last unit, you can now get
started with programming with HTML.
5.0 SUMMARY
As seen in this unit, all you need to know in HTML is the appropriate
tags to be used for various types of displays expected on your browser.
This unit has extended the list of tags studied in the last unit.
Most importantly, the tags used for connecting web pages and files
have been introduced to you in the unit. There are some other tags used
in HTML which are not covered in these two units, but the first
reference under 'References/Further Readings' will help you to
understand more of the HTML tags.
Remember that your HTML code can be typed using any text editor,
but saved with .html extension. There are also special software
packages meant for website development such as the Microsoft Front
Page 2000. You should interact with it.
• Project
• Form
• Controls
• Properties
• Code.
Project
Form
A FORM is simply the window you create which includes the controls
and the code associated with that form.
Figure 3
Controls
Properties
The properties are the specifications of the initial values for your forms
and controls. They provide such characteristics as size, name and
position of your objects. The properties can be set by using the
Properties Windows.
Answer
The properties of the current form, i.e. Form 1.
Code
A code is just the name given to the programming statements you write
and associate with the controls on your form. You will see examples of
codes in the next unit.
Figure 4
Figure 5
The above figures show you a number of things you can do with your
applications you develop with VB. For example, you can compile your
VB program into an executable form as seen in the first screen above
under the File menu option: "Make Project 1.exe"
Remember, the names Project 1, Form 1 and Module 1 are all the
names VB gives to your programming items before you rename them,
using your own names.
The second figure above also shows you what you can do to your
Project components.
For example, you can add an MDI form to your project. There are
majorly two types of forms.
An SDI application is one that requires only a single data window while
an MDI application allows the opening of multiple data documents
within the same application. An example of SDI application is the
Windows Notepad while an example of MDI application is Microsoft
Word or Microsoft Excel.
The controls available on your Toolbox are what make things happen
on your forms. You will be using some of these controls in the next
unit. Before then, you need to know of an essential concept in Visual
Basic.
Events
4.0 CONCLUSION
This unit has given you a brief but essential overview of Visual Basic
language programming. In the unit, you have seen the basic things you
handle within VB programming environment. Such things are:
• Project
• Forms
• Controls
• Properties
• Code.
5.0 S UMMARY
As you have been taught in this unit, Visual Basic is a very easy
language to learn because it is based on the Beginners language, that is,
BASIC. Forms, which are major components of VB Project are where
things happen, being the platforms upon which users can interact with
the computer.
The next unit will show you how to design simple forms with
appropriate controls placed on them to perform one task or the other.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Writing Event-Driven Code
3.2 Adding Menus to Forms 4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
This unit will make use of the basic knowledge you have already got
from the previous unit to get you started with simple programming
using VB. The unit will specifically teach you how to create simple
forms and place some controls on them using the Toolbox.
2.0 OBJECTIVES
Figure 1
Figure 2
• Use "Save Project As" from the File menu to name your project
and the Form 1 file
• Use the Properties Window to rename the Caption as NOU
Example 1.
•
Doing this, you will have the following screen:
Figure 3
These controls are on the first row of the Toolbox. In fact you will see
then name of the control displayed by just pointing to the control. On
placing these controls, you have the following figure:
Figure 4
You will start with the first control, "Command 1" button. Rename the
caption from the Properties window. Remember that you have to select
the button first before the properties are displayed in the Properties
window.
Rename the caption as "EXIT" and then double-click the button to open
the code window as follows:
Figure 5
You are now about to write your first event-driven code. Visual Basic
has made your work easy by already giving you the Header and the
Terminator for your program segment:
From the Properties window, rename the Name property to "exit" and
type the VB command "Unload Me" as the event statement. The name
of the Event is "Click" and to select any other type of event, you can
click the downward arrow as seen below.
Figure 6
SELF ASSESSMENT EXERCISE 1
What do you think the above code will perform on clicking the button
EXIT?
Answer
Now, for the second control on your form, select the control, and from
the Properties Window, click the button in front of the "Picture"
property to select your picture to place on the Form. Locate your picture
from your directory where it is stored as indicated below:
Figure 9
Above is the output of your application. Clicking the EXIT button will
close the “NOU Example 1” window that you have created.
Since you only want to display the picture object, you may not need to
add any code to the control.
3.2 Adding Menus to Forms
To add menus to your form created in the last section, it is very easy.
In this case, you will need the “Menu Editor” which you can access
from the Tools menu or the toolbar as shown below:
Figure 10
Figure 11
Before you add your menus, it is good to state that Menus consist of the
following:
• Menu Title
• Menu Item
• Separator bar
Figure 12
Now, back to the Menu Editor, you have these three essential properties:
Figure 13
As seen in the above Menu Editor, the Menu captioned "NOU Admin"
is expected to have two menu items — "Coordinator" and "Schools".
You can use the Indent arrow to add the menu items. The character "R"
placed between the characters in the title is to specify what letter to use
with the ALT key to select the me nu. For example, by pressing ALT +
A, you can select the "NOU Admin" menu from the menu bar.
If you now select the Run command from your VB toolbar, you have
the following form:
Figure 14
To add code to the menu items, simply click the menu item on the form
to open the code window as follows:
Figure 15
You will now round up this unit having got the basic knowledge of
creating a simple application with Visual Basic.
4.0 CONCLUSION
This unit has taken you through the few basic steps you need to follow
to get started with writing event-driven programs when creating a VB
application. You have seen in the unit how it is easy to place controls
on your forms and how to hook up the controls -with code that is
expected to drive them.
You have been using menus in many applications you have interacted
with such as Microsoft Word. Now, you can create your own menus as
seen in this unit.
5.0 SUMMARY
The unit is not aimed at taking you through the many lists of VB
keywords or operators as in other languages. You are already
acquainted with some of them when you studied BASIC language. This
unit has simply taught you how to add code to your controls and menus.
You have seen how it is very easy to develop applications with VB.
You just need to get started with VB programming now while all other
helps you need to extend your knowledge can be obtained from the
"Books Online" (or MSDN CDs of your Visual Studio setup CDs)
which you can access from the Help menu of your fully installed Visual
Basic programming environment.
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Introduction to Special Programming Software
3.2 Using MathCad Programming Tools
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
2.0 OBJECTIVES
For example, from the above list, some of these packages have been
treated in a course on Software Application Skills in the School of
Science and Technology. They will therefore not be treated in this
course again. Specifically, Microsoft Access and SPSS have been
treated in that course. You may wish to refer to your course material if
you took or are taking the course. Microsoft Access for example is a
very good programming software for database problems and
interestingly enough, Visual Basic that you have just studied in the
previous two units have common programming tools with Microsoft
Access.
Figure 3 (Mathematica):
Exploring various menus for the above applications will show you some
of their programming capabilities. However, the best way of studying
the applications is to open their Help files using the Help menu.
You will now see in the next section some of the programming
capabilities of Mathcad.
The Mathcad version used in this course material is the Version 6.0 of
the application.
• Animation
• Data Analysis
• Plotting Graphics
• Solving Equations
• Statistical Analysis
• Programming
• Symbolic Calculations
• Vectors and Matrix Analysis
• Text Editing.
• etc.
Figure 4
• Arithmetic Palette
• Evaluation and Boolean Palette
• Graphing Palette
Vectors and Matrices Palette
• Calculus Palette
• Programming Palette
• Greek Letters Palette.
See the use of one of the tools on the Evaluation palette as follows:
To obtain the- above results, use the Vectors and Matrices Palette and
click the matrix button to define the rows and columns of the matrix.
MathCad will give you the matrix frame to enter entries. Then simply
type:
A ∧ -1
to obtain A-1. Press "=" key on the keyboard to get the inverse instantly.
From the immediate example, you will observe that MathCad uses the
following operators:
Figure 9:
Figure 10:
Figure 11:
Figure 13
Finally, see a very simple MathCad program to find the sum of the
first n integers:
Figure 15
4.0 CONCLUSION
This unit has shown you the use of some specialized programming
software to solve some classes of problems. The unit specifically
focused on MathCad which has a lot of tools to solve various groups of
mathematical problems.
The unit showed you some examples of problem solving using some
MathCad codes. As you have seen in some of the examples, MathCad
has its Am built- in functions. Below are some of them summarized,
for solving equations:
Figure 16
5.0 SUMMARY
• √(Square Root)
• Σ (Summation)
• # (Not Equal to)
• ∫ (Integral)
• State three (3) built- in functions available in MathCad.
• What is the extension for files created by MathCad.
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Introduction to MATLAB
3.2 Programming with MATLAB
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignments
7.0 References/Further Readings
1.0 INTRODUCTION
In this unit, which is the concluding unit for this course, you are going
to be introduced to one of the most powerful mathematical
applications available for Mathematics and Engineering problems
today. MATLAB is a very high performance language for technical
computing. It consists of essential features that will make you to
appreciate the power of computing.
This unit will therefore introduce you to the general knowledge of the
language application and some of its programming tools. Your study
objectives for this unit are as presented below.
2.0 OBJECTIVES
• Mathematical computations
• Modeling and Simulation
• Algorithm Development
• Data Analysis and Visualization
• Scientific and Engineering Graphics
• Application Development
• etc.
• Simulation
• Optimization
• Neural Networks
• Signal Processing
• Fuzzy Logic
• Control Systems
• Wavelets
• and others.
MATLAB Language
The language allows what have been classified into two as follows:
In the first figure, there are two essential buttons apart from the standard
buttons on the toolbar. They are for the following:
• Workspace Browser
• Path Browser.
For example, by clicking the Path Browser button, you have the
following window when maximized.
Figure 3
The Path Browser allows you to have access to some of the MATLAB
(M) Files. For example, by double-clicking the file "contents.m" in the
path
C:/Matlab \toolbox \matlab\polyfini"
you have the file opened as shown below in the MATLAB Editor.
Figure 4
You will now see below some specific examples of using the
MATLAB programming features.
You will now start to explore the capabilities of MATLAB within its
Command Window by typing each of the following expressions
followed by the ENTER key to see your results:
>> a = [3 2 6 9]
=
3269
>> A = [4 71; 5 9 0; 53 1]
A=
471
590
531
>>B =A'
B=
455
793
101
>> roots (a)
ans =
0.2485 + 1.5863i
0.2485 - 1.5863i
-1.1636
>>
From the above code window, you can see how a vector and a matrix
are typed within the MATLAB programming environment.
In the above working session, you have seen one of the functions
employed by MATLAB. The roots of a polynomial function are
obtained by using the built- in MATLAB function "roots".
a = [3 2 6 9]
You have used another MATLAB built- in function: plot (a) and the
result is the graph seen above.
From the roots of vector a, you can see that MATLAB also handles
complex computations.
MATLAB has a way of keeping track in memory of all that you have
typed at the command prompt and the answers to your computational
processing. You
You can recall all these from the memory by typing the
command;
"whos"
See this below:
Figure 6
Now, below is an example of MATLAB programming that produces a
3-dimensional graph. You can see below the graph the MATLAB
expressions that produce the graph. These expressions can also be
saved as an M-File script and run from the Editor environment.
Figure 7
Figure 8
Now, before you round up this unit, see below the list of some
commands used by MATLAB. The list is obtained by accessing some
of the M-Files in the toolboxes.
Answer