დაპროგრამების საფუძვლები C+ +

September 17, 2017 | Author: Kakha-phoenix | Category: Computing And Information Technology, Science, Technology (General), Engineering, Mathematics
Share Embed Donate


Short Description

დაპროგრამების საფუძვლები C+ +...

Description

saqarTvelos universiteti

l. gaCeCilaZe

daprogramebis safuZvlebi (algoriTmuli ena C++)

Tbilisi 2012

ganxilulia algoriTmebis Sedgenis ZiriTadi principebi, maTi gamosaxvis saSualebebi da daprogramebis ena C++-is safuZvlebi. Teoriul masalasTan erTad, mocemulia Sesabamisi amocanebi da magaliTebi. saxelmZRvanelo gankuTvnilia saqarTvelos universitetis maTematikis da informatikis skolis studentebisaTvis.

recenzenti: sruli profesori m. avaliSvili

 gamomcemloba „saqarTvelos universiteti”, 2012 ISBN

2

Tavi I informatikis ganviTarebis mokle mimoxilva 1.1. informaciis cneba uZvelesi droidan adamianis moRvaweoba mimarTuli iyo bunebis Semecnebisa da aTvisebisaken. Tavdapirvelad igi ubralod, bunebis mza "saCuqrebiT" irCenda Tavs: mcenareuli sakvebiT, fesvebiT, cxovelebiT, rac mis saarsebo saSualebas Seadgenda. magram, amave dros, adamiani Seicnobda gare samyaros da swavlobda bunebaze zemoqmedebis saSualebebs. yuradReba rom mivaqcioT Cvens dRevandel garemocvas, SevniSnavT, rom TiTqmis yvelaferi Seqmnilia an gardaqmnilia adamianis mier. tanisamosi, saxlebi, avtomobilebi, qarxnebi, telefoni, radio da televizori - yvelaferi es adamianis Semoqmedebis Sedegia. adamianis mier bunebrivi resursebis gamoyeneba da masze zemoqmedeba SesaZlebeli gaxda swored im informaciis, codnisa da gamocdilebis wyalobiT, romelic kacobriobam miiRo Tavisi mravalsaukunovani arsebobis manZilze. "informacia" - ras gulisxmoben am sityvaSi? sityva "informacia" laTinuri warmoSobisaa da ganmartebas, gadmocemas aRniSnavs. xSirad "informacias" ganmartaven rogorc Setyobinebas an cnobas raime momxdari ambis an risame mdgomareobis Sesaxeb. gvxvdeba "informaciis" filosofiuri xasiaTis gansazRvrebebic, rogoricaa "informacia realuri samyaros asaxvaa" da sxv. me-20 saukunis meore naxevridan "informacia" zogadsamecniero terminia, romelic moicavs cnobebisa da signalebis gadacemas, gacvlas da igi warmoadgens kibernetikis erT-erT ZiriTad cnebas. 3

1.2. informaciis damuSaveba informacias adamianebi uZvelesi droidan amuSavebdnen, magram TviT termini "informaciis damuSaveba" didi xani ar aris rac gaCnda. yoveldRiur cxovrebaSi adamiani Rebulobda informacias smenis, mxedvelobis, grZnobis organoebis saSualebiT. miRebul informacias igi Segnebulad an Tavisi nebisgan damoukideblad amuSavebda, e.i. axdenda mis Sedarebas misTvis ukve cnobil movlenebTan da aqedan gamomdinare, akeTebda axal daskvnebs, axdenda Tavisi codnis klasifikacias. Tavdapirvelad, informaciis gadacema xdeboda zepirad, Taobidan TaobaSi. es iyo cnobebi nadirobis, nanadirevis gadamuSavebis, miwaTmoqmedebis Sesaxeb da sxv. SemdgomSi ki informaciis fiqsireba xdeboda grafikuli saSualebebiT. ase gaCnda mravali aTeuli saukunis win kldeebze da qvebze Sesrulebuli naxatebi, romlebic gamosaxavda cxovelebs, mcenareebs, sanadiro da samuSao iaraRebs da sxv. adamiani eZebda informaciis fiqsirebis sul axal da axal saSualebebs. gaCnda damwerloba. adamianebi werdnen palmis foTlebze, Tixis filebze, mogvianebiT ki pergamentis furclebze. damwerloba kacobriobis mier Seqmnili informaciis Senaxvisa da gadacemis pirveli universaluri saSualebaa. dro gadioda, Taobebi icvleboda TaobebiT, erTi socialuri wyoba icvleboda meoreTi, izrdeboda kacobriobis mier dagrovili codna samyaros Sesaxeb. es ukanaskneli miT ufro swrafad mimdinareobda, rac ufro efeqturad xdeboda informaciis gadacema, damuSaveba da gamoyeneba. mosaxleobis zrdam gamoiwvia saxelosno da sameurneo sawarmoebis gaCena. amisaTvis ki aucilebeli iyo ufro meti raodenobis adamianis dasaqmeba, risTvisac, Tavis mxriv, saWiro gaxda maTTvis im saidumloebebisa da gamocdilebis gadacema, rome4

