Search Engine

Monday, 5 September 2011

Programming and Basics

LOOP

While writing a program it is necessary to repeat a part of a program for a number of times. The best solution for this is to use a loop it is a method which executes a part of the program repeatedly as specified by the programmer.

TYPES OF LOOPS

a) Pre-Test Loop
b) Post-Test Loop

a) PRE – TEST LOOP

As its name indicates, checks the looping condition at the start of the loop if the condition is true the loop execution starts otherwise stops. This loop is used in a situation when part of program is to be repeated for a fixed number of time.
e.g., FOR …… NEXT.

b) POST – TEST LOOP

This loop checks the looping condition at the end of loop and decides whether or not to continue the execution. This loop is used when a part of the program needs to be repeated until a specified condition is met.
e.g., WHILE …… WEND.

FLOW CHART

Flow chart is a symbolic representation of flow of programme. It can graphically represent data processing procedure Flow chart serves two purposes, i.e., the planning of the program structure as an aid in writing the computer program. Secondly the documentation of the program logic and work flow for the purpose of the communication with other person and to recall a program at a later time. If the program needs to be changed. The second purpose is very important because it is very difficult to check the logic of the program.

SYMBOLS OF FLOW CHART

TERMINAL

The terminal symbol is used to indicate the beginning, ending of the program logic flow. It is the first and last symbol of the flow chart.

INPUT / OUTPUT BOX

The input/output box is used to denote any function of an input and output in the program. If there is a program instruction to input or output the data from any I/O device that step will be indicated on this symbol.

PROCESS BOX

A processing symbol is used in a flow chart to represent arithmetical and data movement instructions.

FLOW LINES

Flow lines are used to indicate the flow of operations. The exact sequence in which the instructions are to be executed. The flow of flow chart is normally from top to bottom and left to right.

DECISION BOX

The decision box is used in a flow chart to indicate a point at which a decision has to be made and to branch to one or more alternative points that is possible during execution. The appropriate path followed, depends on the result of the decision.

CONNECTOR

A flow chart becomes complex, when the number and direction of flow lines is confusing or it spread over more than one page. It is useful to utilize the connector symbol as a substitute for flow lines.

SYSTEM FLOW CHART

System Flow Chart is used to describe complete data processing cycle including the hardware devices and media used. A System Flow Chart shows flow of data in a system where and in what form it is received by the system, how it is input to the computer and what storage media are used to hold it. The symbol used in system flow chart indicates the peripherals to be used in data processing procedure, where output will be produced. System flow chart do not explain the logic of the programs.

ERRORS

Errors are the mistakes made by the programmer during program writing. A program relays run perfectly for the first time and each program needs to be tested to ensure that it is correct and contains no errors. There are three types of errors generally encountered.
a) Syntax Error
b) Logical Error
c) Run Time Error

a. SYNTAX ERROR

The syntax of a programming language is the set of rules to be followed when writing a program in that language. These rules are similar to the grammar rules of Urdu or English language. When a program violates these rules, computer generates a syntax error. Syntax must be correct before program execution.

b. LOGICAL ERROR

These errors are the most difficult ones to find, if a programmer enters a sign of multiply instead of addition at the time of making the program, the answer will not be correct because interpreter will not be able the detect these types of errors. A logical error will not stop the execution of the program but the result will not be accurate.

c. RUN TIME ERROR

These types of errors stop the execution of the program. It may be due to entering the invalid data at the time of executing a program. For example, if a program is expecting the user to enter the numeric data and the user enters a string data, computer will display an error message.

BITS & BYTES

The smallest piece of data that can be recognized and used by a computer, is the bit, a binary digit. A bit is a single binary value, either a 1 or 0. A group of eight bits is called a byte. The byte is the basic unit for measure of the size of the memory, with today’s computer memory sizes. It is more common to hear the term kilobyte (KB) or megabyte (MB).

COMPUTER WORD

A computer word is the number of adjacent bits that can be stored and manipulated as a unit. Just an English vocabulary words are of varying lengths so are computer words. Many microcomputers have the ability to manipulate a 32 bit word, while some models have words length of 8 and 16 bits.

