Uploaded by Dan De Dosan

toprint

advertisement
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
.eg¨jla úi£ug l%uf,aLhla ,sùu (01)
Developing a Programme to solve a problem (Programming)
Introduction to Programming Languages
^mrs.Kl NdId ye|skaùu&
The purpose of a language is to allow people to communicate. Unfortunately computer at present are not
intelligent enough to understand human language, because of this scientist have developed computer friendly
languages. Using such a computer language you can communicate with computer. More specifically you could
instruct the computer to perform a particular task.
NdIdjl ld¾HNdrh jkafka ñksidg ikakf
s õokh lsrSug wjia:dj ,ndoSuhs' wjdikdjlg j¾:udkfha we;s
mrs.Kl" udkj NdId f;areï .ekSug ;rï nqoaêfhka m%udKj;a fkdfõ' thg fya;=j mrs.Kl úoHd{hska
úiska mrs.lhg ñ;%YS,Sa NdId ks¾udKh lsrSuhs' fujeks NdIdjla Ndú;fhka Tng mrs.Klhg Wmfoia
,ndoshyel
What is a computer Language? ^mrs.Kl NdIdjla hkq l=ulao@&
A computer language is a set of symbols and rules used in constructing programs.
mrs.Kl jevigykla ilialrSu i|yd we;s kS;s iy ixfla; j, tl;=jla mrs.Kl NdIdjla fõ
Generation of programming languages ^mrs.Kl NdId hq.&




1st Generation language (1GL) ^m<uq hq.fha mrs.Kl NdId&
2nd Generation languages (2GL) ^fojk hq.fha mrs.Kl NdId&
3rd Generation languages (3GL) ^f;jk hq.fha mrs.Kl NdId&
4th Generation languages (4GL) ^isõjk hq.fha mrs.Kl NdId&
1st Generation languages (1GL) ^m<uq hq.fha mrs.Kl NdId&
 All commands are based on binary codes symbols 0 and 1
^ish,qu úOdk 0 iy 1 hk oaùuh fla; l%uh u.ska mokï úhhq;=h hq;=h&
 Machine level programming language ^mrs.Kl hka;%h uÜgfïu NdIdjls&
 The machine can directly execute the machine code ^hdka;%l
s NdIdj mrs.Klhg >Dcqj l%shd;aul l,
yel&
 Execution is speedy because no translators are used.^mrsj¾:lhska fkdue;s ksid hula isÿùu
fõ.j;ah&
 It is very difficult to write and modify programs.^jevigykla ,sùu yd w,q;alr
s Su ÿIalr ld¾Hhls&
 It is machine dependant language ^mrs.Kl hka;%h u; mokï jQ NdIdjls&
 It is a low level language ^my, fmf,a mrs.Kl NdIdjls&