lic saukuneebis manZilze grovdeboda. amgvarad, aqtualuri gaxda dagrovebuli gamocdilebis gamravlebisa da gavrcelebis problema. am sferoSi gadatrialeba moaxdina sabeWdi dazgis Seqmnam, ris Sedegadac SesaZlebeli gaxda profesiuli codnis masiurad gavrceleba. wlebi gadioda, izrdeboda informaciis moculoba, romelic icvleboda sazogadoebaSi. informaciis Sekrebis, gadamuSavebis da gavrcelebis mizniT iqmneboda gamomcemlobebi da tipografiebi. amgvarad, Seiqmna informaciuli mrewveloba. beWdvis garda gaCnda sxva masobrivi sainformacio saSualebebi - radio da televizia. amasTan, didi tiraJiT gamocemulma gazeTebma, Jurnalebma da wignebma, sasargeblo informaciis garda, adamians uzarmazari moculobis arasaWiro da gamousadegari informaciac moaxvies Tavs, romelic `informaciuli xmauris” saxelwodebiTaa cnobili. DA 1.3. informaciis gamosaxva ricxviTi sidideebis saSualebiT uZvelesi droidan adamians gauCnda aucilebloba iseTi informaciis gamosaxvisa, romelic raodenobriv xasiaTs atarebda. magaliTad, uZvelesi adamiani, imisaTvis, rom Tavisi tomis wevrebisaTvis Seetyobinebina Tu ramdeni cxoveli mokla, xelis TiTebs iyenebda. sabrZolo da Sromis iaraRebis, sakvebisa da sxva sasicocxlo mniSvnelobis nivTebis damzadebisa da gacvlis aucileblobam aiZula adamiani dasaTvlelad Cxirebi da kenWebi gamoeyenebina. gavida xani da raodenobrivi bunebis informaciis gamoxatvisaTvis adamians ricxviTi sidideebi Semoaqvs. ricxviTi sidideebis Semotana umniSvnelovanesi movlenaa kacobriobis ganviTarebis istoriaSi, romelmac dasabami misca ariTmetikis, xolo mogvianebiT algebra-geometriis ganviTarebas. 5

1.4. avtomatizaciis pirveli mcdeloba - saangariSo dafa informaciis ricxvebis saSualebiT warmodgenis SemTxvevaSi misi gadamuSavebis procesi daiyvaneba ricxvebze ariTmetikuli operaciebis Catarebaze. amitom adamianis pirveli mcdeloba dakavSirebuli iyo iseTi xelsawyos gamogonebasTan, romelic aadvilebda ariTmetikuli operaciebis Catarebas. erT-erTi pirveli aseTi xelsawyoa saangariSo dafa. jer kidev ramdenime aTasi wlis win adamianma lerwmis CarCoze Tokebi gaWima, yovel Tokze aT-aTi mZivi aasxa da pirveli saangariSo Seqmna. ariTmetikuli gagebiT, saangariSo dafis RerZebi aRniSnaven ricxviTi sistemis Tanrigebs: pirvel RerZze Camocmul TiToeul koWas erTeulis fasi aqvs, meore RerZze - aTeulis da a.S. aRsaniSnavia, rom erTidaigive koWas sxvadasxva RerZebze sxvadasxva ricxvis gamosaxva SeuZlia. ase, magaliTad, ori koWa pirvel (erTeulebis) RerZze gamosaxavs ricxvs "2", xolo igive ori koWa meore (aTeulebis) RerZze aRniSnavs ricxvs "20". ricxvebis Caweris ganxilul princips poziciuri ewodeba, vinaidan ricxvis Semadgeneli yoveli cifris ricxviTi mniSvneloba damokidebulia ara mxolod mis gamomxatvel simboloze, aramed am simbolos poziciaze ricxvSi. mxolod saangariSo RerZze koWebis raodenobiT mTeli ricxvis sididis dadgena SeuZlebelia, Tu ar gvecodineba RerZis nomeri saangariSo dafaze. aTvlis sistemebs, romlebic aTvlis aRweril princips iyenebs, poziciuri ewodeba. aTvlis poziciuri sistemebidan yvelaze gavrcelebulia indo-arabuli sistema, sadac cifrebis aRmniSvneli simboloebis ricxvi SezRudulia da gamoyenebulia sul 10 simbolo (1,2,3,4,5,6,7,8,9,0). aRsaniSnavia, rom cifri 0 (nuli) Tav6

dapirvelad indoelebma gamoiyenes cifrebis mwkrivSi cifrebis poziciuri mniSvnelobebis gamosavlenad. am sistemas aTobiTi ewodeba, vinaidan igi aTi cifrisagan Sedgeba. aTobiT sistemaSi nebismieri ricxvi Caiwereba 0  9 cifrebis kombinaciiT, magaliTad, 35, 263, 5814 da a.S. poziciuri sistemebisgan gansxvavebiT, aTvlis arapoziciur sistemaSi, rogoricaa romauli sistema, specialuri niSnebi aqvs erTs - I, xuTs - V, aTs - X, ormocdaaTs - L, ass - C, xuTass - D, aTass - M, xolo danarCeni ricxvebi miiReba aRniSnuli ricxvebis mimatebiTa da gamoklebiT. magaliTad, III miRebulia (I+I+I)dan, IV ki (V-I)-dan da a.S. aTvlis romaul sistemaSi aris kidev erTi naklovaneba: igi ar iZleva nebismieri didi ricxvis Caweris saSualebas. magaliTad, 1000000-is Casawerad saWiroa an 1000-jer gavimeoroT M, an SemovitanoT axali simbolo. cxadia, zrdadobis mixedviT ricxvebis Casawerad dagvWirdeba sul axali da axali simboloebis Semotana. 1.5. teqnikuri saangariSo mowyobiloba Zvel droSi uSiSari mezRvaurebisa da brZeni astronomebisaTvis aucilebeli gaxda zusti da swori gaangariSebebis Sesruleba. aseTi gaangariSebebisaTvis ki saWiro iyo specialuri mowyobilobebi. saangariSo dafa ususuri aRmoCnda sul ufro da ufro rTuli amocanebis gadasawyvetad. gavida mravali weli sanam gamoCndeboda pirveli meqanikuri saangariSo mowyobiloba. aseTi didi pauza gamowveuli iyo imiT, rom umravles SemTxvevaSi gamoiyeneboda romauli aTvlis sistema da mxolod indo-arabuli aTvlis sistemis damkvidrebam misca mniSvnelovani biZgi axali tipis saangariSo mowyobilobebis Seqmnas. 7

1614-1617 wlebSi Sotlandielma maTematikosma jon neperma gamoimuSava gamravlebisa da gayofis gaadvilebuli meTodebi, romelic emyareboda saangariSo diskoebsa da pirdapiri gamravlebis cxrils. neperma Seqmna meqanikuri mowyobiloba, romelic Seicavda koWebian diskoebs, romelzec cifrebi iyo amobeWdili. am diskoebis gansazRvruli SeTavsebiT gamoyenebisas isini pirdapiri gamravlebis SesaZleblobas iZleodnen. am saqmeSi mniSvnelovani gadatrialeba moaxdina frangi blez paskalis gamogonebam 1640 wlis bolos, romlis idea mdgomareobda SemdegSi: "romelime Tanrigis yoveli rgoli an gulari, asrulebda ra moZraobas aTi ariTmetikuli cifris manZiliT, aiZulebda momdevno rgols an gulars Seesrulebina moZraoba erTi cifris manZiliT". avtors xuTi wlis daZabuli muSaoba dasWirda am ideis realizaciisaTvis, ramac igi miiyvana e.w. "paskalis borblis" Seqmnamde, romelic xuTniSna cifrebze oTxi maTematikuri moqmedebis saSualebas iZleoda. 1694 wels germanelma maTematikosma leibnicma Seqmna manqana, romelic asrulebda im dros yvela cnobil maTematikur operacias: oTx ZiriTad maTematikur moqmedebas da kvadratuli fesvis amoRebas. bolos, 1838 wels, Svedma inJinerma v. odnerma Seqmna ariTmometri, romlis safuZvelzec Seiqmna sxva mravali saangariSo mowyobiloba. 1.6. pirveli gamomTvleli manqanebi 1822 wels genialurma ingliselma maTematikosma Carlz bebijma xeli mokida proeqtis ganxorcielebas, romelsac mTeli cxovreba miuZRvna. man Seadgina 37 kv.metrze meti moculobis dawvrilebiTi naxazebi, romelTagan mniSvnelovani nawili analizur manqanas ganekuTvneboda. 12 wlis Tavdauzogavi Sromis Semdeg, romelsac Tan sdevda teqnikuri, finansuri da politikuri problemebi, man ukuagdo es proeqti da daiwyo 8

muSaoba analizuri manqanis SeqmnisaTvis. axali tipis manqana iyo rTuli da saSualebas iZleoda gadawyvetiliyo sxvadasxva tipis amocanebi. marTalia, bebijs ar ewera Tavisi Canafiqris ganxorcieleba, magram, miuxedavad amisa, safuZvlianad damuSavebuli misi proeqtiT SeiZleba Tanamedrove gamoTvliTi manqanebis winasaxis danaxva. bebijis sikvdilidan 20 wlis Semdeg amerikelma gamomgonebelma german xoleritma Seqmna eleqtromeqanikuri saangariSo manqana, romelic gamoyenebul iqna aSS-Si 1890 wels mosaxleobis aRwerisas. SemdgomSi ki, mravali wlis ganmavlobaSi, analizuri manqanis msgavsi araferi Seqmnila. pirveli seriuli gamomTvleli manqana me-20 saukunis ormocdaaTian wlebSi Seiqmna da mas Semdeg dRemde arnaxul srulyofas miaRwia. Tanamedrove kompiuterebi xasiaTdeba zemaRali swrafqmedebiT, operatiuli da gare mexsierebis Zalian didi tevadobiT, kompaqturobiT da sxva teqnikuri maxasiaTeblebiT.

9

Tavi II algoriTmizaciis zogadi cnebebi 2.1. amocanebis gadawyvetis ZiriTadi etapebi maTematikuri da sainJinro amocanebis kompiuteris saSualebiT gadawyveta sakmaod rTuli da Sromatevadi procesia, romelic mTeli rigi etapebis Sesrulebas iTvaliswinebs. es etapebia:  amocanis dasma;  amocanis maTematikuri formulireba;  ricxviTi meTodis SerCeva;  gamoTvliTi procesis algoriTmizacia;  kompiuteruli programis Sedgena;  kompiuteruli programis gamarTva;  amocanis gadawyveta.

amocanis dasma. nebismieri amocanis gadawyvetis sawyis etaps amocanis dasma warmoadgens. igi gansazRvravs amocanis gadawyvetis mizans. am etapze amocana profesiuli cnebebis doneze formulirdeba da igi koreqtuli da gasagebi unda iyos SemsruleblisaTvis (momxmareblisaTvis). amocanis maTematikuri formulireba. maTematikuri formulirebis etapze adgili aqvs formulebis saSualebiT amocanis formalizacias, romlis drosac ganisazRvreba sawyisi pirobebi, gamoTvlis cdomileba, sawyisi da saboloo monacemebi. arsebiTad aq adgili aqvs gadasawyveti amocanis maTematikuri modelis SemuSavebas. ricxviTi meTodis SerCeva. rig SemTxvevaSi, erTidaigive amocana sxvadasxva ricxviTi meTodis saSualebiT SeiZleba gadavwyvitoT. meTodis SerCeva damokidebulia mraval faqtorze, romelTagan ZiriTadia amocanis gadawyvetis sizuste, amocanis gadawyvetisaTvis sa10

Wiro kompiuteruli dro da gamoyenebuli operatiuli mexsierebis tevadoba. TiToeul konkretul SemTxvevaSi ricxviTi meTodis SerCeva aRniSnuli kriteriumebis gaTvaliswinebiT xorcieldeba. saWiroa SevniSnoT, rom umartivesi amocanebis gadawyvetis SemTxvevaSi aRniSnuli etapi ar gamoiyeneba, radgan ricxviTi meTodi TviT amocanis maTematikuri formulirebis safuZvelzea gansazRvruli. ase, magaliTad, heronis formuliT samkuTxedis farTobis gamoTvlis, kvadratuli gantolebis fesvebis gansazRvris amocanebi da sxv. gamoTvliTi procesis algoriTmizacia. mocemul etapze, SerCeuli ricxviTi meTodis mixedviT, ganisazRvreba elementaruli gamoTvlebis logikuri mimdevroba, romlis safuZvelzec amocanis amonaxsni miiReba. algoriTmi ar aris meTodi. igi mxolod SerCeuli ricxviTi meTodis realizaciaa. Tu erTidaigive ricxviTi meTodis ramdenime realizacia arsebobs, maSin saWiroa algoriTmis is varianti avirCioT, romelic kompiuteris efeqtur gamoyenebas uzrunvelyofs. sxva sityvebiT rom vTqvaT, saWiroa iseTi algoriTmis SerCeva, romelsac naklebi raodenobis maTematikuri operaciebis Sesruleba da minimaluri tevadobis mexsiereba esaWiroeba. kompiuteruli programis Sedgena. algoriTmis safuZvelze kompiuteruli programis Sedgenis process daprogrameba ewodeba. Tu programa manqanur enazea Sesrulebuli (e.i. programa dawerilia gamomTvleli manqanis kodebSi), maSin misi kompiuteruli realizacia uSualod SeiZleba ganxorcieldes, xolo Tu programa romelime algoriTmul enazea Cawerili, maSin igi specialuri programuli uzrunvelyofis – transliatoris saSualebiT gadaiyvaneba manqanur kodebSi da mxolod amis Semdeg aris SesaZlebeli misi kompiuteruli realizacia. 11

kompiuteruli programis gamarTva. programaSi Secdomebis moZebnisa da gasworebis (redaqtirebis) process gamarTva ewodeba. ganasxvaveben sintaqsuri da logikuri saxis Secdomebs. sintaqsuri Secdomebis SemTxvevaSi programis normaluri funqcionireba SeuZlebelia masSi dauSvebeli programuli konstruqciebis gamo. aRniSnuli Secdomebis moZebna SesaZlebelia transliatorSi arsebuli sintaqsuri kontrolis programis saSualebiT. im SemTxvevaSi, roca kompiuteruli programis muSaobis Sedegi mosalodnel Sedegs ar emTxveva, maSin adgili aqvs logikuri saxis Secdomebs. aRniSnuli Secdomebi ganpirobebulia algoriTmis araswori SemuSavebis an araswori daprogramebis Sedegad. logikuri Secdomebis arseboba imis maniSnebelia, rom saWiroa wina etapebis guldasmiT gadamowmeba, algoriTmSi da programaSi Sesabamisi Sesworebebis Setana. es procedura dakavSirebulia drois mniSvnelovan danaxarjebTan. amocanis gadawyveta. programis gamarTvis Semdeg adgili aqvs kompiuterze amocanis uSualod gadawyvetas, romlis drosac kompiuterSi Seitaneba sawyisi monacemebi da programis Tvlaze gaSvebis Sedegad saWiro rezultatebi miiReba. 2.2. algoriTmis cneba amocanebis gadawyvetis procesSi algoriTmebis SemuSaveba erT-erTi yvelaze mniSvnelovani da pasuxsagebi etapia. am etapze adgili aqvs im elementarul moqmedebaTa Tanmimdevrobis gansazRvras, romelsac SemdgomSi kompiuteri uSualod asrulebs. cxadia, algoriTmis SemuSavebis procesSi Secdomebis daSveba dauSvebelia, radgan igi, Tavis mxriv, gamoTvliT process arasworad warmarTavs da Sedegic araswori miiReba. 12

algoriTmi Tanamedrove maTematikis fundamenturi cnebebis ricxvs miekuTvneba da igi specialuri disciplinis - algoriTmebis Teoriis kvlevis obieqts warmoadgens. algoriTmis Sedgenis process algoriTmizacias uwodeben. termini algoriTmi me-9 saukunis cnobili uzbeki moazrovnis muhamed ben musa al-xorezmis saxelis laTinur transkrifcias ukavSirdeba (Algorithmi). rogorc cnobilia, al-xorezmma Camoayaliba ariTmetikuli moqmedebebis wesebi. misma traqtatebma ariTmetikasa da algebraSi, romelic me-12 saukuneSi laTinur enaze Targmnes, mniSvnelovani gavlena iqonia maTematikis ganviTarebaze dasavleT evropaSi. aqedan gamomdinare, Tavdapirvelad algoriTmis qveS gulisxmobdnen mravalniSna ricxvebze mxolod oTxi ariTmetikuli moqmedebis Sesrulebis wesebs. mogvianebiT ki algoriTms aigivebdnen evklides SromebSi mocemuli ori ricxvis udidesi saerTo gamyofis moZebnis wesTan (evklides algoriTmi). amJamad, termini algoriTmi sxvadasxva saxis calkeuli wesebis sazogado saxelia da igi Semdegnairad aris ganmartebuli: algoriTmi garkveul miTiTebaTa sasruli mimdevrobaa, romlis Sesruleba saSualebas gvaZlevs miviRoT mocemuli amocanis amonaxsni. moviyvanoT algoriTmebis ramdenime magaliTi. algoriTmi 1. ganvixiloT evklides algoriTmi, romlis saSualebiTac SeiZleba amoxsnil iqnes Semdegi tipis amocana: vipovoT mocemuli ori naturaluri a da b ricxvis udidesi saerTo gamyofi. rogorc cnobilia, ori ricxvis udidesi saerTo gamyofi (usg) ewodeba im udides ricxvs, romelzec unaSTod iyofa mocemuli ricxvebi. mis mosaZebnad saWiroa TanmimdevrobiT SevasruloT Semdegi operaciebi: Tavdapirvelad udidesi ricxvi gavyoT umciresze, Semdeg umciresi ricxvi gavyoT miRebul naSTze, Sem13

deg pirveli naSTi gavyoT meore naSTze da a.S. operaciebi gavagrZeloT manam, sanam naSTi nulis toli ar gaxdeba. rigiT bolo gamyofi udides saerTo gamyofs warmoadgens. vinaidan gayofis operacia mravaljerganmeorebad gamoklebis operaciaze daiyvaneba, amitom algoriTmi SeiZleba Semdegnairad iqnes formulirebuli. 1. Tu a  b , maSin gadavideT me-3 punqtze, winaaRmdeg SemTxvevaSi - me-2 punqtze; 2. Tu b  a , maSin gadavideT me-4 punqtze, winaaRmdeg SemTxvevaSi - me-5 punqtze; 3. a -s gamovakloT b da miRebuli sxvaoba CavTvaloT a -s mniSvnelobad. davbrundeT 1-l punqtSi; 4. b -s gamovakloT a da miRebuli sxvaoba CavTvaloT b -s mniSvnelobad. davbrundeT 1-l punqtSi; 5. a -s an b -s miRebuli mniSvneloba CaiTvleba udides saerTo gamyofad. dasasruli. aRniSnuli algoriTmi gamoviyenoT konkretuli ricxvebis udidesi saerTo gamyofis mosaZebnad. davuSvaT, rom a  95 da b  60 . maSin evklides algoriTmis Tanaxmad Sesrulebuli punqtebis mimdevroba da am dros miRebuli a da b sidideebis cvladi mniSvnelobebi warmodgenilia 1-l cxrilSi. cxrili 1

a

b

95 35 35 10 10 10 5

60 60 25 25 15 5 5

algoriTmis bijebi 1, 3 1, 2, 4 1, 3 1, 2, 4 1, 2, 4 1, 3 1, 2, 5

14

marTlac, 1-li punqtis Tanaxmad Sesrulebuli operaciis Sedegad gadavdivarT me-3 punqtze, radgan a  95  60  b . me-3 punqtis Tanaxmad a -s mniSvneloba gaxda toli a  95  60  35 , xolo b winandeburad tolia b  60 . me-3 punqtSi mocemuli miTiTebis Sesabamisad gadavdivarT 1-l punqtze, romlis Sesrulebis Sedegad gadavdivarT me-2 punqtze, radgan a  b utoloba mcdaria. me-2 punqtSi mocemuli miTiTebis Sesabamisad gadavdivarT me-4 punqtze, sadac gamoiTvleba b -s axali mniSvneloba b  60  35  25 da gadavalT kvlav 1-l punqtze da a.S. analogiuri procesebis gameorebis Sedegad miviRebT, rom mocemuli a da b ricxvebis udidesi saerTo gamyofia cifri 5. algoriTmi 2. ganvixiloT algoriTmi, romelic "eratosTenes saceris" saxeliTaa cnobili. elementaruli maTematikis kursidan cnobilia, rom erTisagan gansxvavebul mTel, dadebiT ricxvebs, romlebic unaSTod iyofa mxolod erTsa da Tavis Tavze, martivi ricxvebi ewodeba. martivi ricxvebia, magaliTad, 2,3,5,7,11 da sxv. ZvelberZenma mecnierma eratosTenem, romelic Cvens welTaRricxvamde III-II saukuneebSi moRvaweobda, SeimuSava wesi im martivi ricxvebis gansazRvrisa, romelTa mniSvneloba n -s ar aRemateba. aRniSnuli wesi SeiZleba aRweril iqnes Semdegi algoriTmiT. 1. TanmimdevrobiT CamovweroT yvela naturaluri ricxvi 1-dan n -mde. gadavxazoT 1. gadavideT me-2 punqtze; 2. davuSvaT, rom m cvlads mivaniWeT ricxvi 2-is mniSvneloba. gadavideT me-3 punqtze; 2 3. Tu m  n , maSin gadavideT me-4 punqtze, winaaRmdeg SemTxvevaSi – me-6 punqtze; 4. ricxvebis mocemul mimdevrobaSi m  1 ricxvidan dawyebuli gadavxazoT TiToeuli me- m ricxvi (yu15

radRebas nu mivaqcevT, Tu igi adre gadaxazuli iyo). gadavideT me-5 punqtze; 5. mocemul ricxvTa mimdevrobaSi m -is Semdeg pirveli gadauxazavi ricxvi CaiTvalos m -is axal mniSvnelobad. davbrundeT me-3 punqtze; 6. ricxvTa mimdevrobis yvela gadauxazavi ricxvi CaiTvleba martiv ricxvebad. dasasruli. algoriTmi 3. ganvixiloT e.w. sayofacxovrebo algoriTmi. rogorc cnobilia, Cais dasayeneblad saWiroa vixelmZRvaneloT Semdegi miTiTebebis mimdevrobiT. 1. Cais dayenebis win Caidani mduRare wyliT gamovavloT; 2. CaidanSi CavyaroT Cai, masSi CavasxaT mTeli moculobis 3 / 4 nawili mduRare wyali da gavaCeroT 5-6 wuTi; 3. Caidani dayenebuli CaiT SevavsoT mduRare wyliT; 4. gemovnebis mixedviT CavasxaT finjanSi. Cais dayenebis wesi nebismieri adamianisaTvis cnobilia. misTvis rom algoriTmis saxe migveca Cven mxolod davnomreT aRniSnuli wesis TiToeuli miTiTeba. msgavsi algoriTmebi mravlad SeiZleba movipovoT, Tu CavixedavT samzareulo wignebSi, mebaReobis, mebostneobisa da meyvavileobis popularul saxelmZRvaneloebSi, sayofacxovrebo teqnikis moxmarebis instruqciebSi. maT SeiZleba mivakuTvnoT agreTve is brZanebebi, romliTac sxvadasxva sawarmoSi momuSave personalis moqmedeba ganisazRvreba. Cven drois umetes nawils algoriTmebis Sesrulebaze vxarjavT. 2.3. algoriTmebis ZiriTadi Tvisebebi algoriTmebi mTeli rigi saerTo niSanTvisebebiT xasiaTdebian, romelTagan aRsaniSnavia: 1. universaloba. rogorc wesi, algoriTmi muSavdeba ara calkeuli amocanebisTvis an calkeuli sawyisi monacemebisTvis, aramed amocanebis farTo klasisT16

vis da sawyisi monacemebis sxvadasxva mniSvnelobebisTvis. ase, magaliTad, evklides algoriTmSi sawyis monacemad SeiZleba aviRoT nebismieri mTeli dadebiTi ricxvebis wyvili. 2. diskretuloba. erT-erTi ZiriTadi moTxovna, romelic algoriTmis SemuSavebis dros aucilebelia dakmayofildes, aris gamoTvliTi procesis iseT elementarul etapebad danawevreba, romelTa Sesruleba eWvs ar iwvevs. aseTi saxiT miRebuli Canaweri warmoadgens miTiTebaTa mowesrigebul erTobliobas, romelic algoriTmis diskretul (wyvetil) struqturas warmoadgens. es Tviseba gansakuTrebiT TvalnaTliv Cans `sayofacxovrebo” algoriTmebSi. 3. determinirebuloba. algoriTmis TiToeuli punqti saWiroa formulirebul iqnes ise, rom misi realizaciis dros Semsruleblis moqmedebebi calsaxad ganisazRvros. amitom erTidaigive sawyisi monacemebis dros algoriTmis rogorc saboloo, ise Sualeduri Sedegebi, da, agreTve, TiToeuli punqtis Sesrulebis mimdevroba sxvadasxva Semsruleblis SemTxvevaSic identuri iqneba. ase, magaliTad, 95-sa da 60-is udidesi saerTo gamyofis mosaZebnad gamoTvliTi procesi yovelTvis im mimdevrobiT warimarTeba, rogorc es 1-l cxrilSia warmodgenili da, amasTan, igive Sedegi miiReba. 4. Sedegianoba. nebismieri algoriTmi xasiaTdeba SedegianobiT, rac imaSi mdgomareobs, rom nebismieri dasaSvebi sawyisi monacemebisa da algoriTmis yvela punqtis zustad Sesrulebis SemTxvevaSi gamoTvliTi procesi sasruli raodenobis bijis Semdeg Sewydeba da ama Tu im sizustiT saZebni rezultati miiReba. im SemTxvevaSi, roca saboloo Sedegis miReba SeuZlebelia, maSin gamoTvliTi procesi usasruloa da igi arasdros Sewydeba an erT-erT bijze misi Sesruleba garkveul winaaRmdegobas waawydeba. ase, magaliTad, zemoT ganxiluli 17