LIBRARY FUNCTIONS

GW-BASIC provides many built in functions which are called binary functions. Each function is composed of a format or a short program, that requires at least one parameter to be passed. A parameter is a value which is in that formula or program and this formula or program returns a result. This result can be stored in any appropriate variable or directly displayed on monitor. A library function which has “$” sign is called string library function while others are called numeric library function. A string function returns string value while a numeric function returns numeric value. Following are some library functions.
ABS, MID$, LEN, LEFT$, ASC, CHR$, TAB

EXPRESSIONS

An expression is a combination of constants and variables linked by arithmetic operators like (+, -, *, /, \). Expressions are used to perform different operations. The expressions are evaluated from left to right but some operators have priority over the others. Parenthesis are evaluated first then multiplication and division have the same priority from left to right. Similarly the addition and subtraction are evaluated with equal priorities. If all the operators are used in an expression have the same priority then the expression be executed from left to right.
The expressions can be of three types.
  • Arithmetic expressions
  • Logical expressions
  • Relational expressions.
ARITHMETICAL EXPRESSIONS

In an arithmetic expression the following operators are used in conjunction with the operands.
SymbolMeaning
+ Addition
- Subtraction
  • Multiplication
/ Division
^ Exponentiation
( Left parenthesis
) Right parenthesis

RELATIONAL EXPRESSION

A Relational expression is composed of operands linked by the relational operators. The relational operators used in the relational expression are given.
SymbolMeaning
= equal to
> greater than
< less than
<> not equal to
>= greater than or equal to
<= less than or equal to Example A > B
B <> C

LOGICAL EXPRESSIONS

When a selections is based upon one or more condition being true. It is possible to combine the condition together using logical operators and the resulting condition would either be true or false the most commonly used logical operators are AND, OR and NOT.

COMPUTER LANGUAGE

Language is a system for representation and communication of information or data. Like human beings, a language or signal is required to communicate between two persons. Similarly, we cannot obtain any result by computer without langtage. Computer does not understand directly what we are communicating with computer as English or Arabic, it understands only machine language (binary codes 0-1). Computer translates English language into machine codes through interpreter then process instructions and give us the results.
The computer languages can be divided into two main levels.
  • Machine language (0-1)
  • Symbolic language (A-Z)
Symbolic languages are further divide into two main levels
  • High-level language
  • Low-level language

MACHINE LANGUAGE

Although computers can be programmed to understand many different computer language. There is only one language understood by the computer without using a translation program. This language is called the machine language or the machine codes. Machine codes are the fundamental language of the computer and is normally written as strings of binary 0-1.

ADVANTAGES AND LIMITATIONS OF MACHINE LANGUAGE

Programs written in machine language can be executed very fast by the computer. This is mainly because machine instructions are directly understood by the CPU and no translation of program is required.
However, writing a program in machine language has several disadvantage.

MACHINE DEPENDENT

Because the internal design of every type of computer is different from every other type of computer and needs different electrical signals to operate. The machine language also is different from computer to computer.

DIFFICULT TO PROGRAM

Although easily used by the computer, machine language is difficult to program. It is necessary for the programmer either to memorize the dozens of code number for the commands in the machine’s instruction set or to constantly refer to a reference card.

DIFFICULT TO MODIFY

It is difficult to correct or modify machine language programs. Checking machine instructions to locate errors is difficult as writing them initially.
In short, writing a program in machine language is so difficult and time consuming.

SYMBOLIC LANGUAGES

In symbolic languages, alphabets are used (a-z). symbolic languages are further divide into two main levels.
  • High level languages
  • Low level languages

LOW LEVEL LANGUAGE

