ELEMENTARY PROGRAMMING PRINCIPLES
Definition of terms
Elementary programming principles. A computer program is a set of coded instructions given to the computer, and represents a logical solution to a problem. It directs a computer in performing various operations/tasks on the data supplied to it.
Computer programs may be written by the hardware manufacturers, Software houses, or a programmer to solve user problems on the computer.
Programming is the process of designing a set of instructions (computer programs) which can be used to perform a particular task or solve a specific problem.
It involves use of special characters, signs and symbols found in a particular programming language to create computer instructions
The programming process is quite extensive. It includes analyzing of an application, designing of a solution, coding for the processor, testing to produce an operating program, and development of other procedures to make the system function.
The program created must specify in detail the logical steps to be taken & the method of processing the data input into the computer in order to carry out the specified task.
A computer program performs the following:
- Accepts data from outside the computer as its input.
- Carries out a set of processes on the data within the computer memory.
- Presents the results of this processing as its output, and
- Stores the data for future use.
A programming language is a set of symbols (a language) which a computer programmer uses to solve a given problem using a computer.
The computer must be able to translate these instructions into machine-readable form when arranged in a particular sequence or order.
TERMS USED IN COMPUTER PROGRAMMING
Source program (source code)
The term Source program refers to program statements that the programmer enters in the program editor window, and which have not yet been translated into machine-readable form.
Source code is the code understood by the programmer, and is usually written in high-level language or Assembly language.
Object code (object program).
The term Object code refers to the program code that is in machine-readable (binary) form.
This is the code/language the computer can understand, and is produced by a Compiler or Assembler after translating the Source program into a form that can be readily loaded into the computer.
A computer uses & stores information in binary form, and therefore, it cannot understand programs written in either high-level or low-level languages. This means that, any program code written in Assembly language or high-level language must be translated into Machine language, before the computer can recognize & run these programs.
A Translator is special system software used to convert the Source codes (program statements written in any of the computer programming languages) to their Object codes (computer language equivalents).
The Translators reside in the main memory of the computer, and use the program code of the high-level or Assembly language as input data, changes the codes, and gives the output program in machine-readable code.
In addition, translators check for & identify some types of errors (e.g., Syntax/grammatical errors) that may be present in the program being translated. They will produce error messages if there is a mistake in the code.
Each language needs its own translator. Generally, there are 3 types of language translators:
Note. Interpreters & Compilers translate source programs written in high-level languages to their machine language equivalents.
An assembler translates programs written in Assembly language into machine language that the computer can understand and execute.
Functions of an Assembler.
- It checks whether the instructions written are valid, and identifies any errors in the program.
The Assembler will display these errors as well as the complete source and object programs. If the program has no errors, the job control will let it run immediately, or save the object program so that it may run it later without translating it again.
- It assigns memory locations to the names the programmer uses.
E.g., the Assembler keeps a table of these names so that if an instruction refers to it, the Assembler can easily tell the location to which it was assigned.
- It generates the machine code equivalent of the Assembly instructions.
Usually, the Assembler generates a machine code only when no errors are detected. Some of the errors include;
- Typing mistakes.
- Using the wrong format for an instruction.
- Specifying a memory location outside the range 0 – 2047.
Note. The Assembler cannot detect Logic errors. The programmer knows of these errors only when the program is run & the results produced are incorrect (not what the programmer expected). The programmer must therefore, go through the program & try to discover why an incorrect result was being produced.
An interpreter translates a source program word by word or line by line. This allows the CPU to execute one line at a time.
The Interpreter takes one line of the source program, translates it into a machine instruction, and then it is immediately executed by the CPU. It then takes the next instruction, translates it into a machine instruction, and then the CPU executes it, and so on.
The translated line is not stored in the computer memory. Therefore, every time the program is needed for execution, it has to be translated.
A compiler translates the entire/whole source program into object code at once, and then executes it in machine language code. These machine code instructions can then be run on the computer to perform the particular task as specified in the high-level program.
The process of translating a program written in a high-level source language into machine language using a compiler is called Compilation.
For a given machine, each language requires its own Compiler. E.g., for a computer to be able translate a program written in FORTRAN into machine language; the program must pass through the FORTRAN compiler (which must ‘know’ FORTRAN as well as the Machine language of the computer).
The object code file can be made into a fully executable program by carrying out a Linking process, which joins the object code to all the other files that are needed for the execution of the program. After the linking process, an executable file with an .EXE extension is generated. This file is stored on a storage media.
Points to note.
- The job of a Compiler is much more difficult than that of an Assembler in that, a single statement in a high-level language is equivalent to many machine instructions.
- The format of an Assembly instruction is fairly fixed, while high-level languages give a lot of freedom in the way the programmer writes statements.
Functions of a compiler.
A Compiler performs the following tasks during the compilation process:
- It identifies the proper order of processing, so as to execute the process as fast as possible & minimize the storage space required in memory.
- It allocates space in memory for the storage locations defined in the program to be executed.
- It reads each line of the source program & converts it into machine language.
- It checks for Syntax errors in a program (i.e., statements which do not conform to the grammatical rules of the language). If there are no syntax errors, it generates machine code equivalent to the given program.
- It combines the program (machine) code generated with the appropriate subroutines from the library.
- It produces a listing of the program, indicating errors, if any.
Differences between Compilers and Interpreters
|1. Translates & executes each statement of the source code one at a time.
The source code instruction is translated & immediately obeyed by the computer hardware before the next instruction can be translated.
(Translation & execution go together).
2. Translates the program each time it is needed for execution; hence, it is slower than compiling.
3. Interpreted object codes take less memory compared to compiled programs.
4. For an Interpreter, the syntax (grammatical) errors are reported & corrected before the execution can continue.
5. An Interpreter can relate error messages to the source program, which is always available to the Interpreter. This makes debugging of a program easier when using an Interpreter than a Compiler.
|1. Translates all the source code statements at once as a unit into their corresponding object codes, before the computer can execute them.
A Compiler translates the entire source program first to machine code, and then the code is executed by the CPU.
(Translation & execution are separate phases)
2. Compiled programs (object codes) can be saved on a storage media and run when required; hence executes faster than interpreted programs.
3. Compiled programs require more memory as their object files are larger.
4. For a Compiler, the syntax errors are reported & corrected after the source code has been translated to its object code equivalent.
5. Once the source program has been translated, it is no longer available to the Compiler, so the error messages are usually less meaningful.
Linkers & Loaders
Computer programs are usually developed in Modules or Subroutines (i.e., program segments meant to carry out the specific relevant tasks). During program translation, these modules are translated separately into their object (machine) code equivalents.
The Linker is a utility software that accepts the separately translated program modules as its input, and logically combines them into one logical module, known as the Load Module that has got all the required bits and pieces for the translated program to be obeyed by the computer hardware.
The Loader is a utility program that transfers the load module (i.e. the linker output) into the computer memory, ready for it to be executed by the computer hardware.
Each programming language has a special sequence or order of writing characters.
The term Syntax refers to the grammatical rules, which govern how words, symbols, expressions and statements may be formed & combined.
These are rules, which govern the meaning of syntax. They dictate what happens (takes place) when a program is run or executed.
- Define the following terms:
- Computer program.
- Programming language.
- With reference to programming, distinguish between Source program and Object code.
- What is the function(s) of: Assemblers, Interpreters and Compilers in a computer system?
- (a). What are the main functions of a Compiler?
(b). Differentiate between a Compiler and an Interpreter.
LEVELS OF PROGRAMMING LANGUAGES
There are many programming languages. The languages are classified into 2 major categories:
- Low-level programming languages.
- High-level programming languages.
Each programming language has its own grammatical (syntax) rules, which must be obeyed in order to write valid programs, just as a natural language has its own rules for forming sentences.
These are the basic programming languages, which can easily be understood by the computer directly, or which require little effort to be translated into computer understandable form.
- Machine languages.
- Assembly languages.
Features of low-level languages
- They are machine hardware-oriented.
- They are not portable, i.e., a program written for one computer cannot be installed and used on another computer of a different family.
- They use Mnemonic codes.
- They frequently use symbolic addresses.
Machine languages (1st Generation languages)
Machine language is written using machine codes (binary digits) that consist of 0’s & 1’s.
The computer can readily understand Machine code (language) instructions without any translation.
A programmer is required to write his program in strings of 0’s & 1’s, calculate & allocate the core memory locations for his data and/or instructions.
Different CPU’s have different machine codes, e.g., codes written for the Intel Pentium processors may differ from those written for Motorola or Cyrix processors. Therefore, before interpreting the meaning of a particular code, a programmer must know for which CPU the program was written.
A machine code instruction is made up of 2 main parts;
- An Address (operand):
It specifies the location (address) of the computer memory where the data to be worked upon can be found.
- A Function (operation) code:
It states to the Control Unit of the CPU what operation should be performed on the data/item held in the address, e.g., Addition, Subtraction, Division, Multiplication, etc.
Note. The computer can only execute instructions which are written in machine language. This is because; it is the only language which the computer can understand. Therefore, any program written in any other programming language must first be translated into machine language (binary digits) before the computer can understand.
Assembly language (2nd Generation Languages).
Assembly languages were developed in order to speed up programming (i.e., to overcome the difficulties of understanding and using machine languages).
The vocabulary of Assembly languages is close to that of machine language, and their instructions are symbolic representations of the machine language instructions.
- Assembly language programs are easier to understand, use & modify compared to Machine language programs.
- Assembly language programs have less error chances.
To write program statements in Assembly language, the programmer uses a set of symbolic operation codes called Mnemonic codes.
The code could be a 2 or 3 shortened letter word that will cause the computer to perform specific operation. E.g., MOV – move, ADD – addition, SUB – subtraction, RD – read.
RD PAT, 15 (read the value 15 stored in the processor register named PAT)
SUB PAT, 10 (subtract 10 from the value in register PAT)
A program written in an Assembly language cannot be executed/obeyed by the computer hardware directly. To enable the CPU understand Assembly language instructions, an Assembler (which is stored in a ROM) is used to convert them into Machine language.
The Assembler accepts the source codes written in an Assembly language as its input, and translates them into their corresponding computer language (machine code/ object code) equivalent.
Comments are incorporated into the program statements to make them easier to be understood by the human programmers.
Assembly languages are machine-dependent. Therefore, a program written in the Assembly language for a particular computer cannot run on another make of computer.
Advantages of Low-level languages
- The CPU can easily understand machine language without translation.
- The program instructions can be executed by the hardware (processor) much faster. This is because; complex instructions are already broken down into smaller simpler ones.
- Low-level languages have a closer control over the hardware, are highly efficient & allow direct control of each operation.
They are therefore suitable for writing Operating system software & Game programs, which require fast & efficient use of the CPU time.
- They require less memory space.
- Low-level languages are stable, i.e., they do not crash once written.
Disadvantages of Low-level languages
Very few computer programs are actually written in machine or Assembly language because of the following reasons;
- Low-level languages are difficult to learn, understand, and write programs in them.
- Low-level language programs are difficult to debug (remove errors from).
- Low-level languages have a collection of very detailed & complex instructions that control the internal circuiting of the computer. Therefore, it requires one to understand how the computer codes internally.
- Relating the program & the problem structures is difficult, and therefore cumbersome to work with.
- The programs are very long; hence, writing a program in a low-level language is usually tedious & time consuming.
- The programs are difficult to develop, maintain, and are also prone to errors (i.e., it requires highly trained experts to develop and maintain the programs).
- Low level languages are machine-dependent (specific), hence non-portable.
This implies that, they are designed for a specific machine & specific processor, and therefore, cannot be transferred between machines with different hardware or software specifications.
- It is not easy to revise the program, because this will mean re-writing the program again.
HIGH-LEVEL PROGRAMMING LANGUAGES
High-level languages were developed to solve (overcome) the problems encountered in low-level programming languages.
The grammar of High-level languages is very close to the vocabulary of the natural languages used by human beings. Hence; they can be read and understood easily even by people who are not experts in programming.
Most high-level languages are general-purpose & problem-oriented. They allow the programmer to concentrate on the functional details of a program rather than the details of the hardware on which the program will run.
High-level language programs are machine-independent, (i.e., they do not depend on a particular machine, and are able to run in any family of computers provided the relevant translator software is installed).
Programs written in a high-level language cannot be obeyed by the computer hardware directly. Therefore, the source codes must be translated into their corresponding machine language equivalent. The translation process is carried out by a high-level language software translator such as a Compiler or an Interpreter.
Features of high-level programming languages.
- They contain statements that have an extensive vocabulary of words, symbols, sentences & mathematical expressions, which are very similar to the normal English language.
IF TaxablePay<1000 THEN
Tax: =TaxRate * TaxablePay;
Write (Tax: 6:2);
- Allow modularization (sub-routines).
- They are ‘user-friendly’ and problem-oriented rather than machine-based. This implies that, during a programming session, the programmer concentrates on problem-solving rather than how a machine operates.
- They require one to be obey a set of rules when writing the program.
- Programs written in high-level languages are shorter than their low-level language equivalents, since one statement translates into several machine code instructions.
- The programs are portable between different computers.
Purpose of High-level languages.
- To improve the productivity of a programmer. This is because; the source programs of high-level languages are shorter than the source programs of low-level languages, since one statement translates into several machine code instructions.
- To ease the training of new programmers, since there is no need to learn the detailed layout of a procession/sequence.
- To speed up testing & error correction.
- To make programs easy to understand & follow.
Advantages of High-level languages.
- They are easily portable, i.e., they can be transferred between computers of different families and run with little or no modification.
- High-level language programs are short, and take shorter time to be translated.
- They are easy to lean, understand and use.
- They are easy to debug (correct/remove errors), & maintain.
- High level language programs are easy to modify, and also to incorporate additional features thus enhancing its functional capabilities.
- They are ‘user-friendly’ & problem-oriented; hence, can be used to solve problems arising from the real world.
- They enable programmers to adapt easily to new hardware. This is because; they don’t have to worry about the hardware design of the computer.
- High-level language programs are self-documenting, i.e., the program statements displays the transparency of purpose making the verification of the program easy.
- High level languages are more flexible; hence, they enhance the creativity of the programmer and increase his/her productivity in the workplace.
Disadvantages of using High-level languages
- High-level languages are not machine-oriented; hence, they do not use of the CPU and hardware facilities efficiently.
- The languages are machine-independent, and cannot be used in programming the hardware directly.
- Each high-level language statement converts into several machine code instructions. This means that, they use more storage space, and it also takes more time to run the program.
- Their program statements are too general; hence, they execute slowly than their machine code program equivalents.
- They have to be interpreted or compiled to machine-readable form before the computer can execute them.
- The languages cannot be used on very small computers.
The source program written in a high-level language needs a Compiler, which is loaded into the main memory of the computer, and thus occupies much of memory space. This greatly reduces the memory available for a source program.
TYPES OF HIGH-LEVEL LANGUAGES.
High-level languages are classified into five different groups:
- Third generation languages (Structured / Procedural languages).
- Fourth generation languages (4GLs).
- Fifth generation languages (5GLs)
- Object-oriented programming languages (OOPs).
- Web scripting languages.
The various types of high-level languages differ in:
- The data structures they handle.
- The control structures they support.
- The assignment instructions they use.
- Application areas, e.g., educational, business, scientific, etc.
A structured (procedural) language allows a large program to be broken into smaller sub-programs called modules, each performing a particular (single) task. This technique of program design is referred to as structured programming.
Structured programming also makes use of a few simple control structures in problem solving. The 3 basic control structures are:
- Iteration (looping).
Advantages of structured programming.
- It is flexible.
- Structured programs are easier to read.
- Programs are easy to modify because; a programmer can change the details of a section without affecting the rest of the program.
- It is easier to document specific tasks.
- Use of modules that contain standard procedures throughout the program saves development time.
- Modules can be named in such a way that, they are consistent and easy to find in documentation.
- Debugging is easier because; each module can be designed, coded & tested independently.
Examples of Third generation programming languages include:
- BASIC (Beginners All-purpose Symbolic Instructional Code).
BASIC is a simple general-purpose high-level language used in most computer processing tasks such as developing business and educational applications.
It is easy to learn & use; hence, suitable for students who wish to easily learn programming.
Translation in most versions of BASIC is carried out by an Interpreter.
Disadvantages of BASIC.
- BASIC is available in so many versions with different dialects/languages & therefore, it has no standard.
- Some dialects are limited to data & control structures they support.
- Some versions of BASIC offer limited facilities in terms of structured programming & meaningful variable names.
PASCAL is a general-purpose, high-level programming language, which was named after a French mathematician called Blaise Pascal.
It was developed as an academic tool to help in the teaching and learning of structured programming.
PASCAL supports structured programming, i.e., it uses procedures & functions, which allow a ‘top-down’ approach to solving problems.
- It is not easy to learn because; it has strict rules in its grammar on typing of variables (data names) & declarations.
- It is poor (has limited ability) on handling of data files.
COBOL (COmmon Business Oriented Language)
COBOL is designed for developing programs that solve business problems, e.g., can be used to develop commercial data processing applications such as computer-based inventory control systems.
COBOL is mostly used where large amounts of data are to be handled, because it supports powerful data & control structures.
COBOL programs are semi-compiled, and the intermediate code is interpreted.
A program written in COBOL language consists of 4 divisions: –
- Identification division: Where the programmer & the program details are specified, e.g., program ID, programmer name, etc.
- Environment division: Where the equipments to be used by the source & the object programs are defined, e.g., the computer hardware.
- Data division: Where the various files to be used by the program are described, e.g., a description of the input files.
- Procedure division: Where all the procedures required to manipulate/interrelate the data into information are defined.
Advantages of COBOL.
- It is easy to read.
- It is portable, i.e., can be used on different types of computers. This is because; it has an American National Institute
American National Standards Institute (ANSI): – An international organization that devised/ invented the group of standardized symbols used in flowcharting.
- It is widely used, and has a pool of skilled programmers.
Disadvantage of COBOL.
- The structure of a COBOL program is too long even for simple programs.
E.g., consider the following assignment statement:
DIVIDE A into B giving C.
This statement when used in BASIC language can much short ‘C=A/B’. However, notice that the COBOL statement above is more self defining.
- FORTRAN (FORmula TRANslator)
It was developed for mathematicians, scientists and engineers. It provides an easier way of writing scientific & engineering applications.
FORTRAN statements are mostly in form of mathematical expressions; hence, it is useful in writing of programs that can process numeric data.
FORTRAN programs are compiled.
Advantages of FORTRAN.
- It is portable, i.e. it can be used on different types of computers.
Disadvantage of FORTRAN.
- It is not suited for business applications.
This language was named after the first lady programmer Ada Lovelace.
It is suitable for developing military, industrial and real-time systems.
C is mainly used for developing system software such as the operating system as well as developing the application packages.
It has powerful commands that permit the rapid development of programs, and allows direct control over the hardware.
Disadvantage of C
It is difficult to read & learn because of its strict dialect rules.
LOGO was designed for educational use in which children can explore & develop concepts through programming the movement of a pen.
COROL is used in Real-time processing.
COROL programs are compiled.
- RPG (Report Program Generator)
RPG is used in report generating applications, (i.e. it is designed to facilitate the output of reports of business data).
A Report generator is a software tool that extracts stored data to create customized reports that are not normally/usually produced by existing applications.
- SNOBOL (String Oriented Symbolic Language).
It is a high-level language designed to manipulate strings of characters. It is therefore used for non-numeric applications.
FOURTH GENERATION LANGUAGES (4GL’S).
4GLs make programming even easier than the 3GLs because; they present the programmer with more programming tools, such as command buttons, forms, textboxes etc. The programmer simply selects graphical objects called controls on the screen, and then uses them to create designs on a form by dragging a mouse pointer.
The languages also use application generators (which in the background) to generate the necessary program codes; hence, the programmer is freed from the tedious work of writing the code.
4GLs are used to enquire & access the data stored in database systems; hence, they are described as the Query languages.
Purpose of fourth generation languages.
The 4GL’s were designed to meet the following objectives: –
- To speed up the application-building process, thereby increasing the productivity of a programmer.
- To enable quick & easy amendments and alteration of programs.
- To reduce development & maintenance costs.
- To make languages user-friendly. This is because, the 4GL’s are designed to be user-oriented, unlike the 3rd generation languages which are problem & programmer oriented.
- To allow non-professional end-users to develop their own solutions.
- To generate bug-free codes from high-level expressions of requirements.
Examples of 4GLs are:
- Visual Basic
- Delphi Pascal
- Visual COBOL (Object COBOL)
- Access Basic
Advantages of fourth generation languages.
- They are user-based, and therefore, easy to learn & understand.
- The grammar of 4GL’s is very close to the natural English language. It uses menus & prompts to guide a non-specialist to retrieve data with ease.
- Very little training is required in order to develop & use 4GL programs.
- They provide features for formatting of input, processing, & instant reporting.
FIFTH GENERATION LANGUAGES (5GL’S).
The 5GL’s are designed to make a computer solve a problem by portraying human-like intelligence.
The languages are able to make a computer solve a problem for the programmer; hence, he/she does not spend a lot of time in coming up with the solution. The programmer only thinks about what problem needs to be solved and what conditions need to be met without worrying about how to implement an algorithm to solve the problem.
5GLs are mostly used in artificial intelligence.
Examples of 5GLs are:
- LISP (LISt Processing)
In LISP, both programs & data are arranged (structured) as lists.
It is used in artificial intelligence. However, it is not suitable for commercial data processing applications.
- PROLOG (PROgramming in LOGic)
PROLOG was developed from LISP by the Japanese.
It is designed for use with Expert systems & Artificial Intelligence. It is mostly used for solving problems, which involve objects and relationships between objects.
Like LISP, it is not suitable for commercial data processing applications.
OBJECT-ORIENTED PROGRAMMING LANGUAGES (OOPs)
Object-Oriented Programming is a new approach to software development in which data & procedures that operate on data are combined into one object.
OOPs use objects. An Object is a representation of a software entity such as a user-defined window or variable. Each object has specific data values that are unique to it (called state) and a set of the things it can accomplish called (functions or behaviour).
Several objects can be linked together to form a complete program. Programs send messages to an object to perform a procedure that is already embedded in it. This process of having data and functions that operate on the data within an object is called encapsulation.
The data structure & behaviour of an object is specified/described by a template (called a class). Classes are hierarchical, and it is possible to pass the data & behaviour of an object in one class down the hierarchy.
Object-Oriented programming enables rapid program development. Every object has properties such as colour, size, data source, etc, which can be set easily without much effort. In addition, every object has events associated with it that can be used to trigger certain actions, e.g. remove the window from the screen on clicking the ‘Close’ button.
OOP has contributed greatly to the development of graphical user interface operating systems and application programs.
Examples of Object-oriented programming languages are: –
Java is sometimes associated with development of websites, but it can be used to create whole application programs that do not need a web browser to run.
Java is an OOP language that resembles Object C (a simplified form of C++).
The code of Java displays graphics, accesses the network, and interfaces with users via a set of capabilities known as classes. Classes define similar states & common methods for the behavior of an object.
JAVA programs are not compiled into machine code; instead, they are converted into a collection of bytes that represent the code for an abstract Java Virtual machine (VM). A Java interpreter running on a physical machine is then used to translate those bytes into local actions, such as printing a string or drawing a button.
WEB SCRIPTING LANGUAGES.
Web scripting languages are mostly used to create or add functionalities on web pages.
Web pages are used for creating Web sites on the Internet where all sorts of advertising can be done.
Web pages are hypertext (plain-text) documents written using a language called HyperText Markup Language (HTML). HTML documents have a file extension of .Html or .Htm.
Comparison of Programming languages.
|Machine language||Assembly language||High-level languages|
|1. Instruction set is made up of binary digits (0’s & 1’s).
2. Instruction is made of 2 parts: operation code & operand.
3. No translation is needed. (This is the computer language; hence, the computer understands it directly).
4. Executed by the hardware directly & is faster.
5. Difficult to learn, develop & maintain.
6. Programs are lengthy & tedious.
7. It is time-consuming to develop machine code programs.
8. Used in applications where efficient use of the CPU time is necessary, e.g., developing Operating systems & other Control programs that coordinate the working of peripherals.
|1. Instruction set is made up of Mnemonics & labels.
2. Instruction is made up of 2 parts: operation code & operand, but comments can be added.
3. Uses an Assembler to convert the assembly language source codes to their object code equivalents
4. Executed faster than High-level, but slower than the machine code programs.
5. It’s easier to learn, develop & maintain as compared to machine code programs.
6. Like machine code language, the programs are lengthy & tedious.
7. They take a shorter time to develop as compared to machine code programs, but take longer than High-level language programs.
8. Like machine language, Assembly language programs are used in applications where efficient use of the CPU time is necessary.
|1. Instruction set is similar to English language statements & mathematical operators.
2. The instruction varies depending on the particular language.
3. Uses compiler or interpreter
Compiler translates all the source code at once into object code; Interpreter translates line by line.
4. Translation & execution is very slow.
5. Easy to learn, develop, maintain and use.
6. Programs are shorter & simpler than Machine & assembly lang. programs.
7. Developing High-level language programs takes very short time.
8. Most High-level languages are general-purpose, & can be used to do almost all computer-processing tasks.
Factors to consider when choosing a Programming language.
The following factors should be considered when choosing a Programming language to use in solving a problem:
- The availability of the relevant translator
- Whether the programmer is familiar with the language
- Ease of learning and use
- Purpose of the program, i.e., application areas such as education, business, scientific, etc.
- Execution time
Applications that require quick response are best programmed in machine code or assembly language. High-level languages are not suitable for such application because, they take long to be translated & executed.
- Development time
Development time is the time a programmer takes to write and run a program.
High-level languages are easy to read, understand and develop; hence, they require less development time. Machine code & Assembly languages are relatively difficult to read, understand and develop; hence, they are time-consuming.
The language selected should be suitable and/or successful in the market with respect to the problems to be solved.
It should have accompanying documentation (descriptions) on how to use the language or maintain the programs written in the language.
Programs are developed to solve specific problems, and the problems keep on changing; hence, the programs are also changed to perform the new functions.
Program maintenance is the activity of incorporating more routines onto the program, modifying the existing routines or removing the obsolete routines to make the program adapt to a functionally enhanced environment.
The maintenance is made easier if the language used is easy to read and understand.
- Availability of skilled programmers
The language selected should have a pool of readily available programmers to ease the programming activity, and reduce development time.
- (a). What is a Programming language?
(b). Explain the two levels of programming languages.
- (a). What is meant by ‘Machine language’?
(b). Explain why machine language programming is so error-prone.
(c). Show the difference between Machine language and Assembly language.
(d). Give two advantages & three disadvantages of Machine language programming.
- (a). What are High-level languages?
(b). Give the features/characteristics of high-level programming languages.
(c). Describe briefly how a program written in high-level programming language becomes a machine code program ready for operational use.
(d). Explain the advantages and disadvantages of using a High-level programming language for writing a program.
(e). List four examples of high-level programming languages. Indicate the application of each language in computing.
- (a). What is meant by program portability?
(b). Why are low-level languages not considered to be portable?
- List 8 factors that need to be considered when selecting a programming language.
Stages involved in the program development cycle.
The process of program development can be broken down into the following stages:
- Problem recognition (Identification of the problem).
- Problem definition.
- Program design.
- Program coding.
- Program testing & debugging.
- Program Implementation and maintenance.
- Program documentation.
Problem recognition refers to the understanding and interpretation of a particular problem.
The programmer must know what problem he/she is trying to solve. He/she must also understand clearly the nature of the problem & the function of the program.
In order to understand a problem, look for the keywords such as compute, evaluate, compare, etc.
Usually, a programmer identifies problems in the environment and tries to solve them by writing a computer program.
There are 3 situations that cause the programmer to identify a problem that is worth solving:
- Problems or undesirable situations that prevent an individual or organizations from achieving their purpose.
- Opportunity to improve the current program.
- A new directive given by the management requiring a change in the current system.
Sample problem: Develop a program that can be used to calculate/find the area of a circle. Use the equation A = π * r2.
Problem definition (Problem Analysis).
In Problem definition, the programmer tries to define (determine) the:
- Output expected from the program.
- Inputs needed to generate the output information.
- Processing activities (requirements), and
- Kind of files which may be needed.
- The programmer should write a narrative on what the program will do, and how it is meant to achieve the intended purpose. Within this narrative, he/she is required to determine what data is to be input & what information is to be output.
In calculating the area of any circle, the parameters needed to determine the area of any circle are:
- Input: (a) Pie (π) which is a constant.
(b) The radius of the circle.
- Process: The formula for calculating area of a circle, which is π * radius * radius.
- Output: The area of the circle (A).
At the end of the problem definition, the programmer is required to write a requirements report/document for the new program. This document will enable the programmer to come up with a program design that meets the needs at hand.
Note. Problem definition should be done thoroughly to ensure user satisfaction, and to facilitate the subsequent stages in the program development cycle. A failure at this stage usually results in a system that will not work as intended, or that may not work at all.
Program design is the actual development of the program’s process or problem solving logic called the Algorithm.
It involves identifying the processing tasks required to be carried out in order to solve the problem.
The design stage enables the programmer to come up with a model of the expected program (or a general framework (outline) of how to solve the problem, and where possible, break it into a sequence of small & simple steps.
The models show the flow of events throughout the entire program from the time data is input to the time the program gives out the expected information.
- The processing tasks must be in order & systematic. Therefore, the programmer identifies the processing tasks required, and the exact order in which they are to be carried out.
- The design process does not take account of the programming language to be used in the final product, since it only defines program logic.
- Program design provides for easy maintenance.
Note. It is important to design programs before entering them into the computer. The programmer should only attempt to covert a design into a program code after ensuring that it is logically correct. If possible, check the logical order on the desk.
Some programmers produce rough & ready solutions at a Keyboard, and continue to amend the programs until eventually the program appears to do what was expected. This is not recommended in programming because of the following reasons:
- The final code may not be easy to follow, since it was just cobbled together.
- Variable names & specific items of code may not be documented.
- Programs produced by continuous amendments & changing of codes mostly lead to unforeseen side effects.
E.g., there may not have been plan for testing the program or procedures, hence, the program may easily fail.
- A programmer may be asked to modify the code at a later date. Without sufficient documentation, the programmer will be forced to trace through the program in order to gain an insight into how the program functions.
Many programs are non-monolithic (i.e., they are not usually made up of one large block of code). Instead, they are made up of several units called modules, that work together to form the whole program with each module performing a specific task.
This approach makes a program flexible, easier to read, and carry out error correction.
Program coding is the actual process of converting a design model into its equivalent program.
Coding requires the programmer to convert the design specification (algorithm) into actual computer instructions using a particular programming language.
The programmer may be required to write the program code either in Pascal, C++, Visual Basic or Java, and develop (invent) suitable identifiers, variable names, & their data types. However, remember that, at this stage the coding is still a Pencil & paper exercise.
The end result of this stage is a source program that can be translated into machine readable form for the computer to execute and solve the target problem.
Rules followed in coding a program.
- Use the standard identifiers or reserved words.
- Make the program more readable by using meaningful identifiers.
- Don’t use similar variables.
- Keep spellings as normal as possible.
- Use comments to explain variables & procedures. This makes the program readable.
- Avoid tricks – write the program using straightforward codes that people can readily understand.
- Modularize your program.
Sample programs written in Pascal language.
Develop a program code that would be used to solve the equation of a straight line given by the expression: Y = mx + c
Program StraighLine (input, output);
y, m, x, c: INTEGER;
Writeln (‘Input the value of M’);
Writeln (‘Input the value of X’);
Writeln (‘Input the value of C’);
Y: = (m * x) +c;
Writeln (‘The value of y is:’, Y);
|Program StraightLine (input, output);||This is the program Header.
The word “Program” indicates the beginning of the program whose name is StraightLine.
The (input, output) statements shows that the program expects some input from the Keyboard and display the output on the Screen.
|VAR||VAR is short form for Variable. A variable is a location for data in the computer memory.
This statement tells the computer that variables are about to be declared. When a variable is declared, the computer sets aside some memory space to store a value in the variable.
|y, m, x, c: INTEGER;||Four variables of type Integer have been declared. This means that, the memory spaces that will be set aside can only hold values that are whole numbers.|
|BEGIN||The Begin statement marks the start of the program body. Statements in this section are executed by the computer. E.g., execution starts by asking the user to input the value of m.|
|Writeln (‘Input the value of M’);||The Writeln statement displays whatever is between the inverted commas in the brackets. The statements will be sent to the screen exactly the way they appear in the brackets. This is because; the inverted commas are meant to make the output readable on the screen.
To display the value held in a variable on the screen, remove the inverted commas and write the name of the variable in the brackets, e.g., Writeln (y) will display the value held in the variable y.
|Readln (M);||The Read or Readln statement reads a value and stores it in a variable.
When the program is running, a Read/Readln statement in the code will displays blinking cursor that indicates to the user where to type the input.
|Y: = (m * x) +c;||Calculates the value of y. in Pascal, the symbol ‘: =’ is called the Assignment statement.
The values on the right are calculated then the answer stored in the variable y which is on the left of the assignment symbol.
|Writeln (‘The value of y is:’, Y);||The Writeln displays the value held in the variable y on the screen.
Note. Y is not within the inverted commas.
|END.||The ‘END.’ statement shows the end of a program.|
Program AreaCircle (input, output);
Pi = 3.142;
Radius, Area: REAL;
Writeln (‘Enter the radius’);
Area: = Pi * Radius * Radius;
Writeln (‘The Area is’, Area);
|Program AreaCircle (input, output);||The Header of the program.
The statements in ( ) shows that the user inputs data via Keyboard and the program display information on the Screen.
Pi = 3.142;
|A constant has been declared with a name Pi and value 3.142.|
Radius, Area: REAL;
|Variables with fractional parts have been declared.|
|BEGIN||Marks the beginning of the program body.|
|Writeln (‘Enter the radius’);||Displays on the screen the string between the inverted commas.|
|Readln (Radius);||Displays a blinking cursor that tells the user that an input is needed before the program can continue.|
|Area: = Pi * Radius * Radius;||Calculates the Area. An assignment statement (: =) has been used.|
|Writeln (‘The Area is’, Area);||Displays the value stored in the variable Area.|
|END.||Marks the end of the program.|
- State the rules followed in coding a program.
Program Testing and Debugging
After designing & coding, the program has to be tested to verify that it is correct, and any errors detected removed (debugged).
Testing is the process of running computer software to detect/find any errors (or bugs) in the program that might have gone unnoticed.
During program testing, the following details should be checked;
- The reports generated by the system.
- The files maintained in connection to the system’s information requirements.
- The input to the system.
- The processing tasks.
- The controls incorporated within the system.
Note. The testing process is a continuous process, and it ends only when the Programmer & the other personnel involved are satisfied that when operational, the program will meet the objectives and the growing demands of the organization.
Types of program errors
There are 5 main types of errors that can be encountered when testing a program. These are:
- Syntax errors.
- Run-time (Execution) errors.
- Logical (arithmetic) errors.
- Semantic errors.
- Lexicon errors.
Every programming language has a well-defined set of rules concerning formal spellings, punctuations, naming of variables, etc. The instructions are accepted only in a specified form & and must be obeyed by the programmer.
Syntax errors are therefore, programming errors/mistakes that occur if the grammatical rules of a particular language are not used correctly.
- Punctuation mistakes, i.e., if the programmer does not use the right punctuations & spaces needed by the translator program, e.g., omitting a comma or a semicolon.
- Improper naming of variables.
- Wrong spellings of user defined and reserved words.
Reserved words are those words that have a special meaning to the programming language, and should not be used by the programmer for anything else.
Syntax errors are committed by the programmer when developing, or transcribing the program, and can be detected by the language translators, such as the Compiler as it attempts to translate a program. Such errors must be corrected by the programmer before the program runs.
Logical (arithmetic) errors.
These are errors in the program logic.
Logical errors relate to the logic of processing followed in the program to get the desired results. E.g., they may occur as a result of misuse of logical operators.
Logical errors cannot be detected by the translator. The programmer will detect them when the program results are produced.
The program will run, but give the wrong output or stop during execution.
Run-time (Execution) errors.
These errors occur during program execution.
Run-time (execution) errors occur when the programmer introduces new features in the program, which are not part of the translator’s standards.
For example; they may occur if:
- The computer is asked to divide a number by zero.
- The number generated as a result of an instruction is too large to fit in a memory location.
- When you raise a number to a very big power that cannot be accommodated in the Register’s structure of the computer.
- In case of a closed loop in the program, leading to a set of instructions being executed repetitively for a long time.
Execution errors are not detected by the translator programs, but are detected by the computer during execution. Sometimes, execution errors may lead to premature end of a program.
To detect and eliminate Execution errors, a test run should be performed on the program after it has been translated.
These are meaning errors. They occur when the programmer develops statements, which are not projecting towards the desired goal. Such statements will create deviations from the desired objectives.
Semantic errors are not detected by the computer. The programmer detects them when the program results are produced.
- IF GP>=1500 OR 2200 THEN
TAX: = GP – (GP * 13%)
- IF GP>=1500 AND GP<= 2200 THEN
TAX: = GP – (GP * 13%)
In the 1st statement, if the selection is between 1500 & 2200, the computer will pick only 1500 & 2200, and the other values will not be touched.
In the 2nd statement, the computer will be able to pick all the values between 1500 & 2200 because of the ‘AND’ operator.
These are the errors, which occur as a result of misusing Reserved words (words reserved for a particular language).
- State the three types of errors that can be experienced in program testing, and how each can be detected.
- Syntax errors can be detected by the help of translators while logical errors are detected differently. Explain FIVE methods which can be used to detect Logical errors.
The term Bug is used to refer to an error in a computer program.
Most programming errors often remain undetected until an attempt is made to translate a program.
The most common errors include:-
- Improperly declared Constants and Variables.
- A reference to undeclared variable.
- Incorrect punctuation.
Debugging is therefore, the process of detecting, locating & correcting (removing, eliminating) all errors (mistakes or bugs) that may exist in a computer program.
TYPES OF TESTING (Methods of error detection)
For the program to be assumed as correct, several testing needs to be conducted by the programmer to ascertain/establish their validity.
There are several methods of testing a program for errors. These include:
- Dry running (Desk checking).
- Translator system checking.
- Functional testing.
- Use of Test data.
- Use of debugging utilities.
- Diagnostic procedures.
- System test with actual data.
Dry Running (Desk checking):
Dry running is a method of checking a program for errors by making the corrections on a paper before entering it in the program editor.
It involves going through the program while still on paper verifying & validating its possible results. If the final results agree with the original test data used, the programmer can then type the program into the computer and translate it.
- Dry running helps the programmer to identify the program instructions, detect the most obvious syntax and logical errors, & the possible output.
- Dry running is much faster. This is because; it involves the use of human brain as the processor, which has got a well inbuilt common sense.
Translator system checking:
This is a type of testing, which involves the computer & the translator programs.
After entering the program, it is checked using a translator to detect any syntax errors. The translator can be a Compiler or an Interpreter, which goes through the set of instructions & produces a list of errors, or a program/statement listing which is free from errors.
Functional testing (White-box testing):
This type of testing is based upon examining the internal structure of a program & selecting test data, which give rise to the alternative cases of control flow.
Use of Test data.
The accuracy of a program can be tested by inputting a set of values referred to as Test data. The test data is designed to produce predictable output.
There are 2 types of test data;
- Real data (live data): – test data obtained from the real problem environment (practical applications).
- Dummy data: – assumed test data.
The programmer invents simple test data, which he/she uses to carry out trial runs of the new program. At each run, the programmer enters various data variations including data with errors to test how the system will behave. For example, if the input required is of numeric type, the programmer may enter alphabetic characters. The programmer will then compare the output produced with the predicted (actual) output.
- Where possible, the program should be tested using the same test data that was used for desk checking. More strict/rigid tests should be applied on the program in order to test the program to its limits.
- Only Logical errors & Semantic errors can be corrected by the programmer using test data.
- A good program should not crash due to incorrect data entry but should inform the user about the irregularity and request for the correct data to be entered.
Use of debugging utilities.
After the program has been entered in the program editor, debugging utilities which are built in the computer can be run during translation to detect any syntax errors in the program.
The errors are corrected and the debugging process is repeated again to find out more errors, before the program is executed.
For complex programs, diagnostic procedures, such as Trace routines, may be used to find logical errors.
A Trace prints out the results at each processing step to enable errors to be detected quickly.
System Test with actual data.
This is whereby the new program is run in parallel with the existing system for a short time so that results can be compared and adjustments made. In such cases, the system test is made using actual data.
- Differentiate between Testing and Debugging.
- What is Dry running?
Implementation and Maintenance.
Implementation refers to the actual delivery, installation and putting of the new program into use.
The program is put into use after it is fully tested, well documented, and after training the staff who will be involved in the running of the new program.
Structured Walk Through:
It is an organized style of evaluating/reviewing a program by a team of other programmers, which then reports to the programming team.
REVIEW AND MAINTENANCE.
Once the program becomes operational, it should be maintained throughout its life, i.e., new routines should be added, obsolete routines removed, & the existing routines adjusted so that the program may adapt to enhanced functional environments.
The main objective of maintenance is to keep the system functioning at an acceptable level.
Program maintenance mainly involves: –
- Correcting errors that may be encountered after the program has been implemented or exposed to extensive use.
- Changing procedures.
- Hardware and software maintenance.
- Changing parameters and algorithms used to develop the original programs.
- Making any adjustments as new technology comes.
Note. Program maintenance runs parallel to the maintenance of the program documentation, i.e., any time maintenance is carried out on the program, the documentation should also be updated to convey the right image of the system.
After writing, testing, and debugging a program, it must be documented. In other words, the programmer should describe all what he was doing during the program development stages.
Program documentation is the writing of supportive materials explaining how the program can be used by users, installed by operators, or modified by other programmers.
Note. All the program development activities (i.e., from the initial stage up to the complete program) should be documented/recorded in order to assist in the development of the program, future modification of the program, general maintenance, machine & software conversion at a later date, and program changeover.
Documentation can either be; Internal or External.
Internal documentation is the writing of non-executable lines (comments) in the source program that help other programmers to understand the code statements.
External documentation refers to reference materials such as user manuals printed as booklets.
Types of program documentation.
There are 3 target groups for any type of documentation:
- User-oriented documentation.
This enables the user to learn how to use the program as quickly as possible, and with little help from the program developer.
- Operator-oriented documentation:
This is meant for computer operators such as the technical staff. It is used to help them install & maintain the program.
- Programmer-oriented documentation:
This is a detailed documentation written for skilled programmers. It provides the necessary technical information to help in future modification of the program.
Some documents used in program documentation.
- User guide/ manual.
This is a manual provided for an end-user to enable him/her use or operate the program with minimal or no guidance.
A User guide is used in user-oriented documentation.
- Reference guide.
It is used by someone who already knows how to use the program but needs to be reminded about a particular point or obtain more detailed information about a particular feature.
- Quick Reference guide.
This could be a single sheet or card small enough to fit into a pocket. It is used by the user to get help for the common tasks carried out within the program.
- Technical manuals.
They are intended for System analysts & Programmers. They assist in maintaining & modifying the program design and code.
Contents in a program document.
- Title of the program.
- Function of the program.
- Language used.
- Hardware & Software required to support the processing of the system.
- File specifications (details of the data structures used, & details of how data files are to be organized, accessed, and kept secure).
- Limitations of the program.
- Format of the input & the output expected.
- Design of the program using the design tools (i.e., detailed algorithms & procedures used).
- A listing of the Source program and the program flowcharts.
- A carefully devised set of Test data, and a table of expected results.
- Detailed instructions on how to run the program.
- What is program designing?
- (a). Define program documentation.
(b). What does a program documentation contain?
- Briefly explain how each of the following documents are useful in programming?
- User manual / guide.
- Reference guide.
- Quick reference guide.
- Program documentation is different from Implementation. Explain.
- Outline and briefly explain the stages involved in program development.
DEVELOPING OF ALGORITHMS
After carefully analyzing the requirements specification, the programmer usually comes up with the algorithm.
Definition of an Algorithm:
- An Algorithm is a limited number of logical steps that a program follows in order to solve a problem.
- A step-by-step (a set of) instructions which when followed will produce a solution to a given problem.
- Algorithms take little or no account of the programming language.
- They must be precise/ accurate, unambiguous/clear and should guarantee a solution.
Program design Tools.
Algorithms can be illustrated using the following tools:
- Decision Tables.
- Decision Trees.
Note. For any given problem, the programmer must choose which algorithm (method) is best suited to solve it.
- A pseudocode is a method of documenting a program logic in which English-like statements are used to describe the processing steps.
- These are structured English-like phrases that indicate the program steps to be followed to solve a given problem.
- The term “Code” usually refers to a computer program. This implies that, some of the words used in a pseudocode may be drawn from a certain programming language and then mixed with English to form structured statements that are easily understood by non-programmers, and also make a lot of sense to programmers.
However, pseudocodes are not executable by a computer.
Guidelines for designing a good pseudocode.
- The statements must be short, clear and readable.
- The statements must not have more than one meaning (i.e., should not be ambiguous).
- The pseudocode lines should be clearly outlined and indented.
- A pseudocode must have a Begin and an end.
i.e., a pseudocode should show clearly the start and stop of executable statements and the control structures.
- The input, output and processing statements should be clearly stated using keywords such as PRINT, READ, INPUT, etc.
Write a pseudocode that can be used to prompt the user to enter two numbers, calculate the sum and average of the two numbers and then display the output on the screen.
PRINT “Enter two numbers”
INPUT X, Y
Sum = X + Y
Average = Sum/2
Write a structured algorithm that would prompt the user to enter the Length and Width of a rectangle, calculate the Area and Perimeter, then display the result.
Step 1: Draw the rectangle of Length (L) and Width (W).
Step 2: Write down the Pseudocode.
PRINT “Enter Length and Width”
READ L, W
Area = L * W
Perimeter = 2 (L + W)
Write a pseudocode that can be used to calculate the Diameter, Circumference and Area of a circle and then display the output on the screen.
Set π to 3.14
Prompt the user for the Radius (R)
Store the radius in a variable (R)
Set Diameter to 2 * Radius
Set Circumference to π * 2 * Radius
Set Area to π * Sqr (Radius)
Write a pseudocode for a program that would be used to solve equation: E = MC2.
Enter values from M to C
E = M * C * C
- It is important to use program control structures when writing Pseudocodes. The most common constructs are:
- Looping (Repetition / Iteration) – used where instructions are to be repeated under certain conditions.
- Selection – used when choosing a specified group of instructions for execution. The group chosen depends on certain conditions being satisfied.
Write a pseudocode for a program that can be used to classify people according to age. If a person is more than 20 years; output “Adult” else output “Young person”.
PRINT “Enter the Age”
IF Age > 20 THEN
PRINT “Young person”
Note. Pseudocodes make an algorithm easier to understand. This is because; the algorithm can be read from top to bottom without the need for jumping backwards or forwards to follow the logic of the algorithm as in flowcharts.
- A Flowchart is a diagrammatic or pictorial representation of a program’s algorithm.
- It is a chart that demonstrates the logical sequence of events that must be performed to solve a problem.
Types of Flowcharts.
There are 2 common types of Flowcharts:
- System flowchart.
A System flowchart is a graphical model that illustrates each basic step of a data processing system.
It illustrates (in summary) the sequence of events in a system, showing the department or function responsible for each event.
- Program flowchart.
This is a diagram that describes, in sequence, all the operations required to process data in a computer program.
A program flowchart graphically represents the types of instructions contained in a computer program as well as their sequence & logic.
A Flowchart is constructed using a set of special shapes (or symbols) that have specific meaning. Symbols are used to represent operations, or data flow on a flowchart.
Each symbol contains information (short text) that describes what must be done at that point.
The symbols are joined by arrows to obtain a complete Flowchart. The arrows show the order in which the instruction must be executed.
SYMBOLS USED IN PROGRAM FLOWCHARTS.
Below is a standard set of symbols used to draw program flowcharts as created by American National Standard Institute (ANSI).
- Terminal symbol.
Ellipse (Oval in shape)
It is used to indicate the point at which a flowchart, a process or an algorithm begins & ends.
- All Flowcharts must have a START & STOP symbol. The START/BEGIN symbol is the first symbol of a flowchart, & identifies the point at which the analysis of the flowchart should begin. The STOP/END symbol is the last symbol of a flowchart, & indicates the end of the flowchart.
- The words Begin & End (or Start & Stop) should be inserted in the Terminal symbol.
- Input or Output symbol.
– It is used to identify/specify an input operation or output operation.
Input operation Output operation
Note. The words mostly associated with I/O operations are READ & PRINT. READ describes the entry of computer data, while PRINT relates to the printed output of information.
- Process symbol.
– Process symbol is used to indicate that a processing or data transformation is taking place.
The information placed within the process symbol may be an algebraic formula or a sentence to describe processing.
Processing defined as a Formula Processing defined as a Sentence
- Decision symbol.
– It is used to indicate/ specify a condition or to show the decision to be made.
There are 2 main components of a Decision symbol:
- A question asked within the Decision symbol, that indicates the comparison / logical operation.
- The results of the comparison (which are given in terms of YES or NO).
The arrows labeled YES or NO lead to the required action corresponding to the answer to the question.
- Flow lines.
Flow lines with arrowheads are used to indicate the direction of processing of the program logic, i.e., they show the order in which the instructions are to be executed.
The normal flow of a flowchart is from Top to Bottom, and Left to Right.
Note. Flow lines should never cross each other.
- Connector symbol.
Sometimes, a flowchart becomes too long to fit in a single page, such that the flow lines start crisscrossing at many places causing confusion & also making the flowchart difficult to understand.
The Connector symbol is used as a connecting point for arrows coming from different directions.
A Connector symbol is represented by a Circle, and a letter or digit is placed within the circle to indicate the link.
Note. Connectors do not represent any operation. They are used to connect two parts of a flowchart, indicating that the flow of data is not broken.
General guidelines for drawing a program flowchart.
- A flowchart should have only one entry/starting point and one exit point (i.e., ensure that the flowchart has a logical start and finish).
- The flowchart should be clear, neat and easy to follow.
- Use the correct symbol at each stage in the flowchart.
- The flowchart should not be open to more than one interpretation.
- Avoid overlapping the lines used to show the flow of logic as this can create confusion in the flowchart.
- Make comparison instructions simple, i.e., capable of YES/NO answers.
- The logical flow should be clearly shown using arrows.
Note. A flowchart should flow from the Top to Bottom of a page, and from the Left to the Right.
- Where necessary, use Connectors to reduce the number of flow lines.
Connectors are helpful when a flowchart is several pages long, and where several loops are needed in the logic of the flowchart.
- Check to ensure that the flowchart is logically correct & complete.
Draw a flowchart for a program that can be used to prompt the user to enter two numbers, find the sum and average of the two numbers and then display the output on the screen.
Draw a flowchart for a program that would prompt the user to enter the Length and Width of a rectangle, calculate the Area and Perimeter, then display the result.
Draw a flowchart for a program that can be used to calculate the Diameter, Circumference and Area of a circle and then display the output on the screen.
Design a flowchart for a program that can be used to classify people according to age. If a person is more than 20 years; output “Adult” else output “Young person”.
Draw a flowchart for a program that would be used to classify animals according to sex. If a letter M is input, the program should display ‘Male’ otherwise it should display “Female”.
Write a program using a flowchart to convert temperature from 0C to 0F.
Fahrenheit =32 + (9o x C/5).
- A flowchart must have a Start and an end.
- A flowchart is useful when the algorithm is short & the flowchart can fit conveniently on a single page. If the flowchart is too large, it is recommended to use Pseudocodes for long & complicated programs.
Advantages of using Flowcharts.
The following are the benefits of Flowcharts:
- Quicker understanding of relationships.
They assist programmers to understand procedures more quickly.
A programmer can represent a lengthy procedure more easily with the help of a flowchart than describing it by means of written notes.
- Effective synthesis.
Flowcharts may be used as working models in the design of new programs and systems.
- Proper program documentation.
Program flowcharts serve as good program documentation, which is needed for the following reasons:
- If programs are modified in future, the flowcharts will direct the programmer on what was originally done.
- When staff changes occur, the flowcharts may help new employees understand the existing programs.
- Flowcharts assist in program conversion when new hardware/software are acquired.
Program flowcharts act as a guide during the program preparation stage. Instructions coded in a programming language may be checked against the flowchart to ensure that no steps are omitted.
- Orderly debugging and testing of programs.
Flowcharts help in detecting, locating and removing mistakes.
The programmer can refer to the flowchart as he/she re-checks the coding steps, & the logic of the written instructions.
- Efficient program maintenance.
Flowcharts facilitate the maintenance of operating programs. They help the programmer to concentrate on the part of the information flow which is to be modified.
Limitations of using Flowcharts.
- Flowcharts are complex, clumsy & become unclear, especially when the program logic is complex.
- If changes are to be made, the flowchart may require complete re-drawing.
- Reproduction of flowcharts is usually a problem, since the flowchart symbols cannot be typed.
- No uniform practice is followed for drawing flowcharts as it is used as an aid to the program.
- Sometimes, it becomes difficult to establish the link between various conditions, and the actions to be taken upon a particular condition.
- Define the following:
- (a). State the various types of flowcharts.
(b). Discuss the advantages and disadvantages of flowcharts.