evklides algoriTmi Sedegs mxolod mTeli dadebiTi ricxvebis SemTxvevaSi iZleva. winaaRmdeg SemTxvevaSi gamoTvliTi procesi usasrulod gagrZeldeba. aRniSnuli algoriTmis gamoyeneba 0 da 0 ricxvebis udidesi saerTo gamyofis mosaZebnad aseve mcdar Sedegs iZleva: algoriTmis Tanaxmad, igi nulis tolia, maSin roca sanamdvileSi igi saerTod ar arsebobs. garda amisa, SesaZlebelia SemTxvevebi, roca garkveuli algoriTmiT zogierTi moqmedebebis Sesruleba SeuZlebelia da gamoTvliTi procesi romelime punqtze Sewydeba. ase, magaliTad, y  x /(1  x ) formulis saSualebiT y -s gamoTvlis algoriTmi Sewydeba gayofis etapze, roca x  1 , radgan am SemTxvevaSi adgili eqneba nulze gayofas. ganxiluli magaliTebi imaze metyvelebs, rom sazogadod, algoriTmis SemuSavebis dros saWiroa ganisazRvros misi gamoyenebis are, rac, Tavis mxriv, ukavSirdeba simravles im sawyisi monacemebisa, romlisTvisac algoriTmi Sedegiania. algoriTmebis SemuSaveba mniSvnelovanwilad SemoqmedebiTi, evristikuli procesia. igi, rogorc wesi, saWiroebs erudicias, gamomgoneblobis unarsa da aratradiciul midgomas. magram mas Semdeg, rac algoriTmi SemuSavdeba, Sesabamisi amocanebis gadawyveta ukve meqanikurad Sesruldeba da, cxadia, es procesi iqneba avtomatizebuli. aRniSnuli faqti TvalnaTliv adasturebs ara marto algoriTmebis mniSvnelobas, romelTa SemuSaveba nebismieri amocanis avtomatizebuli gadawyvetis aucilebel etaps warmoadgens, aramed algoriTmebis Teoriis mniSvnelobasac, romelic mkacr mecnierul, maTematikur safuZvelze maTi SemuSavebis, analizisa da gardaqmnis saSualebas gvaZlevs. 2

