Вы находитесь на странице: 1из 18

Lecture 2

Program:

A set of step-by-step instructions that directs a computer to perform a specific task and to produce the required results. Programming is a process of designing/ creating a program. Programmer is a person who writes the program.

Programming:

Programmer:

A set of rules and reserved words (keywords) that can be used to tell a computer what are the operations to be done. Artificial language composed by a fixed vocabulary and set of rules is used to create instructions for the computer to follow. Now, there are over 200 programming languages in the world. For example: Cobol, Pascal, C, C++, and Fortran.

How Human Interact:

Example: People communicate using human languages, such as Bahasa Melayu, English and Japanese.
Interaction

HUMAN LANGUAGE (BAHASA MELAYU)

How Human and Computer Interact:

People communicate with computers using programming languages such as C, C++ and Cobol.
Interaction

PROGRAMMING LANGUAGE (C, C++, COBOL)

#include <stdio.h> #include <conio.h>

main() { int a,b,c; /* hold variables value*/ int sum; /* variable to hold total (a+b+c) */

float avg; /* variable output*/ clrscr();

printf (Input three numbers:); /* ask user to enter 3 numbers */ scanf (%d %d %d, &a, &b, &c); sum = a+b+c; /* calculate total of a, b and c*/

avg = sum / 3; /* calculate average*/

printf (Average of the numbers: %.2f, avg); }

/* Display the average */

Executable program: program that can operate a computer Executable programs are written with binary numbers, which is a computers internal language (machine language)
An example of a simple machine language program containing two instructions is:
11000000000000000001000000000010 11110000000000000010000000000011

Opcode is short for operation code; tells the computer the operation to be performed.

Assembly language: uses the substitution of wordlike symbols for the opcodes, and decimal numbers and labels for memory addresses
LOAD first ADD second MUL factor STORE answer

Machine and assembly languages are low-level languages because they both use instructions that are directly tied to one type of computer. Programs written in a computer language are referred to as source programs and source code.
When each statement in a high-level source program is translated individually and executed immediately upon translation, the programming language is called an interpreted language. Interpreter: program that translates each statement in a high-level source program and executes it immediately upon translation.

Compiled language: the statements in a high-level source program are translated as a complete unit before any individual statement is executed. Compiler: translates a high-level source program as a complete unit before any statement is executed The output produced by the compiler is called an object program (machine language version of the source code).
Linker: combines additional machine language code with the object program to create a final executable program

A fourth-generation programming language (or 4GL) is a programming language designed with a specific purpose in mind such as the development of commercial business software

A translator is a program that:


Checks syntax of a program to ensure the programming language is used correctly, by giving you the syntax-error messages, which is known as diagnostics. Translates a program into language that the computer can understand. Produces descriptive error messages known as syntax-error to programmer if there are errors in the programs.

Syntax set of rules to be followed when writing a program, these rules are similar to the grammatical rules in English. Example: Message displayed on the screen is please enter a number. C Language: printf(please enter a number);

Syntax Error error in the use of a programming language. Example in C: Statement: clrscr() If semicolon (;) is not placed after statement, a message will display: Error DIT103.CPP: Declaration syntax- error The correct syntax is: clrscr();

Assembler
Translates the whole program at one time. Also called assembler program. A program, which is used to convert assembly language to machine language.
sseg sseg segment stack db 256 dup (?) ends 11101 11110 10111000 11101000 11111100 10111000 10001110 10111000 10001110 100000 100000

dseg segment data db 2 x 4 = dseg ends cseg segment assume cs:cseg:ds:sdeg:ss:sseg. es:nothing proc far Start

Assembler

11011000

11000000

Assembly Language

Machine Language

Compiler
Translate the whole program at one time. Translates the source code, for example COBOL language to machine language. Used to translate C, COBOL and other language.
# include <stdio.h> main( ) { int x, y, z, sum; double avg;

11101 11110 10111000 11101000 11111100 10111000 10001110 10111000 10001110

100000 100000

printf(" Enter 3 numbers:"); scanf("%d %d %d",&x, &y, &z); sum = x + y + z; avg = sum / 3; printf("x = %d y = %d z = %d ", x, y, z); printf("the average is = %f",avg); return 0; }

Compiler

11011000 11000000

Machine Langeage C Language

Interpreter
Program that translates a high level language to machine language. It translates one line at a time and executes each line after it is translated. Displays feedback as the error occurred. Used to translate BASIC and SQL language.
BASIC PROGRAM AVERAGING THREE INTEGERS PRINT Mengira Purata PRINT --------------------- PRINT Nilai A = ; 20 PRINT Nilai B = ; 30 PRINT Nilai C = ; 40 PRINT Purata tiga nombor ialah ; (20+30+40)/3 END
10001110 10111010 10111011 10001101 10111111 10110000 10110011 11100011 00001110 10100000 10111001 10100100 11000000

110110
000000010 000001000 111111000 110000

Interperter

Basic Language

Machine Language

Accuracy
Program that fulfils all the specifications, requirements and objectives. For example: ATM machine. When a user withdraws RM200, the user will get RM200 in cash. To ensure accuracy, programmer needs to define a control to prevent invalid value.

Reliability
No errors. Produces output as required. Information is reliable if the user can depends on its accuracy and completeness. Example: the balance in Touch N Go card.

Usability
Easy to use and learn. Programmer or non-programmer can use the interaction. Example, LRT-STAR machine (ticket) can be used by anyone.

4. Maintainability
A program that is easily understood, tested and modified without having to change the whole program. The program may be changed by any programmers at anytime to fulfil the current requirement. Example: Total digit of telephone number can be changed from 7 to 8 digits without changing the existing application program.

Efficiency
Fast program execution and quick access to data to generate output. Example: Tickets System in LRT-STAR System.

Readability
A readability program is: A clear and understandable program. Using meaningful name for variables. Have explanations on the programs function. Instruction is written by using spacing in between words.

Вам также может понравиться