Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.

%yS ICT mka;sh


ksiel A idud¾:h

meial,a l%uf,aL NdIdj' /Pascal Programming Language

Array ^wrdj&
tl u m%rEmhg wh;a o;a; tl u kula fhdod .ksñka u;lh ;=< ;eïm;alÍ s ug wrdj Ndú; flf¾' tawkqj
lsishï fmdÿ kulska y÷kajk whs;u(Items) iuQyhla wrdjla(Array) f,i y÷kajkq ,nhs
(An array is used to save data items of the same type in memory using a single variable identifier name.)

……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 1
yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h

……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..

wrdjl ,laIK (Attributes of an Array)


² wrdjl fldgia tkï wjhj$o¾Yl (Elements/Indices) hdnoj msysghs' (Elements of an array are positioned
next to each other. /re adjacently)
² wrdjl o¾Ylh (Index) tkï" wkqms<f s j< wxlh wrdfõ ku iu. fldgq jryka ;=< olajkq ,efí' (The
index of an array (sequential number) is indicated with the array name in square brackets.)

/Array length = 5
taludk wrdj/One dimensional Array
wkql%ñl j ksYaÑ; m%udKhl tl u m%rEmhlg wh;a o;a; ;ekam;a lsÍu i|yd Ndú; lrk o;a; jHqyhls.
(This is a data structure used to save data of the same type sequentially)
taludk wrdjla ks¾udKh lsrSu (Creating an One dimensional Array)

VAR wrdfõ ku : ARRAY[wdrïNl w.h .. wjidk w.h] OF o;a; m%rEmh/Datatype ;

Ex:-
VAR student : ARRAY(0..4) OF STRING;
VAR marks : ARRAY(0..9) OF INTEGER;