EX: Machine Language (hdka;%l
s NdIdj )
2nd Generation languages (2GL) ^fojk hq.fha mrs.Kl NdId&
 Assembly language is used ^Assembly keu;s mrs.Kl NdIdj Ndú; lrk ,oS&
 Assembler is used to convert assembly language into machine language (wefiïí,s NdIdj hdka;%l
s
NdIdj njg yerùug wefiïí,¾ (Assembler) keu;s mrsj¾:lhd Ndú; lrk ,oS&
O/L ICT
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 1
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
 Mnemonics and variables are used to write codes ^fla; ,sùug Mnemonics iy úp,Hka Ndú; lrk
,oS&
 It is a machine dependant language ^mrs.Kl hka;%h u; mokï jQ NdIdjls&
 Difficult to write and modify programs ^jevigykla ,sùu yd w,q;l
a r
s Su ÿIalr ld¾Hhls&
 It is a low level language ^my, fmf,a mrs.Kl NdIdjls&
 Execution is fast ^hula isÿjk fõ.h jeäh&
EX: Assembly Language (wefiïí,s NdIdj)
3rd Generation languages (3GL) ^f;jk hq.fha mrs.Kl NdId&
 It is easy to understand, because it is similar to human languages ^udkj NdIdjkag iudk ksid
f;areï.ekSug myiqh&
 Compilers or interpreters are used as translators. ^iïmdol (Compilers) iy w¾;úkHdil (interpreters)
keu;s mrsj¾:lfhda Ndú; lrk ,oS&
 It is easy write and modify programs.^jevigykla ,sùu yd w,q;alr
s Su b;d myiq ld¾Hhls&
 They are not machine dependent languages ^mrs.Kl hka;%h u; mokï fkdjQ NdIdjfõ&
 It is a High level language ^by, fmf,a mrs.Kl NdIdjls&
 Some of the 3rd generation languages are unstructured languages such as Basic ^BASIC jeks NdIdjka
wdlD;s rys; tajd fõ&
Ex: BASIC, FORTRAN, COBOL, Pascal, Java, C++, Visual Basic, Python
4th Generation languages (4GL) ^isõjk hq.fha mrs.Kl NdId& (Artificial Language $lD;Su nqoaêh iys;
NdId)
 Artificial Intelligence is used in these languages ^fuu mrs.Kl NdId lD;Su nqoaêh Ndú;lrhs&
 It consumes less time to write a program ^jevigykla ,sùug wvq ld,hla jehfõ&
 Very easy to write and modify .^jevigykla ,sùu yd w,q;alsrSu b;d myiq ld¾Hhls&
 It is a High level language ^by, fmf,a mrs.Kl NdIdjls&
EX: Prolog, LISP
Classification of Programming Languages ^mrs.KlNdId j¾.Slrkh&
1
Low Level Languages ^my, fmf,a mrs.Kl NdId&
First and second generation languages are considered low level languages. ^m<uq iy fojk hq.fha NdId
fuu j¾.hg wh;afõ&
EX: Machine Language (hdka;%l
s NdIdj )
Assembly Language (wefiïí,s NdIdj )
2
High Level Languages ^by, fmf,a mrs.Kl NdId&
 3GL and 4GL are considered high level languages ^f;jk iy isõjk hq.fha NdId fuu j¾.hg
wh;afõ&
EX: BASIC, FORTRAN, COBOL, Pascal, Java, FOCUS, IDEAL, dbase III plus, Visual basic, C++,
Small Talk, Visual.net, Prolog, LISP
O/L ICT
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 2
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
Language Translator ^NdId mrsj¾;lhd&
Translators are used to convert source code into machine (object) code. These are three types of translators
m%Nj fla;h ^wm úiska mrs.Kl NdIdjla wdOdrfhka ,shk fla;h ^Source Code) hdka;%l
s NdIdj (Machine
Language) njg yerùug mrsj¾:lhska Ndú; lrkq ,nhs'
mrsj¾;lhska m%Odk j¾. ;=kla fõ
1.
Assembler (wefiïí,¾)
2.
Compiler (iïmdol)
3.
Interpreter (w¾;úkHdil)
Source Code/m%Nj fla;h
Translator
^mrs.Kl NdIdj
wdOdrfhka wm ,shk
fla;h&
mrsj¾;lhd
Machine Language/hdka;%l
s
NdIdj
Machine Code/Object Code
jia;= fla;h
Assembler (wefiïí,¾)
 It is a low-level language Translator. ^my, fmf,a mrsj¾:lfhls&
 It is a software program that converts assembly language into machine language. ^wefiïí,s NdIdj
