You are on page 1of 56

1 Form 5 Lesson Notes Part 1 Program & Programming

LESSON ONE : PROGRAMMING 1. A computer program is a series of organised instructions that directs a computer to perform tasks. Without programs, computers are useless. 2. A program is like a recipe. It contains a list of variables (called ingredients) and a list of statements (called directions) that tell the computer what to do with the variables. 3. Like a recipe, a program can be written in different programming languages which may express the steps differently according to the programming languages syntax, but deliver the same end result. 4. Programming is a creation of a set of commands or instructions which directs a computer in carrying out a task. 5. Later these commands or instructions will be compiled and / or interpreted and then transformed to executable instructions that a computer or electronic device can execute or run. 6. Programming language is a set of words, symbols, and code that enables human to communicate with computers. 7. It is a language used for writing computer programs that direct a computer perform computation and to organize the flow of control between mechanical devices. 8. Hundreds of programming languages exist today. Each language has its own standard or rules for writing the commands and / or instructions. 9. Examples of programming languages are : o Basic (Beginners All Purpose Symbolic Instruction Code) o Pascal o C o Smalltalk

2 Form 5 Lesson Notes Part 1 Program & Programming

LESSON TWO : GENERATIONS OF PROGRAMMING LANGUAGES 1. Levels of programming languages : a) Low-level language b) High-level language 2. A low-level programming language is a programming language that provides little or no abstraction from a computers microprocessor. 3. A high-level programming language is a programming language that is more abstract, easier to use, and more portable across platform. 4. Generations of programming languages : a) First Generation Language machine language b) Second Generation Language assembly language c) Third Generation Language COBOL, BASIC, C, Ada, Compilers, Interpreter d) Fourth Generation Language Report Generators, Query Language Application generators e) Fifth Generation Language natural language 5. First and Second Generation Programming Language are Low-level Programming Languages. 6. Third, Fourth and Fifth Generation Programming Language are HighLevel Programming Language. FIRST GENERATION PROGRAMMING LANGUAGE 1. The first generation of programming language, or 1GL, is machine language. 2. Machine language is a set of instructions and data that a computers central processing unit can execute directly. 3. Machine language statements are written in binary code, and each statement corresponds to one machine action. SECOND GENERATION PROGRAMMING LANGUAGE 1. The second generation programming language, 2GL, is assembly language. 2. Assembly language is the human-readable notation for the machine language used to control specific computer operations. 3. An assembly language programmer writes instructions using symbolic instruction codes that are meaningful abbreviations or mnemonics. 4. An assembler is a program that translates assembly language into machine language.

3 Form 5 Lesson Notes Part 1 Program & Programming

5. Since assembly language consist of human readable abbreviations, the assembler must first convert assembly language into machine-readable language before the computer can readily understand its instructions. THIRD GENERATION PROGRAMMING LANGUAGE 1. The third generation of programming language, 3GL, or procedural language uses a series of English-like words that are closer to human language to write instructions. 2. High-level programming languages make complex programming simpler and easier to read, write and maintain. 3. Programs written in a high-level programming language must be translated into machine language by a compiler or interpreter. 4. PASCAL, FORTRAN, BASIC, COBOL, C and C++ are examples of third generation programming languages. FOURTH GENERATION PROGRAMMING LANGUAGE 1. The fourth generation programming language or non-procedural language, often abbreviated as 4GL, enables users to access data in a database. 2. Example : SQL can be used to query data. 3. A very high-level programming language is usually limited to a very specific application that might use syntax which is never used in other programming languages. 4. SQL, NOMAD and FOCUS are examples of fourth generation programming languages. FIFTH GENERATION PROGRAMMING LANGUAGE 1. The fifth generation programming language or visual programming language is also known as natural language. 2. It provides a visual or graphical interface, called visual programming environment for creating source codes. 3. Fifth generation programming allows people to interact with computers without needing any specialized knowledge. 4. People can talk to computers and the voice recognition systems cam convert spoken sounds into written words, but these systems do not understand what they are writing; they simply take dictation. 5. Prolog and Mercury are the best known fifth generation languages.