m%Yakh 01(-
Student keu;s úYd,;ajh 5 la jk wrdjla(Array) ks¾udKh lr tys uQ,dx.(Eliments) ;=< Samna, Kamal,
Nimal, Ruwan iy Sarath keu;s jpk .nvd lr kej; tajd fmkaùu'

Create an array of size of 5, named “Student” and store the words Saman, Kamal, Nimal, Ruwan and Sarath in
its elements and display those words and write a Pascal programme for above incident.

O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 2


yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h

…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………….
m%Yakh 02(-
isiqka oifofkl=f.a jdr úNd.fha ICT <l=kq ,ndf.k “Thank You” hk mksúvh fmkaùfuka miqj kej;
tu ixLHd oyh ;srfha fmkaùug Pascal l%uf,aLh ,shkak'
Write a Pascal programme to get ICT marks of 10 students and show the message “Thank you” and display
those 10 marks.

……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..

O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 3


yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h

……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
……………………………………………………………………………………………………..
m%Yakh 03(-
isiqka oifofkl=f.a jdr úNd.fha ICT <l=kq ,ndf.k tajdfha tl;=j" idudkHh" jeäu <l=k iy wvqu
<l=k fidhd tajd fmkajk Pascal l%uf,aLhla wrdj(Array) wdOdrfhka ,shkak
Write a Pascal programme with the help of array to get ICT marks of 10 students and find the total marks,
average marks, maximum marks and minimum marks and show them.

PROGRAM ICT_Marks(INPUT,OUTPUT);
USES CRT;
VAR marks : ARRAY [0..9] OF INTEGER;
x,sum,max,min:INTEGER;
av:REAL;
BEGIN
CLRSCR;
max:=0;
min:=100;
FOR x:= 0 TO 9 DO
BEGIN
WRITELN(‘Enter ICT Marks’);
READLN(marks[x]);
sum:=sum+marks[x];
IF marks[x]>max THEN
max:=marks[x];
IF marks[x]<min THEN
min:=marks[x];
END;
CLRSCR;
av:=sum/10;
WRITELN(‘Total marks of all student ’,sum);
WRITELN(‘Average marks of a student’,av:2:2);
WRITELN(‘Maximum marks’,max);
WRITELN(‘Minimu marks’,min);
READLN;
END.
Wml%uf,aL (Sub Programme)
l%uf,aLhl l%shdj,s m%udKh jeäùu;a iu.u th ixlS¾K jk ksid lshjd f;areï .ekSu" l%uf,aLh kv;a;=
lsÍu jeks lghq;= wmyiq fõ' tneúka l%uf,aL ,sùfï § yels;dla ÿrg Wml%uf,aL f,i ,sùu isÿlrkq
,nhs'
As a program becomes complex, when the number of sub processes increase, it will be difficult to
read and understand and also to maintain. Therefore, programs as much as possible while writing
is useful.
O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 4
yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h

Wm .eg¿j 01 Wm l%uf,aLh 01
Sub problem Sub programme 01
01 ………………..

m%Odk Wm .eg¿j 02 Wm l%uf,aLh 02


.eg¿j Sub problem Sub programme 02
Main 02 ………………..
Problem

Wm .eg¿j n Wm l%uf,aLh n
Sub problem n Sub programme n
………………..

Wml%uf,aL j¾. (Types of Sub programmes)

m%Odk l%uf,aLh yd iïnkaO Wml%uf,aL u.ska m%Odk l%uf,aLh fj; m%;sodkhla wdmiq ,nd §ug yels iy
fkdyels jYfhka Wml%uf,aL j¾. folla we;' m%;o s dkhla wdmiq ,nd Èh yels Wml%uf,aL Y%s; ^Function&
f,i o" m%;o s dkhla wdmiq ,nd Èh fkdyels Wml%uf,aL ld¾h mámdáh ^Procedure& f,i o ye¢kafõ'
(There are two types of sub programs in addition to the main program. A sub program which returns an output
back to the main program and a sub program which does not return an output back to the main program. A sub
program which returns an output back is called a Function and a sub program which does not give an output is
called a Procedure.)

Wml%uf,aL y÷kajd§u/Introducing the Sub programme

PROGRAM
CONST
VAR
Wml%uf,aLh/Sub programme

BEGIN
m%Odk l%uf,aLh ;=,oS Wm l%uf,aLh weu;Su
Calling the sub programme
END.

ld¾h mámdáh ^Procedure&


PROCEDURE ld¾h mámdáfha ku (VAR úp,H ( o;a; m%rEmh/DATA TYPE);

BEGIN
ld¾h mámdáfha wvx.= m%ldYk 1/Statement 1;
ld¾h mámdáfha wvx.= m%ldYk 2/Statement 2;
:
ld¾h mámdáfha wvx.= m%ldYk n/Statement n;
END;

O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 5


yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h

Y%s;h ^Function&

FUNCTION Y%s;fha ku (VAR úp,H ( o;a; m%rEmh ):Y%s;fha o;a; m%rEmh/DATA TYPE of function ;

BEGIN
Y%s;fha wvx.= m%ldYk 1/Statement 1;
Y%s;fha wvx.= m%ldYk 2/Statement 2;
:
Y%s;fha wvx.= m%ldYk n/Statement n;
END ;

m%Yakh 01(-
jD;hl wrh ,ndf.k j.–M,h fidhd th fmkajk Pascal l%uf,aLkh ,shkak
Write a Pascal programme that shows the Area when the Radius of a circle is given

PROGRAM Circle(INPUT,OUTPUT);
USES CRT;
CONST pie:=22/7;
VAR r:INTEGER;
cho:STRING;

PROCEDURE get_data(VAR r:INTEGER);


BEGIN
WRITELN(‘Enter Radius’);
READLN(r);
END;

PROCEDURE area(VAR r:INTEGER);


VAR a:REAL;
BEGIN
a:=pie*r*r;
WRITELN(‘Area = ‘,a:2:2);
END;

BEGIN
TEXTCOLOR(YELLOW);
REPEAT
get_data(r);
area(r);
WRITELN(‘Do you want to run this again? For YES press Y and NO press N’);
READLN(cho);
UNTIL((cho <> ‘y’) AND (cho <> ‘Y’));
END.

O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 6


yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h
m%Yakh 02(-
by; .eg¿j Function Ndú;fhka úioSu/Solving the above problem using Functions

PROGRAM Circle(INPUT,OUTPUT);
USES CRT;
CONST pie:=22/7;
VAR r:INTEGER;

PROCEDURE get_data(VAR r:INTEGER);


BEGIN
WRITELN(‘Enter Radius’);
READLN(r);
END;

FUNCTION area(VAR r:INTEGER):REAL;


VAR a:REAL;
BEGIN
a:=pie*r*r;
area:=a;
END;
BEGIN
TEXTBACKGROUND(RED);
get_data(r);
WRITELN(‘Area = ‘, area(r):2:2);
END.
mervhsu (Paradigms)
l%uf,aLk l%shdj,shg m%fõY ùu ms‚i úl,am m%fõY .Kkdjla we;' tAjd l%uf,aLk mervhsu (Paradigms)
f,i ye¢kafõ'
(There are many different approaches to computer programming. These are called programming paradigms.)
mervhsu
(Paradigms)

úOdkd;aul m%ldYk
(Imperative) (Declarative)

mámdá.; jia;= keUqre iudka;r.; ;d¾lsl Y%s;uh o;a; o;a; .nvd


(Procedural) (Object ieleiau (Logical) .e,Sï (Data Base)
Oriented) (Parallel (Functional
Processing) Data Flow)

C Java Java Prolog Lips SQL

O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 7


yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h

mámdá.; (Procedural) yd m%ldYk (Declarative) l%uf,aL (Programme) w;r fjki


Difference between procedural and declarative paradigms

mámdá.; l%uf,aL (Procedural Programme)


mámdá.; NdIdjla hkq b;d fyd¢ka jHqy.; jQ mshjr ud,djlska iy mámdáj,ska (Procedural) iukaú;
mß.Kl l%uf,aLk NdId j¾.hls' tys l%uj;a mshjrj,ska iukaú; m%ldYk (Statements) wvx.= fõ‘
(A procedural language is a computer programming language which consists of a well-structured set of steps
and procedures.)
Eg:- Pascal
m%ldYk l%uf,aL (Declarative Programme)
m%ldYk l%uf,aLhla hkq md,k .e,Su úia;r lsÍulska f;drj" .Kkh lsÍfï ;d¾lsl kHdh úoyd olajk"
mß.Kl l%uf,aLj, jHqyh iy wjhj f.dvkxjk wdldrhls‘'
(A declarative paradigm develops a structure and elements of computer program by indicating calculations
and/or logic without a control flow.)
Eg Visual Basic

jHQy.; (Structured) iy jia;= keUqre (Object oriented) l%uf,aL (Programme)


(Comparison of structured and object oriented paradigms)

jHQy.; l%uf,aL (Structured Programme) :-


jHqy.; l%uf,aL hkq ;d¾lsl l%uf,aLk mervhsuhla jk w;r th jia;= keUqre l%uf,aLj, mq¾j
wjia:djls' jHqy.; l%uf,aL mervhsu u.ska l%uf,aLh f;areï .ekSu iy kùlrKh i|yd myiqlï
i,ihs' by< isg my<g (Top - down) m%fõY we;'
(A structured program is a logic based paradigm and it is the pre discussed object oriented program. A
structured programming paradigm provides facilities to understand and modify the program. The system is
divided into sub systems and there is a top – down flow in it.)

jHqy.; l%uf,aL/Structured Program

mrsYS,lhdg o;a; we;=,;a lrk f,i oekqï fohs/ (Informs the user to enter data)

mrsYS,lhd we;=,;a l< o;a; ,nd.kS/ (Retrieves data entered by the user)

o;a; l%h
s dj,shg Ndckh lrhs (Data is processed)

mrsYS,lhdg m%;sM,h ,ndfohs (User is given the output)

jia;= keUqre l%uf,aL (Object oriented Programme)

jia;= keUqre mß.Kl l%uf,aL hkq jia;= (Objects) hk ixl,amh u; mokï jQ l%uf,aL mervhsu fõ'
(Object oriented programming is a programming paradigm based on the concept of objects.)

O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 8


yhjk jrg;a" ICT jxYl:dj rkska ,shQ" Y%S ,xldfõ wxl tfla" úch.%yS ICT mka;sh
ksiel A idud¾:h

l%uf,aLkh iy msgm;a f,aLkh (Programming and Scripting)

l%uf,aLk NdIdj, idudkHfhka mo fhdackh (Syntax) iïnkaOfhka ±ä kS;s Í;s mj;S' ks;r u mdfya
iïmdokh lsÍu wjYH fõ' l%uf,aL NdId iïmdokh (Compile) l< hq;= fõ. msgm;a f,aLk NdId
idudkHfhka fjk;a fhojqula
^WÞ - fjí n%jqirhla fyda fjí i¾jrhla& iu. fndfyda úg l%h s d;aul jk fla;hla ksIm
a dokh flf¾'
tfuka u msgm;a f,aLk NdId w¾: úkHdY (Interprit) l< hq;= h' kjlhkaf.ka w;sYh nyq;rhla msgm;a
rpk NdIdj Ndú; lsÍu jvd myiq hehs is;;s'

(Usually, there are hard and fast syntax rules in programming languages. These should often be compiled.
Programming languages need to be compiled. Further, scripting languages should be interpreted.)

Eg:- Java Script


PHP
VB Script

10 fY%aKsh-2022 (2023 OL) # ICT


Online mka;s ld, igyk
^isxy, iy bx.%Sis udOH&

www.apexonline.lk (0702229555)
m<uq lKavdhu
foie' 02 n%yiam;skaod iji 5'00-07'00
fojk lKavdhu
foie' 04 fikiqrdod rd;%S 8'30 - 10'30
f;jk lKavdhu
foie' 05 brsod rd;%S 8'30 - 10'30
-------------------------------------------------------------
www.surathaonline.lk (0412233169)
m<uq lKavdhu
foie' 01 nodod iji 05'00 - 07'00
fojk lKavdhu
foie' 06 i÷od rd;%S 8'30 - 10'30
-------------------------------------------------------------
www.dakunaonline.com (0779143001)
m<uq lKavdhu
foie' 04 fikiqrdod iji 05'00 - 07'00
fojk lKavdhu
foie' 05 brsod iji 03'30 - 05'30

jeo.;a(-
by; Online ICT mka;s 2023 i'fm< úNd.h olajd
wLKavj l%shd;aul fõ'

O/L ICT ICT - A Wreufha woaú;Sh kduh - l=i,a weye,wdrÉÑ Page 9

You might also like