18

Tavi III algoriTmebis gamosaxvis formebi SemuSavebuli algoriTmi momxmareblisTvis rom gasagebi gaxdes, saWiroa gamosaxvis konkretuli saSualebebis safuZvelze misi formalizacia, romelic garkveuli wesebis dacviT unda ganxorcieldes. algoriTmebis gamosaxvis mravali forma arsebobs, romelic erTmaneTisagan simartivis, TvalsaCinoebis, formalizaciis xarisxis, kompaqturobisa da sxv. maCveneblebis mixedviT gansxvavdeba. algoriTmebis TeoriaSi ZiriTadad gavrcelebulia algoriTmebis gamosaxvis Semdegi formebi: sityvieri, grafikuli, sxvadasxva formaluri algoriTmuli enebis safuZvelze SemuSavebuli saSualebebi da sxv. 3.1. sityvieri forma algoriTmebis gamosaxvis sityvieri forma SedarebiT yvelaze gavrcelebuli formaa. am formiT algoriTmebis warmodgenisaTvis Cveulebrivi salaparako ena gamoiyeneba. amis naTeli magaliTia meore paragrafSi ganxiluli algoriTmebi. sityvieri formiT warmodgenil algoriTmebSi specialuri SeTanxmebebisa da daSvebebis safuZvelze SesaZlebelia maTi SedarebiT kompaqturad Cawera. qvemoT mocemulia evklides algoriTmis kompaqturi varianti. algoriTmi 4 (evklides algoriTmi). 1. dasawyisi; 2. sawyisi monacemebis Setana ( a , b ); 3. Tu a  b , maSin gadavideT me-5 punqtze, winaaRmdeg SemTxvevaSi - me-4 punqtze; 4. Tu b  a , maSin gadavideT me-6 punqtze, winaaRmdeg SemTxvevaSi - me-7 punqtze; 5. a  a  b ; gadavideT me-3 punqtze; 19