4 Form 5 Lesson Notes Part 1 Program & Programming

LESSON THREE : PROGRAMMING APPROACHES There are different approaches in programming : a) Structured Programming b) Object-Oriented Programming STRUCTURED PROGRAMMING 1. Structured programming often uses a top-down design model where developers map out the overall program structure into separate subsections from top to bottom.

2. A program may have a module or several modules.

3. Structured programming is beneficial for organizing and coding computer programs which employ a hierarchy of modules. 4. This means that control is passed downwards only through the hierarchy. 5. Examples of structured programming languages include Ada, Pascal and Fortran.

5 Form 5 Lesson Notes Part 1 Program & Programming

OBJECT-ORIENTED PROGRAMMING 1. The object-oriented approach refers to a special type of programming approach that combines data with functions to create objects.

2. In object-oriented program, the objects have relationships with one another. 3. For example, if bicycle is an object, then mountain bike, road bike and tandem bike would be other objects that have some common features of a bicycle, but yet have a few differences. 4. Among these differences are : a mountain bike has multiple gears, a road bike has an engine, and a tandem bike has two sets of seats and pedals for two riders. 5. One of the earliest OOP languages is Smalltalk. 6. Java, Visual Basic and C++ are examples of popular OOP languages. DIFFERENCES BETWEEN STRUCTURED AND OBJECTORIENTED PROGRAMMING 1. Structured programming often uses a top-down design model 2. The object-oriented programming approach uses objects.

6 Form 5 Lesson Notes Part 1 Program & Programming

LESSON FOUR : TRANSLATORS 1. All software packages or programs are written in high-level languages, for example, C++, Visual Basic and Java. 2. In order for the computer to be able to carry out the instructions, the highlevel languages must be translated into machine language before the computer can understand and execute the instructions in the program. 3. The translation of high level languages to machine language is performed by a translator. 4. There are three translation methods of programming : assembler, interpreter and compiler. 5. A programmer will write a source code which consists of the instructions needed to run a program. 6. Then the compiler or interpreter with assembler will translates the source code into machine language which is made of a sequence of bits (eg. 01100011) 7. The computer will load the machine code ad run the program. ASSEMBLER 1. An assembler is a computer program for translating assembly language essentially, a mnemonic representation of machine language into machine language that can be executed by the computer. 2. For example, in Intel 80836, the assembly language for the no operation command is NOP and its machine code representation is 10010000. 3. Example of assemblers are MACRO-80 Assembler and Microsoft MASM. INTERPRETER 1. Interpreter is a program designed to interpret and execute program directly from its source codes without compiling it first. 2. The source code of an interpreted language is interpreted and executed in real time when the user executes it. 3. The interpreter will read each code converts it to machine code and executes it line by line until the end of the program. 4. Examples of interpreter-based language are BASIC, Logo and Smalltalk.

7 Form 5 Lesson Notes Part 1 Program & Programming

COMPILER 1. Compiler is a computer program that translates source code text which is written in a high level programming language into a lower level language (e.g. assembly language or machine language) and will create an executed file. 2. The source code (in text format) will be converted into machine code which is a file consisting of binary machine code that can be executed on a computer. 3. If the compiler encounters any errors, it records them in the programminglisting file. 4. When a user wants to run the program, the object program is loaded into the memory of the computer and the program instructions begin executing. 5. A compiled code generally runs faster than programs based on interpreted language. 6. Several programming languages like C++, Pascal and COBOL use compilers as their translators.

8 Form 5 Lesson Notes Part 1 Program & Programming