hdka;%l
s NdIdj njg yerùug fuu jevigyk Ndú; lrk ,oS&
 Converts Mnemonics into machine code (Mnemonics hdka;%l
s NdIdjg yrjhs&
EX: Assembly language (wefiïí,s NdIdj)
Compiler (iïmdol)
 It is a translator of high level languages ^by, fmf,a mrsj¾:lfhls&
 Converts a whole program into machine language at once ^m%Nj fla;h ^wm úiska ,shk fla;h&
hdka;%l
s NdIdj njg tljr mrsj¾;kh lrhs&
EX: Pascal, Visual Basic
Interpreter (w¾;úkHdil)
 It is a translator of high level languages ^by, fmf,a mrsj¾:lfhls&
 Translate source code into machine code line by line ^m%Nj fla;h ^wm úiska ,shk fla;h& hdka;%sl
NdIdj njg fma,sfhka fma,sh mrsj¾;kh lrhs$jrlg tla fma,shla ne.ska mrsj¾;kh lrhs&
EX: Python
Solving Problems ^.eg¿ úioSu&
Steps of solving a problem ^.eg¿jla úioSfï mshjr&
1
Understanding the problem/Analysing the problem
^.eg¿j y÷kd.ekSu$.eg¿j úYaf,aIKh&
2
Developing an Algorithm for the problem
^.eg¿j i|yd we,af.drs;uhla f.dvke.Su&
O/L ICT
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 3
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
3
Cording Programme ^mrs.Kl NdIdjla wdOdrfhka fla; lsrSu&
4
Testing and debugging ^mrSCIdjg ,lalr
s Su yd jeros ksjeros lsrSu&
5
Execute the programme on the input data ^jevigyk wdodk o;a;u; l%h
s d;aul lsrSu&
(01) .eg¿j y÷kd.ekSu$.eg¿j úYaf,aIKh
(Understanding the problem/Analysing the problem)
.eg¨jla úi£u i|yd fhdod.kakd wuqøjH wdodk ^Input& f,i ye¢kafõ' th úi£fuka ,nd .kakd
m%;M
s ,h" m%;sodkh ^Output& f,i ye¢kafõ' wdodk" m%;sodk njg m;alÍ
s u" l%h
s dj,sh fyj;a ieliSu
^Process& f,i ye¢kafõ' l%h
s dj,shla mshjfrka mshjr isÿ jk w;r tajd wkqms<f
s j<lska oelaùu b;d
jeo.;afõ' .eg¨jla úYaf,aIKh lsÍfï § tys wdodk" l%shdj,sh yd m%;sodk fjka fjka j y÷kd .kq ,nhs'
The raw materials that are used to solve a problem are known as the 'input'. The result obtained after solving a
problem is known as the 'output'. Converting input to output is called the 'process'. A process takes place step
by step and it is very important to understand the order of process. When analyzing a problem, the input,
processing and output are identified separately.
.eg¨j
( ;eme,a lsÍug iqÿiq ,smshla iE§u
wdodk
( ,smsh ,sùug iqÿiq fld<hla" mEkla" ,shqï ljrhla" uqoaor iy ue,shï
l%h
s dj,sh ( 1' ,smsh ,sùu
2' ,smsh kjd ,shqï ljrhg nyd ,Su
3' ,shqï ljrh we,ùu
4' hd hq;= ,smskh ,shqï ljrfha ,sùu
5' uqoaor we,ùu
m%;o
s dkh
( ;eme,a lsÍug iqÿiq ;;a;j
a fha mj;sk ,smshla
igyk
( fuu l%shdj,sfha mshjr wxl 4 iy 5 yqjudre lr isÿ l< yels h' tfy;a wfkl=;a mshjr
wkqms<sfj<ska u isÿ l< hq;= fõ'
Problem
: Preparing a letter which can be posted.
Input
: A sheet of paper, suitable to write the letter on, a pen, an envelope, a stamp and Glue
Process
1. Writing the letter
2. Folding the letter and putting it into the envelope
3. Pasting the envelope
4. Writing the recipient's address on the envelope
5. Sticking the stamp
Output
: A letter ready to be posted.
Note
: Steps No. 4 and 5 in this process can be interchanged. However, the other steps should be
followed in the order indicated.
O/L ICT
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 4
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
.eg¨j ( ixLHdjla T;af;a o brÜfÜ o hkak fiùu
wdodkh
( ixLHdj
l%h
s dj,sh ( ixLHdj foflka fnod fYaIh ^b;srsh& fiùu
fYaIh } 0 kï brÜfÜ ixLHdjla nj ;SrKh lsÍu
fYaIh } 1 kï T;af;a ixLHdjla nj ;SrKh lsÍu
m%;o
s dkh ( ixLHdj T;af;a fyda brÜfÜ nj oelaùu
Problem
: Finding whether a number is odd or even
Input
: Number
Process
: Dividing the number by 2
Deciding that the number is even if the remainder = 0
Deciding that the number is odd if the remainder = 1
Output
: Indicating whether the number is odd or even
úl,am úi÷ï y÷kd.ekSu
(Identifying the alternative solutions?)
.eg¨jla i|yd úi÷ï tllg jvd jeäfhka mj;S kï tajd úl,am úi÷ï f,i ye¢kafõ' fuh .eg¨fõ
iajNdjh u; ;SrKh jkakls'
If there is more than one solution to a given problem such solutions are called alternative solutions. Such
solutions depend on the nature of the problem.
ksoiqk 1
Tn mdi,g meñfKkafka mdi,a nihlska hehs is;kak' mdi,g meñfKñka isák úg nia r:fha fodaIhla
ksid w;ru. kej;=‚ kï Tng mdi, fj; meñKSug yels fjk;a l%u .ek is;kjd fka o@ fufia Tn
is;kafka mdi, fj; hdug yels fjk;a úl,am úi÷ï h'
1' mdi,g tk fjk;a mdi,a nia r:hlska mdi, fj; meñKSu
2' Tn <Õ uqo,a we;s kï ,x.u fyda fm!oa.,sl nia r:hlska mdi, fj; meñKSu
3' mdr Èf.a mhska u .uka lr mdi, fj; meñKSu
4' flá ud¾.hlska mhska .uka lr mdi, fj; meñKSu
5' foujqmshkag fï nj oekaúh yels kï Tjqkaf.a iydh we;s j mdi, fj; meñKSu
6' úYajdijka; wfhl=f.a iydh we;s j fudag¾ r:hlska fyda fudag¾ ihsl,hlska mdi, fj; meñKSu
tÈk wksjd¾hfhka u mdi,g meñKSug wjYH Èkhla kï fuu úl,am úi÷ï w;ßka fyd| úi÷ula f;dard
.;hq;=h' ta wkqj hï .eg¨jlg úi÷ï iuQyhla ^l=,lhla& mj;S kï ta ms<sn| j i,ld n,d fyd|
úi÷ula f;dard .ekSu jvd;a WÑ; fõ' fufia .eg¨jlg mj;sk ish¨ úi÷ï" úi÷ï wjldYh (Solution
Space) f,i ye¢kafõ' mß.Kl l%u f,aLkfha § o úúO úi÷ï y÷kdf.k fyd| u úi÷u f;dard .ekSu
l< hq;= h' túg ir, flá l%uf,aLkhla ks¾udKh lsÍug yels fõ'
O/L ICT
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 5
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
All the solutions pertaining to a problem are called solution space. In computer programming also, various
solutions should be identified and an appropriate solution should be selected. Then we can create a short,
simple programme.
ksoiqk 2
RcqfldaKdi%hl mßñ;sh fiùug we;s úi÷ï wjldYh fidhd n,uq' fuu .eg¨jg wod< wdodk" m%;sodk
iy ieliSu úYaf,aIKh fldg olajuq'
wdodk
ieliSu
m%;o
s dk
( RcqfldaKdi%fha È. yd m<,
( mßñ;sh .Kkh lsÍu
( mßñ;sh
mßñ;sh .Kkh lsÍu i|yd úi÷ï wjldYh fidhuq'
1 jk úi÷u' mßñ;sh } È. ¬ m<, ¬ È. ¬ m<,
2 jk úi÷u' mßñ;sh } ^È. x 2& ¬ ^m<, x 2&
3 jk úi÷u' mßñ;sh } ^È. ¬ m<,& x2
fuu úi÷ï w;ßka tl;= lsÍu ms<n
s | j muKla wjfndaOhla we;s wfhl=g fyd| u úi÷u f,i 1 jk
úi÷u f;dard .; yels h' .=K lsÍu yd tl;= lsÍu ms<sn| j wjfndaOhla we;s wfhl=g fyd| u úi÷u
f,i 3 jk úi÷u f;dard .; yels h' thg fya;=j tl;= lsÍfï yd .=K lsÍfï ldrl wju m%udKhla
mj;sk neúks'
ksoiqka 3
YsIHhl= f;dr;=re yd ikakf
s õok ;dlaIK úIhh i|yd ,nd .;a ,l=Kq ixLHdj 35g wvq kï Tyq wiu;a
nj fyda 35 fyda Bg jeä kï Tyq iu;a nj o oelaùu
wdodk
( ,l=Kq ixLHdj
ieliSu
( ,nd we;s ,l=Kq m%udKh 35 iu. iei£u
úi÷u 1'
,l=Kq 35g wvq kï
m%;M
s ,h
} wiu;a
tfia fkdfõ kï
m%;M
s ,h
} iu;a
úi÷u 2' ,l=Kq 35 fyda Bg jvd jeä kï
m%;M
s ,h
} iu;a
tfia fkdfõ kï
m%;M
s ,h
} wiu;a
m%;o
s dk ( iu;a fyda wiu;a nj
(02) .eg¿j i|yd we,af.drs;uhla f.dvke.Su
(Developing an Algorithm for the problem)
What is an Algorithm? ^we,af.drs;uhla hkq l=ulao@&
An algorithm is a step-by-step procedure for solving a problem. (An algorithm is a method to show the steps in
solving a problem)
^.eg¿jla úioSu i|yd wkq.ukh l,hq;= mshjr ish,a, wkqms<sfj,ska oelajQ l%ufõohla we,af.drs;uhla
fõ ^.eg¿jla úioSu mshjfrka mshjr oelajQ l%uhla&&
O/L ICT
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 6
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
WodyrK - ,smshla ;eme,a lsÍu i|yd we,af.drs;uh (Developing an algorithm to post a letter.)
^1& ,smsh ,sùu
^2& ,smsh keùu
^3& ,shqï ljrhlg oeóu
^4& ,smskh ,sùu
^5& uqoaor we,ùu
^6& ;eme,a lsÍu
Write the letter
Folding the letter
Inserting the letter in an envelop
Writing the address
Sticking the stamp
Posting the letter
by; mshjr ,smshla ;eme,a lsÍu i|yd jQ we,af.dß;uh fõ' fuu we,af.dß;ufha ^1&" ^2& iy ^3& jk
mshjr wkqms<sfj<ska u isÿl< hq;= h' ^4& iy ^5& mshjr udrel< yels h' thg fya;=j ,smskh ,shd uqoaor
we,úh yels h' tfuka u uqoaorh w,jd ,smskh ,súh yels h' ta wkqj we,af.dß;uhl wkqms<sfj<ska u
l%h
s d;aul l< hq;= mshjr mj;sk w;r iuyr úg mshjr lsysmhl wkqms<sfj< fjkia l< o tu.ska bÈßm;a
flfrk l%h
s dj,shg ydkshla isÿ fkdfõ'
Representation of Algorithm ^we,af.drs;u ksrEmkh&
1
Graphical Representation ^rEmuh ksrEmkh&
2
Textual Representation ^,sÅ;uh ksrEmkh&
Flow Charts ^.e,Sï igyka&
A flow chart is a graphical representation of an algorithm. Each step in the flow chart is represented by a
designed symbol and is linked with arrows showing the direction of data flow. A standard set of symbols has
been introduced to be used in flow chart.
^we,af.drs;uhl úOdkhka ls%hdl,hq;= wdldrh wkqms<sfj,ska rEmuh ixfla; u.ska oelajQ igykla
.e,Sïigykla f,i y÷kajkq,nhs' .e,Sï igykla ks¾udKfhaoS Ndú; l, hq;= iïu; ixfla; y÷kajdoS
we;'&
Symbols Used in Flow chart
.e,Sï igykloS Ndú;hg .kakd ixfla;
1
Start/Stop, Begin/End
wdrïNh$wjidkh
Terminator
2
Input/Output
3
Process
O/L ICT
wdodk$m%;o
s dk
ieliSu$l%h
s dj,sh
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 7
jeäu isiqka msßila iyNd.S jk m%;M
s , j,ska Y%S ,xldfõ wxl tfla ICT mka;sh
ksiel A idud¾:h
iïnkaOlh
4
Connector
5
Decision
6
Flow Lines/Flow direction
;SrKh
.e,Sï f¾Ld$.e,Sï osYdj
m%Yak wxl 01
Draw a flow chart to add two numbers given by the user and display the sum (total) of those two numbers
^Ndú;lrkakd úiska ,ndfok ixLHd foll tl;=j fidhd tu tl;=j fmkajk .e,Sï igykla w|skak&
O/L ICT
iqúYsIaG ICT m%;sM,hl woaú;Sh kduh - l=i,a weye,wdrÉÑ
Page 8
Download