6. b  b  a ; gadavideT me-3 punqtze; 7. usg  a ; 8. Sedegis (usg) amobeWdva; 9. dasasruli. meoTxe algoriTmi, pirvelisgan gansxvavebiT, Seicavs algoriTmis dawyebisa da damTavrebis aRmniSvnel miTiTebebs. garda amisa, vinaidan nebismieri algoriTmis SemuSavebis dros saWiroa gaviTvaliswinoT misi kompiuteruli realizaciac, amitom aq damatebulia sawyisi monacemebis kompiuterSi Setanisa da saboloo Sedegis monitoris ekranze an sabeWd mowyobilobaze gamotanis miTiTebebic (punqtebi 2 da 8). Semdegi tipis frazebis " x -s gamovakloT y da miRebuli sxvaoba CavTvaloT x -is mniSvnelobad", "CavTvaloT, rom x tolia y -is" nacvlad gamoyenebulia Canawerebi " x  x  y " da " x  y ". es saSualebas gvaZlevs SedarebiT kompaqturad CavweroT me-3, me-4 da me-5 punqtebi. im punqtebSi, sadac miTiTebuli ar aris gadasvlis mimarTuleba (punqtebi 2 da 7), igulisxmeba rigiT Semdeg punqtze gadasvla. saWiroa SevniSnoT, rom maTematikuri TvalsazrisiT, Canaweri x  x  y mcdari gamosaxulebaa. igi arc igiveobaa, arc gantoleba da arc tolobis piroba. gaugebaria, ra unda daviTvaloT amgvari formuliT? samagierod, algoriTmebis TeoriaSi msgavs gamosaxulebas garkveuli datvirTva gaaCnia, vinaidan niSani "  ", romelic maTematikaSi gamoiyeneba rogorc tolobis piroba, igiveobis niSani, gantolebis niSani da, bolos, Cveulebrivad, formulis niSani, aq miniWebis operacias aRniSnavs. aqedan gamomdinare, zemoT aRniSnuli Canaweri Semdegnairad ikiTxeba: x -s mivaniWoT x  y sxvaobis mniSvneloba. analogiurad ikiTxeba Canaweri " x  y ": x -s mivaniWoT y -is mniSvneloba. miniWebis operaciis Sesrulebis wesidan gamomdinareobs, rom algoriTmebis TeoriaSi dasaSvebia SemTxveva, roca erTidaigive cvladi miniWebis "  " niSnis 20

rogorc marcxniv, ise marjvniv mdebareobs. magaliTad,

x  x  1 , y  y , z  sin z da a.S. algoriTmebis warmodgenis sityvieri forma mTeli rigi naklovanebebiT xasiaTdeba, romelTagan ZiriTadia mkacri formalizaciisa da gamoTvliTi procesis uqonloba. miuxedavad amisa, igi nebismieri sirTulis algoriTmebis gamosaxvis saSualebas iZleva. savarjiSo 1. vTqvaT, mocemulia raRac a1 , a2 ,, aN elementebis mimdevroba. y 

N

a i 1

i

formulis safuZvel-

ze SevadginoT aRniSnuli elementebis jamis gamoTvlis algoriTmi sityvieri formiT. algoriTms aqvs Semdegi saxe: 1. dasawyisi; 2. y  0 ; i  1 ;

y  y  ai ; 4. Tu i  N , maSin gadavideT me-6 punqtze, winaaRm3.

deg SemTxvevaSi – me-5 punqtze; 5. i  i  1 ; gadavideT me-3 punqtze; 6. amobeWdva ( y ); 7. dasasruli. savarjiSo 2. SevadginoT y 

x2  3 gamosaxulebis 3x  1