LESSON FIVE : INSTALLATION OF MICROSOFT VISUAL BASIC 6.0 1. Microsoft Visual Basic 6.0 was designed to be easy to learn and use. 2. The language not only allows programmers to easily create simple GUI applications, but also has the flexibility to develop fairly complex applications as well. 3. Programming in Microsoft Visual Basic 6.0 is a combination of visually arranging components or controls on a form. 4. Hence a simple program can be created without the programmer having to write many lines of code. VISUAL BASIC 6.0 MINIMUM REQUIREMENTS

o Microsoft Windows 95 or later o 486DX / 66 MHz or higher processor o 16 MB of RAM for Windows 95 / 98 or 32 MB of RAM for
Windows XP

o A minimum of 290 MB of free had disk space


To install Visual Basic 6.0, you must key in the product number and user ID. VISUAL BASIC 6.0 FEATURES 1. Microsoft Visual Basic is fast and easy with intuitive tools that enable you to rapidly build your own Windows applications. 2. You can use Microsoft Visual Basic to develop programs such as games, calculator, phonebook database and lots more. 3. The word Visual refers to the technique used to build the Graphical User Interface (GUI). 4. Visual Basic features an easy drag and drop method to produce an interactive Graphical User Interface (GUI) for your program. 5. The Basic part refers to the BASIC (Beginners All-Purpose Symbolic Instruction Code) language, a high level programming language develop by Microsoft. 6. Among the main features of Visual Basic are drag and drop user interface, data access features, ActiveX technologies and Internet capabilities.

9 Form 5 Lesson Notes Part 1 Program & Programming

7. Drag and drop user interface allows you to instantly create an interactive user interface for your software without dozens of codes. 8. Data access features allow your application to access information from a database such as a telephone book program. 9. ActiveX technologies allow you to make use of the functionality provided by other applications. 10. Internet capabilities allow your program to interactively utilize the Internet. INSTALLING VISULA BASIC 6.0 1. Insert the Visual Basic 6.0 CD. Windows should start the Setup program automatically. 2. Follow the instructions given by the setup wizard. 3. When finished successfully, you should be able to locate Visual Basic 6.0 within your Program Files. EXPLORE THE VISUAL BASIC ENVIROMENT

o Toolbar o Toolbox o Properties window o Project window o Form layout window o Form window editing area o Active form

10 Form 5 Lesson Notes Part 1 Program & Programming

LESSON SIX : BASIC ELEMENTS IN PROGRAMMING There are five basic elements in programming : 1. Constant 2. Variables 3. Data types 4. Operators 5. Control Structures CONSTANT 1. Constant is a data container that stores information. 2. The value will never change (remain constant) at any time during the course of a program. 3. Declare is the official term used in programming to announce to the program the condition of statement in programming. Const number = 12.5 VARIABLES 1. Variable is a data container that stores information. 2. The value inside may change at any time during the course of a program. 3. Declaring variables : Dim marks As Integer Marks = 25 DATA TYPES

OPERATORS

11 Form 5 Lesson Notes Part 1 Program & Programming

Operator is a symbol that tells what action to perform.

CONTROL STRUCTURES Control structures allow the programmer to control the flow of a program.

12 Form 5 Lesson Notes Part 1 Program & Programming

LESSON SEVEN : CONSTANTS AND VARIABLES 1. The renter has to pay the rental of RM26 each month. This is the fixed value. So we call it a constant value. 2. The values that may change are total calls and service tax. They are called variables. CONSTANTS & VARIABLES Constant is a virtual data container that stores information. The value will never change (remains constant) at any time during the course of a program. Declaring constant : Const PI = 3.142 Const g = 9.8 Variable is a virtual data container that stores information. The value inside may change at any time during the course of a program. Declaring variable : Dim Total As Integer Dim NAME As String DIFFERENCES BETWEEN CONSTANTS AND VARIABLES Constants Characteristi c Value is not changeable during the course of the program. Use constant when you want to declare something that wont be changed midway in your program execution. Variables Value can be changed anytime during the course of the program. Use variable to store data that may or will change during the running of the program.

Usage

13 Form 5 Lesson Notes Part 1 Program & Programming

