Upload
muhammad-hazwan
View
219
Download
0
Embed Size (px)
Citation preview
7/31/2019 Understand Programming Languages
1/18
7/31/2019 Understand Programming Languages
2/18
Program: A set of step-by-step instructions that directs a
computer to perform a specific task and to producethe required results.
Programming: Programming is a process of designing/ creating a
program.
Programmer: Programmer is a person who writes the program.
7/31/2019 Understand Programming Languages
3/18
A set of rules and reserved words (keywords) that
can be used to tell a computer what are theoperations to be done.
Artificial language composed by a fixed vocabularyand set of rules is used to create instructions for thecomputer to follow.
Now, there are over 200 programming languages inthe world. For example: Cobol, Pascal, C, C++, andFortran.
7/31/2019 Understand Programming Languages
4/18
Example: People communicate using human languages, such asBahasa Melayu, English and Japanese.
Interaction
HUMAN LANGUAGE (BAHASA MELAYU)
People communicate with computers using programming languagessuch as C, C++ and Cobol.
PROGRAMMING LANGUAGE (C, C++, COBOL)
Interaction
7/31/2019 Understand Programming Languages
5/18
#include
#include
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 */
}
7/31/2019 Understand Programming Languages
6/18
Executable program: program that can operate acomputer
Executable programs are written with binarynumbers, 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 thecomputer the operation to be performed.
7/31/2019 Understand Programming Languages
7/18
Assembly language: uses the substitution of word-
like symbols for the opcodes, and decimal numbers
and labels for memory addressesLOAD first
ADD second
MUL factor
STORE answer
7/31/2019 Understand Programming Languages
8/18
Machine and assembly languages are low-level languages becausethey both use instructions that are directly tied to one type ofcomputer.
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 translatedindividually and executed immediately upon translation, theprogramming language is called an interpreted language.
Interpreter: program that translates each statement in a high-levelsource program and executes it immediately upon translation.
7/31/2019 Understand Programming Languages
9/18
Compiled language: the statements in a high-levelsource program are translated as a complete unitbefore any individual statement is executed.
Compiler: translates a high-level source program as acomplete unit before any statement is executed The output produced by the compiler is called an
object program (machine language version of thesource code).
Linker: combines additional machine language codewith the object program to create a final executableprogram
7/31/2019 Understand Programming Languages
10/18
A fourth-generation programming language(or 4GL) is a programming language designedwith a specific purpose in mind such as thedevelopment of commercial business
software
7/31/2019 Understand Programming Languages
11/18
A translator is a program that:
Checks syntax of a program to ensure theprogramming language is used correctly, by givingyou the syntax-error messages, which is known asdiagnostics.
Translates a program into language that thecomputer can understand.
Produces descriptive error messages known assyntax-error to programmer if there are errors inthe programs.
7/31/2019 Understand Programming Languages
12/18
Syntax set of rules to be followedwhen 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 aprogramming 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();
7/31/2019 Understand Programming Languages
13/18
Translates the whole program at one time.
Also called assembler program.
A program, which is used to convert assembly language tomachine language.
sseg segment stackdb 256 dup (?)
sseg ends
dseg segmentdata db 2 x 4 = dseg endscseg segment
assume cs:cseg:ds:sdeg:ss:sseg.es:nothingStart
Assembler
Assembly Language Machine Language
11101 100000100000
111101011100011101000111111001011100010001110 11011000
1011100010001110 11000000
proc far
7/31/2019 Understand Programming Languages
14/18
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
main( )
{
int x, y, z, sum;double avg;
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;}
11101 100000
100000
1111010111000
11101000
11111100
10111000
10001110 11011000
10111000
10001110 11000000
Compiler
C Language
Machine Langeage
7/31/2019 Understand Programming Languages
15/18
Program that translates a high level language to machine
language.
It translates one line at a time and executes each line afterit is translated.
Displays feedback as the error occurred.
Used to translate BASIC and SQL language.
10001110 11000000
10111010
10111011
10001101 110110
10111111
10110000 000000010
10110011 000001000
11100011 111111000
00001110 110000
1010000010111001
10100100
Interperter
Basic Language Machine Language
BASIC PROGRAMAVERAGING 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
7/31/2019 Understand Programming Languages
16/18
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 controlto prevent invalid value.
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.
7/31/2019 Understand Programming Languages
17/18
Easy to use and learn. Programmer or non-programmer can
use the interaction.
Example, LRT-STAR machine (ticket) can be used byanyone.
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 fulfilthe current requirement.
Example: Total digit of telephone number can be changedfrom 7 to 8 digits without changing the existing applicationprogram.
7/31/2019 Understand Programming Languages
18/18
Fast program execution and quick access to data to
generate output.
Example: Tickets System in LRT-STAR System.
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.