gamoTvlis algoriTmi sityvieri formiT (miTiTeba: gamoviyenoT damxmare z cvladi Sualeduri mniSvnelobis dasamaxsovreblad). algoriTms aqvs Semdegi saxe: 1. dasawyisi; 2. x -is wakiTxva ( x -is konkretuli mniSvnelobis Setana); 3. z  3  x ; 4. 5.

z z; z  z 1; 21

6. 7. 8. 9. 10.

y  x x; y  y  3; y  y/ z; amobeWdva ( y ); dasasruli. 3.2. grafikuli forma

algoriTmis grafikul gamosaxulebas blok-sqema ewodeba. blok-sqemis TiToeuli Semadgeneli ubani garkveuli formis geometriuli figurebiT gamoisaxeba. TiToeuli figura gamoTvlebis erT garkveul etaps aRniSnavs da mas bloks uwodeben. qvemoT mocemul me-2 cxrilSi warmodgenilia daprogramebis praqtikaSi gamoyenebuli da yvelaze gavrcelebuli blokebi, romlebic aucilebelia nebismieri blok-sqemis Sedgenis dros. Cveulebriv, blokis SigniT iwereba teqsti, romelic Sesasrulebel moqmedebas akonkretebs. im SemTxvevaSi, Tu teqsti ar eteva blokis CarCoebSi, maSin igi calke, SeniSvnis (komentaris) saxiT mieTiTeba. SeniSvna: a =10 mm, 15 mm an 20 mm; b =1,5 a ; dasaSvebia b =2 a ; konturis xazis sisqe S  0,6  1,5 mm; SesaZlebelia a =50 mm, 75 mm an 100 mm. blok-sqemaSi algoriTmis Sesrulebis Tanmimdevroba Sesasrulebeli operaciebis Sesabamisi blokebis TanmimdevrobiT SeerTebis safuZvelze xorcieldeba SemaerTebeli xazebiT, romelsac informaciis nakadis xazebs uwodeben. nakadis xazebis ZiriTad mimarTulebad miCneulia mimarTuleba zevidan qvemoT da marcxnidan marjvniv. im SemTxvevaSi, roca erTi blokis meore blokTan SeerTebis mimarTuleba ZiriTad mimarTulebas emTxveva, maSin nakadis xazs, rogorc wesi, mimarTulebis maCvenebeli isari ar ukeTdeba; yvela danarCen SemTxvevaSi ki misi gaTvaliswineba aucilebelia. 22

#

dasaxeleba 2 gamoTvlebis bloki

aRniSvna da zomebi 3

a

1. 1.

a

b

funqcia 4 gamoTvlebis (operaciebis) Sesruleba, romlis Sedegad monacemebis mniSvnelobebi icvleba.

2.

logikuri bloki

garkveuli pirobebis mixedviT algoriTmis Sesrulebis mimarTulebis amorCeva.

3.

modifikaciis bloki

a

b

a b

winaswar gansazRvruli procesis bloki

0,15a

a

4.

b

23

operaciebis Sesruleba algoriTmebis punqtebis Sesacvlelad. adre Sedgenili da calke aRwerili algoriTmebis gamoyeneba (qveprogramis an standartuli programis mixedviT

gamoTvla). 5.

a

0,25a

Setanagamotanis bloki

0,25a

b

gaSvebagaCerebis bloki

R

R=0,25a 0,5a

6.

b

7.

nakadis xazi

=0,5a

D

8.

pirveli tipis SemaerTebeli

sawyisi monacemebis Setana, saboloo Sedegebis gamotana.

monacemebis damuSavebis procesis dasawyisi, dasasruli, Sewyveta blokebs Soris kavSiris miTiTeba. nakadis gawyvetil xazebs Soris kavSiris miTiTeba.

meore tipis SemaerTebeli

0,2a

9.

0,5a

0,5a

24

sxvadasxva furclebze ganTavsebuli algoriTmis nawilebs So-

10.

nakadis xazebis gadakveT a komentari

0,5a

a

11.

ris kavSiris miTiTeba. sqemis elementsa da ganmartebas Soris kavSiris miTiTeba

nakadis xazebis Serwyma

12.

nakadis xazebis gadakveTa a

blokTan mimarTebaSi informaciis nakadis xazi SeiZleba iyos Semavali da gamomavali. blokSi Semavali nakadis xazebis raodenoba principialurad SezRuduli ar aris, blokidan gamomavali nakadis xazi ki mxolod erTia SesaZlebeli. gamonakliss logikuri bloki warmoadgens. mas gaaCnia aranakleb ori gamomavali nakadis xazi, romelTagan TiToeuli Seesabameba logikuri pirobis erT-erT SesaZlo variants. am SemTxvevaSi saWiroa nakadis xazebis markireba sityvebiT `ki” da `ara” ise, rogorc es naCvenebia naxazze 1. 25

ara

ki

ab

ara

ki nax. 1 blok-sqemis aRweris gaadvilebis mizniT yvela bloki, gaSveba-gaCerebis blokis garda, TanmimdevrobiT inomreba. nomeri iwereba blokis zemoT marcxena kuTxeSi (nax. 2).

A 12

13

A

nax. 2 erTmaneTisagan daSorebul blokebs Soris nakadis xazebi SeiZleba gavwyvitoT, magram gawyvetis wertilebSi orive mxridan saWiroa movaTavsoT pirveli tipis SemaerTebeli, romelic identificirebuli iqneba romelime asoTi, cifriT an maTi kombinaciiT (nax. 3). B2

8

ki

9

ara B2

nax. 3 26

SedarebiT rTuli algoriTmebis SemuSavebisa da maTi gamosaxvis dros SesaZlebelia naxazi gadaitvirTos urTierTgadamkveTi nakadis xazebiT. aseT SemTxvevaSi dasaSvebia erTmaneTisgan daSorebul blokebs Soris nakadis xazebis gawyveta. Tu nakadis xazebiT erTmaneTTan dakavSirebuli blokebi sxvadasxva furclebzea moTavsebuli, maSin saWiroa gamoyenebul iqnas meore tipis SemaerTebeli, romelSic Caiwereba furclis nomeri da im blokis nomeri, romliskenac mimarTulia nakadis xazi (nax. 4).

15 001 15

002

16

16

furceli 001

furceli 002

nax. 4 im SemTxvevaSi, roca algoriTmis blok-sqema erT furcelze ar eteva da igi ramodenimezea warmodgenili, maSin nakadis xazis erTi furclidan meoreze ga27

dasvlis dasafiqsireblad saWiroa meore tipis SemaerTeblis gamoyeneba. amasTan, pirvel furcelze gamoxatul SemaerTebelSi saWiroa Caiweros meore furclis nomeri da im blokis nomeri, romelsac nakadis xazi uerTdeba; xolo meore furcelze warmodgenil SemaerTebelSi – pirveli furclis nomeri da im blokis nomeri, saidanac nakadis xazi miemarTeba. blok-sqemebiT algoriTmebis warmodgenis procesi metad martivia da igi sakmao TvalsaCinoebiT xasiaTdeba. amasTan, am formiT algoriTmis gamosaxvis procesSi detalizaciis xarisxi SeuzRudavia. daprogramebis praqtikaSi cnobili faqtia, rom roca blok-sqema rTulia, igi Tavis sailustracio Tvisebas kargavs. amitom aseT SemTxvevaSi Tavdapirvelad dasaSvebia mTeli gamoTvliTi procesis zogadi gamsxvilebuli blok-sqemis Sedgena, xolo Semdeg TiToeuli misi blokis calke blok-sqemis saSualebiT warmodgena.