LESSON EIGHT : DATA TYPES 1. Data type determines the type of data a variable can store, for example a number or a character. 2. Examples of data type are integer, double, string and boolean. Data Types Examples Integer 18, 79, 21 Double 41.5, 31.47 String Kok Keong, Ali Boolean TRUE, FALSE INTEGER 1. Integer data type contains any whole number value that does not have any fractional part. 2. This is how we declare an integer type constant in Visual Basic statement:
Const Year_Birth = 1990

3. This is how we declare an integer type variable in Visual Basic statement:


Dim Age As Integer Age = 17

DOUBLE 1. Double is any number value that may and could contain a fractional part 2. This is how we declare a double type constant in Visual Basic statement:
Const PI = 3.142

3. This is how we declare a double type variable in Visual Basic statement:


Dim Marks As Double Marks = 60.5

STRING 1. String is any value that contains a sequence of characters. 2. This is how we declare string type constant in Visual Basic statement:
Const Name = AHMAD

3. This is how we declare string type variable in Visual Basic statement:


Dim Address As String Address = Kuala Lumpur

BOOLEAN 6. Boolean type consists either a True or False value. Programmers usually use it to store status. 7. This is how we declare a Boolean type constant in Visual Basic statement:
Const Input_Status = true

3. This is how we declare a Boolean type variable in Visual Basic statement:


Dim Input_Status As Boolean Input_Status = true

14 Form 5 Lesson Notes Part 1 Program & Programming

LESSON NINE : OPERATORS 1. Operator is a symbol or notation that tells a computer to perform certain actions or operations. 2. An example : the plus (+) notation will tell the computer to perform the add operation. 3. There are three types of operator: o Mathematical operator o Relational operator o Logical operator MATHEMATICAL OPERATOR 1. Plus : + 2. Minus : 3. Multiply : * 4. Divide : / RELATIONAL OPERATOR 1. Equal to : = 2. Greater than : > 3. Less than : < 4. Greater than or equal to : >= 5. Less than or equal to : <= LOGICAL OPERATOR 1. AND 2. OR 3. NOT FUNCTION OF MATHEMATICAL OPERATORS Mathematical operators are notations that tell the computer to perform mathematical operations. The program in Visual Basic 6.0 on the right shows an example of a mathematical operation that calculate total marks based on the total marks of section one and section two. The examples declare three variables named TotalMark, SectionOneMark and SectionTwoMark.

15 Form 5 Lesson Notes Part 1 Program & Programming

FUNCTION OF RELATIONAL OPERATORS Relational operators perform comparison between two elements. They return an element of logical 1 (True) where the relation is true, and element of logical 0 (False) where the relation is false. The table shows some common relational operators and their expression.

Example : In this program, A>=B is used to test if the value of left expression (A) is greater than or equal to that of the right expression (B). If the conditions are met, then the program will return a logical 1 and proceed to print A is greater than or equal to B else it will return a logical 0 and proceed to print A is less than B. FUNCTION OF LOGICAL OPERATORS Logical operators are notations that tell the computer to perform logical operations. Example of logical operators are : AND, OR and NOT. Logical operator compares two conditions and return a TRUE or FALSE value.

16 Form 5 Lesson Notes Part 1 Program & Programming

AND operator The diagram shows a truth table of AND operator. Notice that truth value of X AND Y is True if only both X and Y are True (1), Else it is false (0) OR operator The diagram shows a truth table of OR operator. Notice that truth value of X OR Y is True (1) either X or Y are True (1) or both X and Y true (1). Else it is false (0). NOT operator The diagram shows the truth table of NOT operator. NOT X is the negation of X. It is essentially the 1s complement operation. Notice that truth value of NOT X is True (1) when X is False (0) and vice versa. Logical operators perform logical operations such as checking the condition of two Boolean values. if are (1)

17 Form 5 Lesson Notes Part 1 Program & Programming

DIFFERENCE IN MATHEMATICAL, RELATIONAL AND LOGICAL OPERATOR 1. Function Mathematical operators perform mathematical operations such as plus or substract. 2. Symbols These operators have their own symbols based on the programming language. Relational operators perform element-byelement comparison between two arrays. Logical operators perform logical operations such as checking the condition of two Boolean values.

18 Form 5 Lesson Notes Part 1 Program & Programming

LESSON TEN : PSEUDO CODE 1. Pseudo code is text only sentences that describe the logic and program flow of a computer program. 2. Pseudo code resembles plain English. 3. It usually does not have any specific programming language syntax and grammar. 4. Pseudo code is directly linked to the computer codes because each pseudo code statement can often be converted into the programming language virtually line by line. 5. There are no set rules for writing pseudo code. 6. A programmer can have his or her personalized pseudo code. 7. He or she must use consistent language and syntax in the pseudo code, so that he or she can understand it at a later stage. 8. Below is a complete pseudo code from BEGIN to END that illustrates the following program.

19 Form 5 Lesson Notes Part 1 Program & Programming

AN EXAMPLE PROGRAM BASED ON A PSEUDO CODE This program will basically calculate the volume of a sphere based on the given value r.

20 Form 5 Lesson Notes Part 1 Program & Programming

LESSON ELEVEN : FLOW CHART There are five main elements in a flow chart : 1. Terminator shows the beginning or end of a program 2. Flowline and arrowhead use to connect symbols and indicate the sequences of operation. 3. Input or output shows either an input operation (e.g. an INPUT from the user) or an output operation (e.g. PRINT some messages). 4. Process shows a process to be carried out (e.g. calculation). 5. Decision shows a decision (or choice) to be made. The program should continue along one of two routes (e.g. if ..else). A flow chart is a diagram using symbols to show the step-by-step sequence of procedures in a program. A flow chart describes the logic and program flow of a computer system graphically.

EXAMPLE OF A FLOW CHART

21 Form 5 Lesson Notes Part 1 Program & Programming

A student requests his mark from the program. The program will then check whether his mark is more /equal to 50 or not. If the mark is over or equal to 50, the program will print a congratulatory message together with the mark. If the mark is lower than 50, then the program will print a motivational message together with the result.

22 Form 5 Lesson Notes Part 1 Program & Programming

LESSON TWELVE : CONTROL STRUCTURES 1. Control structure is a structure of statements in programming that allows the programmer to control the flow of a program. 2. Control structure can be divided into : (i) sequence control structures (ii) selection control structures (iii) repetition control structures 3. We will concentrate on the sequence control structure and selection control structure. SEQUENCE CONTROL In sequence control, the statements are executed one by one in consecutive order.

Example : This program on the left diagram will request the users

23 Form 5 Lesson Notes Part 1 Program & Programming

date of birth and then request todays date, calculate the age and finally will print the users age. For example, todays date is 1Jan-2006, then the results will shown as follows: Another example of pseudo code and result that has sequence control structure : be

Diagram below shows the flow chart for a general sequence control structure. The flow chart on the left represents a program that will request the users date of birth and then request todays date, calculate the age and finally the users age.

24 Form 5 Lesson Notes Part 1 Program & Programming

SELECTION CONTROL There are times when you want your program to make a decision based on the situation given. A program that stores students marks may respond differently to different marks. For example, a simple mathematical program will display its result as odd or even based on the result.

Selection control enables the programmer to assign different events for different situations. An example of selection control is If..Then.Else statement. The basic pseudo code for If..ThenElse statement is as follows: BEGIN Request condition If condition is true Then give positive response Else give negative response End If End Lets see a pseudo code example for the IfThen..Else statement for a program that will print You are too heavy to ride the toy car if the students weight is more than or equal to 50. Otherwise it will print you can ride the toy car. BEGIN Request students weight If students weight is more than of equal to 50 kg Then

25 Form 5 Lesson Notes Part 1 Program & Programming

Print You are too heavy to ride the toy car. Else Print You can ride the toy car. End If End

Let see a program that will respond differently for different service hours in a school library. A student requests her service hours in a library from the program. The program will then check whether her service hours are more than / equal to 30 or not. If the service hours are over or equal to 30, the program will print a message Thank you for your service. If the service hours are lower than 30, then the program will print a message Please continue to serve in the library. This program will declare a constant pi equal to 3.142. Then the program declares two variables to be used in the program (r and volume) The program will then assign some value to the r variable. The program will then calculate the volume using the formula volume = (4/3) r3 and display the volume calculated with a message box.

26 Form 5 Lesson Notes Part 1 Program & Programming

Write a program that will retrieve the current date from the system. If todays date is more than 15 then the program will display a message box with the message We are towards the end of the month. Else the program will print We are at the beginning of the month. Answer as shown on the right.

DIFFERENCES BETWEEN SELECTION CONTROL AND SEQUENCE CONTROL 1. Execution flow Sequence control executes statement one by one in linear or consecutive order. Selection control will execute different statements for different conditions. 2. Usage Programmers use sequence control if they want to execute the code line by line regardless of the condition. It does not use the decision symbol. Programmers use selection control if they want to implement decision making process in the program as it can execute different codes for different circumstances. It uses the decision symbol. 3. Flow Chart

27 Form 5 Lesson Notes Part 1 Program & Programming

LESSON THIRTEEN : PRGRAM DEVELOPMENT PHASES


In program development, there are five main phases as shown in the diagram on the left.. These phases are a series of steps that programmers undertake to build computer programs. PROBLEM ANALYSIS PHASE o The programmer will interview the client to find out what the clients needs are. o For example, the client might be a school that wishes to set up school registration program. So, the school administrator might tell the programmer they need to record students data such as name, date of birth, gender, class, parents names, addresses and contact numbers. PROGRAM DESIGN PHASE o Based on that, the programmer will design a flow chart that represents the needs of the client, which in this case is the school registration program.

CODING o Once the flow chart is confirmed, the programmer will perform coding.

TESTING AND DEBUGGING PHASE o The school registration program will be tested by the users at the clients site. In this case, it will be the school office administrators. IF there are any errors, the programmer will do a debugging of the program.

DOCUMENTATION PHASE o After this, the programmer will complete the documentation for the program; this includes the user manual, a clear layout of the input and output records and a program listing.

28 Form 5 Lesson Notes Part 1 Program & Programming

LESSON FOURTEEN : PROBLEM ANALYSIS PHASE


In this phase, a programmer must o review and define the problems, o identify the data input, process and output for the program.

1. In this study, the programmer reviews and defines the problems faced by the school administrators : The school enrolment has increased so much that it has become very difficult for them to perform student registration without the help of a computer program or system. 2. The programmer must indicate the purpose of the program before continuing to the next task : In this case, the purpose of the school registration program is to computerize the registration of new students. 3. In this situation, the programmer identifies the data input, process and output for the program : o First step : The programmer identifiers the data input, for example students name, students NRIC, gender, telephone number, date of birth, parents name and address. Second step : The programmer identifies the process for the program. Any new student who enrolls in the school should have all his or her data keyed into the schools registration program. Third step : The programmer identifies the output for the program. For example, the student who has been registered will be notified of his or her class in the coming academic year or term.

LESSON FIFTEEN : PROGRAM DESIGN PHASE

29 Form 5 Lesson Notes Part 1 Program & Programming

In program design, these are three popular tools used, namely o the top-down design model, o pseudo code, o flow chart. In this case study, the programmer generates a top-down design model. This topdown

model consists of three modules, namely input module, process module and output module. Then the programmer writes the pseudo code for the program based on the top-down design model.

Next, the programmer draws the flow chart that shows the data flow of the program.

30 Form 5 Lesson Notes Part 1 Program & Programming

Besides flow chart, a programmer also produces input and output user interfaces base on the existing form.

31 Form 5 Lesson Notes Part 1 Program & Programming

LESSON SIXTEEN : CODING PHASE


1. It is the software that we run on computers which instruct computers what to do. 2. These software contain instructions in the form of special symbolic code, which have been written by computer programmers. 3. The process of writing instructions or code for computers is known as coding. 4. Hence without coding, there would be no software to help us perform useful tasks on computers. 5. In coding phase, a programmer uses a program development tool which generates or provides some or all codes. 6. Coding is the process of writing the solution using the computer programming language. After finishing the coding process, the

programmer will type the programming language code into the computer. 7. There are many different programming languages in the market. Examples of the popular programming language used in Malaysian secondary school are Visual Basic and C language. 8. Each of these programming languages has its own particulars syntax. 9. A programming languages syntax is a set of rules specifying a style of writing instructions for a solution.

32 Form 5 Lesson Notes Part 1 Program & Programming

TO WRITE CODE USING MICROSOFT VISUAL BASIC 6.0 Here is an example which generates Visual Basic code. 1. Select File 2. Select New Project 3. Click Open

33 Form 5 Lesson Notes Part 1 Program & Programming

34 Form 5 Lesson Notes Part 1 Program & Programming

35 Form 5 Lesson Notes Part 1 Program & Programming

CODING USING GUI OF VISUAL BASIC 6.0 Case Study : Student Registration Program 1. Select File 2. Select New Project 3. Single click OK (to choose Standard exe)

36 Form 5 Lesson Notes Part 1 Program & Programming

37 Form 5 Lesson Notes Part 1 Program & Programming

38 Form 5 Lesson Notes Part 1 Program & Programming

LESSON SEVENTEEN : TESTING & DEBUGGING PHASE o If errors are uncovered during testing, the programmer will proceed to
debugging.

o Debugging involves tracing the source of errors in the program and


making the necessary corrections.

o After correcting the errors, it is normal for programmers to test run the
program again just to make sure that the errors have been properly fixed. TESTING & DEBUGGING

o Once the programmer has finished the coding, the next step is to test it. o The Purpose of program testing is to ensure the program runs correctly and
is error-free.

o There are three types of errors uncovered during this phase: syntax errors,
logic errors and run-time errors.

o When the code violates the syntax of the programming language, a syntax
error occurs. SYNTAX ERROR

o A syntax error is caused by wrong spelling in command and declaration.


Other syntax errors include case sensitive, punctuation and wrong word command.

39 Form 5 Lesson Notes Part 1 Program & Programming

o They either show up as you type the program code, or if you have turned
off the automatic syntax error check, the syntax errors show up when you try to run or compile the program.

o o When syntax error is located, a message is displayed on the screen. o The programmer must review and correct all syntax errors.

40 Form 5 Lesson Notes Part 1 Program & Programming

LOGIC ERROR

o If the expected output and actual output do not match for any set of data,
the program has a logic error.

o A logic error is an error in the design that causes inaccurate outputs.

o We can use desk check technique to test logic errors. There are 3 steps to
perform desk checking. a. First, create a set of test data that includes input and output data. b. Second, use the test data to test the coding and record the result. c. Lastly, compare the manual results with the computer generated results.

41 Form 5 Lesson Notes Part 1 Program & Programming

RUN-TIME ERROR

o Run-time error is an error that occurs while the program is running or


executing.

o A run-time error may cause the program to stop running.

DEBUGING

o The process of locating and correcting of syntax and logic errors in a


program is known as debugging the program.

o The program errors themselves are called bugs. Thus removing the errors
is called debugging.

42 Form 5 Lesson Notes Part 1 Program & Programming

LESSON EIGHTEEN : DOCUMENTATION PHASE o Documentation refers to the written description and pseudo code of computer programs.

43 Form 5 Lesson Notes Part 1 Program & Programming

o Although documentation is stated as the last phase in program development, it is actually performed throughout all the five main phases of program development.

o Documentation consists of materials generated during each phase.

o Thus the documentation package is made up of the detailed problem definition, the program plan (flow chart or pseudo code), comments within the source program and testing procedures.

44 Form 5 Lesson Notes Part 1 Program & Programming

o Other items in the documentation package also include a detailed description of the program, clear layouts of input and output records, and a program listing.

45 Form 5 Lesson Notes Part 1 Program & Programming

o The programmer should ensure that all documentation is complete and accurate. o Documentation becomes especially valuable when the program requires changes in the future. o Proper documentation greatly reduces the amount of time a new programmer spends in learning about the existing programs. o Internal documentation consists of comments within the program. o These two types of comments are global comments and internal comments.

o Global comments, usually stated at the top of the program, explain the programs purpose and identify the programs name, its author and the date the program was written.

46 Form 5 Lesson Notes Part 1 Program & Programming

o Internal comments, which appear throughout the body of the program, explain the purpose of the code statements within the program.

o Internal comments are mostly addressed to other programmers who may have to make corrections or other modifications in programming language.

47 Form 5 Lesson Notes Part 1 Program & Programming

LESSON NINETEEN : DEVELOP A PROGRAM o A project is a set of activities with a fixed start date and end date. o Some examples of projects are the construction of your school building
and the setting up of your school library.

o Program development is also a project. o A successful program development project will result in one or more
programs that are error-free, affordable, relevant to the needs of users and delivered on time.

o All the software that you find so helpful, educational and enjoyable today
is the outcome of successful program development projects.

o For a program development project to succeed, the people involved must


possess the appropriate set of communication, management and technical skills. APPLY PROGRAM DEVELOPMEN PHASES TO SOLVE PROBLEMS In library where the number of books is increasing, librarians face problems in registering or cataloguing their books without the help of a computer program. Therefore programmers can help librarians to analyse their requirements and set up the relevant system.

48 Form 5 Lesson Notes Part 1 Program & Programming

49 Form 5 Lesson Notes Part 1 Program & Programming

50 Form 5 Lesson Notes Part 1 Program & Programming

Type miss match

51 Form 5 Lesson Notes Part 1 Program & Programming

52 Form 5 Lesson Notes Part 1 Program & Programming

AN EXAMPLE USING VISUAL BASIC 6.0

53 Form 5 Lesson Notes Part 1 Program & Programming

Click Check

54 Form 5 Lesson Notes Part 1 Program & Programming

LESSON TWENTY : THE LATEST PROGRAMMING LANGUAGE

FIFTH GENERATION LANGUAGES

o Fifth generation programming language (5GL) is an advance programming


language which concentrates on solving problems using constraints given to the program.

o In fifth generation language, the


programmer just need to define the problem to be solved and the program will automatically code the program based on the problem definition.

o Fifth generation languages are


designed to make the computer solve the problem for you.

o Fifth generation languages are mostly used in artificial intelligence


research.

o Examples of fifth generation languages include Prolog and Mercury.


NATURAL LANGUAGE

o Natural Language programming aims to use natural language such as


English to write a program.

o Instead of using a specific programming language syntax, natural language


programming will use normal English as the input to program software.

55 Form 5 Lesson Notes Part 1 Program & Programming

o Such a technique would


mean less technical programming knowledge is required to write a program.

o The programmer needs to


define the program using normal language.

o An example of a tool for


natural language is Metafor created by researchers from the Massachusetts Institute of Technology. OPENGL (GRAPHIC LIBRARY)

o OpenGL is a standard specification to describe the standard Application


Programming Interface (API) for 3D/2D computer graphic applications.

o OpenGL specification declares a set of functions and the exact behaviours


that the 3D/2D application must perform.

o OpenGL was developed by Silicon Graphics. o OpenGL is widely used in virtual reality, scientific visualization, flight
simulation and video game development. 3D / 2D

56 Form 5 Lesson Notes Part 1 Program & Programming

You might also like