A language which is one step higher than machine language in human readability is called Assembly Language or a low-level language. In an assembly language binary numbers are replaced by human readable symbols called mnemonics. Thus a low-level language is better in understanding than a machine language for humans and almost has the same efficiency as machine language for computer operation. An assembly language is a combination of mnemonic, operation codes and symbolic codes for addresses. Each computer uses and has a mnemonic code for each instruction, which may vary from computer to computer. Some of the commonly used codes are given in the following table.
COMMAND NAMEMNEMONIC
Add – ADD
Subtract – SUB
Multiply – MUL
Compare Registry – CR
Compare – COMP
Branch Condition -BC
Code Register -LR
Move Characters -MVE
Store Characters -STC
Store Accumulator – STA
An assembly language is very efficient but it is difficult to work with and it requires good skills for programming. A program written in an assembly language is translated into a machine language before execution. A computer program which translates any assembly language into its equivalent machine code is known as an assembler.

HIGH – LEVEL LANGUAGE

A language is one step higher than low-level languages in human readability is called high-level language. High – level languages are easy to understand. They are also called English oriented languages in which instruction are given using words. Such as add, subtract, input, print, etc. high level language are very easy for programming, programmer prefer them for software designing that’s why these languages are also called user’s friendly languages. Every high level language must be converted into machine language before execution, therefore every high level language has its own separate translating program called compiler or interpreter. That’s why some time these languages are called compiler langauges. COBOL, BASIC, PASCAL, RPG, FORTRAN are some high level languages.

INTERPRETER

An interpreter is a set of programs which translates the high-level language into machine acceptable form. The interpreters are slow in speed as compared to compilers. The interpreter takes a single line of the source code, translates that line into object code and carries it out immediately. The process is repeated line by line until the whole program has been translated and run. If the program loops back to earlier statements, they will be translated afresh each time round. This means that both the source program and the interpreter must remain in the main memory together which may limit the space available for data. Perhaps the biggest drawback of an interpreter is the time it takes to translate and run a program including all the repetition which can be involved.

PROGRAM DEVELOPMENT PROCESS

In order to develop a computer program, a programmer has to go through the following stages:

1. DEFINING AND ANALYSING THE PROBLEM

In this step a programmer studies the problem and decides how the problem will be best solved. Studying a problem is necessary because it helps a programmer to decide about:
  • The facts and figures to be collected.
  • The way in which the program will be designed.
  • The language in which the program will be most suitable.
  • What is the desired output and in which form it is needed, etc.

2. DESIGNING THE ALGORITHM

An algorithm is a set of instructions or sequence of steps that must be carried out before a programmer starts preparing his program. The programmer designs an algorithm to help visualize possible alternatives in a program.

 3. FLOWCHARTING

A flow chart is a graphical representation of a program which helps a programmer to decide on various data processing procedures with the help of labeled geometrical diagrams. A flow chart is mainly used to describe the complete data processing system including the hardware devices and media used. It is very necessary for a programmer to know about the available devices before developing a program.

4. CODING OR WRITING THE PROGRAM

The next job after analysing the problem is to write the program in a high-level language, usually called coding. This is achieved by translating the flow chart in an appropriate high-level language, of course according to the syntax rules of the language.

5. TEST EXECUTION

The process of execution of any program to find out for errors or bugs (mistakes) is called test execution. This is very important because it helps a programmer to check the logic of the program and to ensure that the program is error-free and workable.

6. DEBUGGING

It is a term which is used extensively in programming. Debugging is the process of detecting, locating and correcting the bugs by running the programs again and again.

7. FINAL DOCUMENTATION

It is written information about any computer software. Final document guides the user about how to use the program in the most efficient way.

MODES OF OPERATION

There are two modes of operation for BASIC. The mode that you are in determines what BASIC will do with the instruction you give it. When you start BASIC you receive the OK prompt. You then have two modes available to you immediately.

DIRECT MODE

In the direct mode BASIC acts like a calculator. No line numbers are required. Direct mode is not of course the main purpose of BASIC, but it is useful at times particularly when you are debugging program or short problems in which you want to perform quick calculation e.g., PRINT 3+4.

INDIRECT MODE

In this mode you first put a line number on each statement. Once you have a program you can run it and get your results. The indirect mode saves your instructions in the computer along with their line number, you can execute the program as many times as you wish simply by typing RUN.

STEPS OF PROGRAMMING

There are five steps in preparing a computer programme which are also called ABCDE of Programming.

ANALYSIS

In this step the system analyst tries to become familiar with the problem. He has to study the problem and prepare some notes upon that problem. He also notes that what is given, what is required and what will computer can do.

BLOCKING

In this step the programmer converts the analyst report to a series of steps through which the computer will give the required result. The steps are commonly known as Algorithm. There are different ways to write those detailed sequential steps. The most common method used is flow charting. A flow chart is symbolic representation of flow of a programme.

CODING

In this step the programmer writes the programme in any computer language. This step is known as coding. After this programme is fed into the computer and is compiled with the help of a given compiler.

DEBUGGING

Debugging is a step in which a programmer corrects a syntax error which may come after the compilation.

TESTING

Testing is a step where the programmer is finally testing the programme for execution (there may be any logical mistake which compiler cannot trace).

EXECUTION

In this step we send the programme for execution where company’s data will be fed and process.

VARIABLES AND CONSTANTS

VARIABLES

Variables are names used to represent values used in BASIC programme. The values of a variable may be
assigned by the programmer or it may be assigned as the result of calculation in the programme. Before a variable is assigned a value is assumed to be zero (or null for string variable).

VARIABLES NAMES & DECLARATION CHARACTERS

Variable names may be of any length up 40 characters are significant. Variable name can contain letters, numbers and decimal point. However, the first character must be a letter. A variable should not be a reserve word.
Variable may represent either a numeric value or a string.

NUMERIC VARIABLE

Numeric variable names may be declared as integer, single precision, double precision values. The type of declaration characters for these variable names are as follows.

STRING VARIABLE

In programming we often use to handle alphanumeric or string variables. String variables consist of names, addresses or in general any string or series of letters, number or special characters.
Without the use of string variable whenever any differentiation needs to be made e.g., from employee to employee or from application no. to application no., a number has to be assign to each employee or each application.
A string variable name starts with an alphabet and terminate with a dollar sign ($). In a string the value must be in quotation marks. No arithmetic operations except addition and in addition the values do not add they are just written together. The maximum number of character allowed in a string varies from system to system but a typical value is 256.

CONSTANTS

Constants are those that do not change while executing the programme. BASIC deals with two types of constant.
1. Numeric constant
2. String constant

1. NUMERIC CONSTANT

All numbers belong to this category because their values remain constant during execution.
They may take any of the following forms:
1. Commas are not allowed in a numeric constant.
2. The use of the positive sign is optional but negative sign should be used if the number is negative.

2. STRING CONSTANT

A string constant is any set of valid basic characters enclosed in quotation marks. The quotation marks do not form part of string. Strings are used to represent non-numeric information such:
1. Name of persons and places
2. Addresses
3. Days, Months, Years.

INTRODUCTION TO BASIC

BASIC is a high level language used for purpose of writing a program on a computer. It stands for Beginners All-purpose Symbolic Instruction Code. BASIC is an easy to use “friendly” language where instruction resembles elementary, algebraic formulas and certain English keywords such Let, Read, Print, Goto etc.

HISTORY OF BASIC

The language was developed at Dartmouth College in 1967, under the direction of John Kemeny and Thomas Kurtz. It was quickly discovered and adopted. All the major computer manufacturers offered their own version of BASIC for their particular computers.
In 1978, the American National Standard Institute standardized an essential subset of BASIC in order to promote uniformity from one version of BASIC into another.
In recent years some new version of BASIC have been developed which included a variety of features that are not included in more traditional versions.

STRUCTURE OF BASIC PROGRAM

Each instruction in a BASIC program is written as a separate statement. Thus a program will be composed of a sequence of statements.
The following rules apply to all BASIC statements:
1. Every statement must appear on a separate line number.
2. Each statement number must be followed by a BASIC keyword which indicates the type of instruction.
3. On one single line number we cannot write two statements, if we need we must use “colon”.
4. We can write 255 characters on one line.

No comments:

Post a Comment