3.3. algoriTmebis warmodgenis cxriluri forma algoriTmebis warmodgenis cxriluri forma metad mosaxerxebeli formaa. arsebobs sxvadasxva tipis cxrilebi. Cven ganvixilavT maT Soris or umartivess. pirveli tipis cxrili gamoiyeneba im SemTxvevebSi, sadac saWiroa mocemuli formulis saSualebiT gamoTvliTi procesis iseTi organizacia, romelic calkeuli operaciebis mixedviT Sualeduri Sedegebis dafiqsirebis saSualebas iZleva. aRniSnuli problemis gadawyveta dakavSirebulia mocemuli formulis safuZvelze elementarul moqmedebaTa Tanmimdevrobis gansazRvrasTan, rac, Tavis mxriv, algoriTmis Sesabamis miTiTebaTa Tanmimdevrobas ganapirobebs. algoriTmis aseTi formiT warmodgena, upirveles yovlisa, mizanSewonilia im SemTxvevaSi, roca saWiroa erTi gamosaxulebis ramdenime mniSvnelobis gamoTvla Sesavali sidideebis sxvadasxva mniSvnelobebis dros. 28

ganvixiloT sailustracio magaliTi 3.1. wakveTili konusis moculoba gamoiTvleba Semdegi formuliT: 1 2 2 V  H ( R  Rr  r ), 3 sadac H – wakveTili konusis simaRlea, xolo R da r – Sesabamisad zeda da qveda fuZeebis radiusebi. saWiroa SevadginoT wakveTili konusis moculobis gansazRvris cxriluri algoriTmi da misi saSualebiT gamoviTvaloT V-s mniSvnelobebi Sesavali H, R da r sidideebis sxvadasxva mniSvnelobebis dros. mocemuli amocanis gadasawyvetad SevadginoT Semdegi saxis cxrili (ix. cxrili 3).

cxrili 3. H 10 20 30

R 4 5 7

r 2 3 5

H

⅓H

R2

Rr

r2

R2+Rr+r2

V

cxadia, rom cxrilis TiToeuli striqonis Sevsebis Tanmimdevroba wakveTili konusis moculobis gamoTvlis algoriTms gansazRvravs. ganvixiloT meore tipis cxrili. umartives SemTxvevaSi igi oTxi nawilisgan Sedgeba da aqvs nax. 5-ze warmodgenili cxrilis forma.

29

1

2

3

4



k

Y

N

Y

-



N

piroba 2

-

Y

Y

Y



N

piroba 3

Y

-

Y

N



-

…. . .













piroba n

N

Y

N

-



Y

moqmedeba 1

x



x



moqmedeba 2

x

moqmedeba 3

x

x

x











x



. . .



moqmedeba m

x

x

x

IV Sesasrulebeli moqmedebebis aRniSvna

II moqmedebebis sia

cxrilis nomeri piroba 1

III pirobebis Sesrulebis Sedegebi

I pirobebis sia

wesebi

nax. 5. cxrilis marcxena mxares zemodan qveviT Camowerilia algoriTmis mixedviT gamoyenebuli yvela piroba da amocanis gadawyvetis procesSi Sesasrulebeli yvela moqmedeba. TiToeuli piroba an moqmedeba erT striqonSi iwereba. cxrilis marjvena mxare, romelSic pirobebis Sesrulebis Sedegebi da Sesasrulebeli moqmedebebi aRiniSneba, ramdenime svetad aris dayofili. TiToeuli sveti Seesabameba TiTo wess, sadac gansazRvrulia Tu romeli pirobebia Sesamowmebeli, ro30

gori unda iyos Semowmebis Sedegebi da am Sedegebis mixedviT Tu ra moqmedebebis Sesrulebaa saWiro. wesi unda iTvaliswinebdes yvela SesaZlo SemTxvevas da igi specialuri simboloebiT aRiniSneba. Tu romelime wesSi piroba gamoyenebulia rogorc elementi, maSin Sesabamisi svetisa da striqonis gadakveTaze iwereba Y(ki) an N(ara). pirveli simbolo aRniSnavs pirobis Sesrulebas, xolo meore – arSesrulebas. wesSi gauTvaliswinebeli pirobis SemTxvevaSi Sesabamis poziciaSi Caiwereba defisi (-). Tu wesiT gansazRvrulia raRac moqmedebis Sesruleba, maSin Sesabamisi striqonisa da svetis gadakveTaze Caiwereba simbolo "x", xolo winaaRmdeg SemTxvevaSi pozicia Se-uvsebeli darCeba. Tu pirobebis formulireba iseTia, rom SesaZlebelia mxolod ori pasuxi - "ki" an "ara", maSin aseT cxrils SezRuduls uwodeben. ("cxrili SezRuduli SesasvlelebiT"). im SemTxvevaSi, roca pirobebi rTulia da savaraudo pasuxebis ricxvi orze metia, maSin mizanSewonilia visargebloT gafarToebuli cxriliT ("cxrili gafarToebuli SesasvlelebiT"), romelic Semdegnairad unda Seivsos: rTuli pirobis dasawyisi Caiwereba pirobebis CamonaTvalSi, xolo misi gagrZeleba Sesabamis svetebSi gadanawildeba. martivi pirobis Caweris wesi ki igivea, rac pirvel SemTxvevaSi. magaliTi 3.2. SevadginoT evklides algoriTmi gafarToebuli cxrilis saxiT. algoriTmi warmodgenilia cxrilSi 4.

31

cxrili 4

wesebi

I

II

cxrili 001 a a=a-b b=b-a gadavideT 001 cxrilze usg=a(an b) dasasruli

1

2

3

>b

b, ab, maSin SevasruloT moqmedeba a=a-b da moqmedeba "gadavideT 001 cxrilze"; II- wesi - Tu a20, romelic ciklis muSa (ZiriTadi) nawilis boloSia moTavsebuli (bloki 7). aRniSnuli pirobis samarTlianobis SemTxvevaSi (i>20) adgili aqvs ciklidan gamosvlas, winaaRmdeg SemTxvevaSi (i20) ki - ciklis dasawyisSi gadasvlas. magaliTi 4.8. igive amocana (rac magaliT 4.7-Sia) gadavwyvitoT ukumTvlelis gamoyenebis SemTxvevaSi. lok-sqema warmodgenilia nax. 16-ze. dasawyisi

2 Setana a1,a2,…a20 1

S=0

ciklis momzadeba da gawyoba

i=20 4 ciklis damTavrebis 122pirobis Semowmeba 4

ki

ib a≥b ab a>=b a0) || (y0 an y0); ( Sedegi: x0 ) 63

6.4. miniWebis operacia C++-Si arsebobs miniWebis operacia, romelic Zireulad gansxvavdeba maTematikuri tolobis niSnisgan, Tumca amave niSniT gamoisaxeba. igi tolobis niSnis marcxniv arsebul cvlads aniWebs amave niSnis marjvniv moTavsebuli gamosaxulebis mniSvnelobas. mag: x=x+5 – maTematikaSi dauSvebelia, xolo C++-Si savsebiT realuri dasaSvebi operaciaa, sadac x cvladis mimdinare mniSvneloba izrdeba xuTiT da miRebuli Sedegi eniWeba amave x cvlads. miniWebis operaciis asociaturoba marjvnidan marcxnivaa. aRniSnuli operacia saSualebas iZleva ariTmetikuli operaciebi Caiweros kompaqturad. es operaciebi warmodgenilia me-6 cxrilSi. (sadac a cvladis mniSvneloba xuTis tolia. a=5). cxrili 6 operacia nimuSi ganmarteba Sedegi += -= *= /= %=

a+=7 a-=2 a*=3 a/=2 a%=3

a=a+7 a=a-2 a=a*3 a=a/2 a=a%3

a=12 a=3 a=15 a=2 a=2

6.5. inkrementisa da dekrementis operaciebi C++-Si farTod gamoiyeneba inkrementisa (++) da dekrementis (_ _) unaruli operaciebi. operacias, romlis drosac cvladis mniSvneloba izrdeba erTiT da miRebuli Sedegi amave cvladSi inaxeba, inkrementis operacia ewodeba. mag: x++ an ++x.

64

operacias, romlis drosac cvladis mniSvneloba mcirdeba erTiT da miRebuli Sedegi amave cvladSi inaxeba, dekrementis operacia ewodeba. mag: x-- an –x. arsebobs aRniSnuli operaciebis Caweris ori forma: a) prefiqsuli; b) postfiqsuri. prefiqsuli formis gamoyenebis SemTxvevaSi cvladis mniSvneloba jer izrdeba (mcirdeba) da Semdeg gamoiyeneba igi gamosaxulebaSi, xolo postfiqsuri formis SemTxvevaSi cvladi jer gamosaxulebaSi gamoiyeneba da Semdeg xdeba misi mniSvnelobis inkrementi (an dekrementi). magaliTad: a) x=5; b) x=5; ++x; x++; y=x+2; y=x+2; aRniSnuli unaruli operaciebis asociaturoba marjvnidan marcxnivaa. 6.6. terneruli operacia algoriTmul ena C++-Si arsebobs erTaderTi terneruli (?:) - pirobiTi operacia, romelic sami operandisagan Sedgeba. misi Caweris zogadi saxe Semdegia: pirobiTi gamosaxuleba? moqmedeba-1 : moqmedeba-2 magaliTad: a>b? "Yes " : "No" Tu piroba a>b - WeSmaritia, viRebT Sedegs "Yes", winaaRmdeg SemTxvevaSi - Sedegs "No". sakvanZo (koduri) sityvebi C++-Si C++-Si arsebobs mTeli rigi sakvanZo (koduri) sityvebisa, romelTa gamoyeneba monacemTa identifikatore65

bis saxiT dauSvebelia. am sakvanZo sityvaTa CamonaTvali moyvanilia me-7 cxrilSi. cxrili 7 sakvanZo (koduri) sityvebi C++-Si C da C++-Si

auto default float register struct volatile

break do for return switch while

case double goto short typedef

char else if signed union

enum int sizeof unsigned

continue extern long static void

friend public

inline template

mxolod C++-Si

asm new this

catch operator throw

class private try

delete protected virtual

6.7. maTematikuri funqciebis biblioTeka tipiuri maTematikuri gamoTvlebis gansaxorcieleblad C++-Si gamoiyeneba maTematikuri funqciebis biblioTeka , sadac Tavmoyrilia maTematikur funqciaTa umravlesoba. argumentebis saxiT funqciebs gaaCniaT double tipis mniSvnelobebi da amave tipis Sedegebsac iZlevian, Tumca SesaZlebelia rogorc argumentebis, ise saboloo Sedegebis saxiT gamoyenebul iqnas float tipis mniSvnelobebi. es maTematikuri funqciebi warmodgenilia me-8 cxrilSi. 66

cxrili 8 funqciis Canaweri C++-Si sin(x) cos(x) tan(x) asin(x) acos(x) atan(x) sqrt(x) pow(x,y) exp(x) fabs(x) log(x) log10(x) ceil(x) floor(x) fmod(x,y)

ganmarteba sinx ( x argumenti moicema radianebSi) cosx ( x argumenti moicema radianebSi) tgx ( x argumenti moicema radianebSi) arcsinx ( x argumenti moicema radianebSi) arccosx ( x argumenti moicema radianebSi) arctgx ( x argumenti moicema radianebSi)

x kvadratuli fesvi x-dan x x ayvanili y xarisxSi ex eqsponencialuri funqcia y

x x-is moduli (absoluturi mniSvneloba) lnx naturaluri logariTmi (e-s fuZiT) lgx aTobiTi logariTmi(10-s fuZiT) x-is damrgvaleba metobiT momdevno mTel ricxvamde (aranakleb x-isa) x-is damrgvaleba naklebobiT momdevno mTel ricxvamde (araumetes x-isa) x-is y-ze gayofis Sedegad miRebuli naSTi (aTwiladi ricxvi)

67

6.8. programis Sedgenis struqtura ganvixiloT daprogramebis ena C++-ze elementaruli programis Sedgenis magaliTi: // The first program. #include main( ) { cout" ewodeba "aviRoT nakadidan" da "cin" obieqtTan erTad igi axdens nakadidan im monacemTa aRebas, romelsac momxmarebeli mas awvdis klaviaturis meSveobiT. cout warmodgeba sityvebisgan C (si), output (gamotana) anu "gamotana C-Si", xolo cin - sityvebisgan C (si), input (Setana) anu "Setana C-Si". cout operatorTan xSirad gamoiyeneba nakadis manipulatori endl (end line – niSnavs striqonis, xazis dasasruls), romelic gamoitans ra axal striqonze gadasvlis simbolos, "asufTavebs gamotanis bufers".1

1

buferi – egm-is droebiTi mexsiereba, sadac Tavsdeba moWrili an kopirebuli obieqtebi.

70

Tavi VII mmarTveli struqturebi daprogramebis ena C++-Si gamoiyofa Semdegi mmarTveli struqturebi: 1. mimyoli (wrfivi) struqtura; 2. ganStoebadi (amorCevis) struqtura; 3. cikluri (gameorebis) struqtura. wrfivi struqturis SemTxvevaSi programis yoveli momdevno brZaneba mkacrad sruldeba wina brZanebis Sesrulebis Semdeg. rogorc cnobilia, wrfivi struqturis mqone programebis magaliTebi praqtikaSi mcire raodenobiT moiZebneba. ganStoebadi struqturis dros adgili aqvs programaSi arsebuli brZanebebis Sesrulebis Tanmimdevrobis Secvlas gamomdinare ama Tu im pirobidan, rac iwvevs masSi erTgvar ganStoebebs. C++-Si arsebobs ganStoebadi struqturis ganxorcielebis sami SesaZlebloba:  amorCevis struqtura if (Tu);  amorCevis struqtura if/else (Tu/winaaRmdeg SemTxvevaSi);  amorCevis struqtura switch (amorCeva). programuli kodis ama Tu im fragmentis mravaljerad gameorebas cikli ewodeba. igi SeiZleba iyos: ariTmetikuli da iteraciuli. ariTmetikul ciklSi gameorebaTa ricxvi winaswaraa cnobili. aq ciklis mmarTveli parametris (mTvlelis) sawyisi da saboloo mniSvnelobebi, aseve misi cvlilebis biji winaswar gansazRvrulia da moicema cxadi saxiT. iteraciul ciklebSi, ki gameorebaTa ricxvi ucnobia da ciklis mmarTveli parametri SeiZleba arc iyos cxadi saxiT warmodgenili. C++-Si ganixileba cikluri struqturebis sami saxe:  cikli while (manamde, sanam); 71

 cikli do/while (cikli/manamde, sanam);  cikli for (cikli). rodesac cikluri procesi grZeldeba usasrulod (ganusazRvreli drois manZilze), programistebi am process programis Caciklvas uwodeben, xolo Tavad cikls aRniSnul SemTxvevaSi usasrulo cikli ewodeba. C++-Si Tavs iCens Calagebuli ciklebic. es is SemTxvevaa, rodesac erTi ciklis tanSi Tavsdeba sxva ciklis tani. cikls, romelSic sxva cikli Tavsdeba, gare cikli ewodeba, xolo gare ciklis tanSi moTavsebul cikls – Sida cikli. Cvens mier ganxiluli sityvebi: if, else, switch, while, do, for warmoadgenen daprogramebis ena C++-is sakvanZo (kodur) sityvebs. isini Cadebulia aRniSnuli enis safuZvlebSi da gamoyenebas hpovebs mis mmarTvel struqturebSi. ganvixiloT wrfivi struqturis mqone programaTa magaliTebi C++-Si. magaliTi 7.1. SevadginoT programa, romelic gamoTvlis Z cvladis mniSvnelobas, Tu: 2

z  y  x; y  1  x 

sin x 1  ln( x  1)

; sadac x=0,8.

amoxsna: // z cvladis mniSvnelobis gamoTvla #include #include main( ) { double z, y, x=0.8; y=sqrt(1+x)+sin(x)/(1+log(x+1)); z=pow(y,2)+x; cout
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF