180 likes | 390 Views
daprogramebis safuZvlebi leqcia #1. 2009-2010 sasw.w. I semestri Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba. 1. ras warmoadgens C. ra aris programireba rogor muSaobs C rogor SeviswavloT C programebi-amocanis dasmidan Sesrulebamde
E N D
daprogramebis safuZvlebileqcia #1 2009-2010 sasw.w. I semestri Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba
1. ras warmoadgens C • ra aris programireba • rogor muSaobs C • rogor SeviswavloT C • programebi-amocanis dasmidan Sesrulebamde • programis Seqmna integrirebul garemoSi
ra aris programireba C enis ZiriTadi funqciaa programistsa da kompiuters Soris urTierTobis damyareba manqanuri enis instruqcia - 0 da 1 asembleri (instruqciebis krebuli) Targmna programa (assembly language) MOV A,47 1 ADD A,B HALT . . . • igive programamanqanur enaze • 010 1111 • 0011 0111 • 0111 0110 • . . .
rogor muSaobs C C-is popularobis mizezebi: moqniloba gadatanadoba kompiuteruli programa monacemebi (data) instruqciebi (instructions)
monacemebi • mexsierebis erTeuli-baiti (8 biti) • monacemi-baitebis mimdevroba • aRiweros monacemi int total/* angariSebis jami */ int balance[100] /* balansi 100 angariSisTvis */ struct rectangle { int width; /* marTkuTxedis sigane piqselebSi */ int height; /* marTkuTxedis simaRle piqselebSi */ color_type color /* marTkuTxedis feri */ fill-type fill; /* Sevsebis wesi */ };
instruqciebi • miniWebis Setyobineba (assignment statement) area=(base * height)/2.0; /* samkuTxedis farTobis gamoTvla */ • marTvis Setyobinebebi: pirobiTi (if, switch) ganmeorebiTi (while, for) • funqciebi-Setyobinebebis jgufi • funqciaTa jgufi–sawyisi faili (sourse file)
maRali donis kodi kompileri instruqciebis krebulis ena asembleri saboloo kodi amkinZavi programa biblioTeka Sesrulebadi programa rogor SeviswavloT Cprogramebi-amocanis dasmidan Sesrulebamde
programis Seqmna integrirebul garemoSi integrebul garemo (IDE) Seicavs teqstur redaqtors, sxvadasxva menius, marTvis Rilakebs da a.S. Dev-C++
2. stili • ra aris stili • komentarebi • programis kodis wera: gavrcelebuli midgomebi • stili Tu kulti? • kodis formatireba wanacvlebis saSualebiT • sicxade da simartive
komentarebi /************************************************ * hello -- program to print out "Hello World". * * Not an especially earth-shattering program * * Author: Steve Oualline. * * * * Purpose: Demonstration of a simple program. * * * Usage: * * Runs the program and the message appears. * *************************************************/ #include <stdio.h> #include <stdlib.h> int main() { /* Tell the world hello */ printf("Hello World\n"); system (“PAUSE”); return (0); }
/******************************** ********************************* * gafrTxileba:es aris gamafrTxilebeli * * gzavnilis magaliTi, romelic * * programistis yuradRebas miiqcevs * ************************************ ***********************************/
/*----------> sxva, naklebad mniSvnelovani Setyobineba <--------*/ /*>>>>>>>>>>>> mTavari seqciis saTauri <<<<<<<<<<<<<<< */ /******************************************************** * Cven viyenebT CarCoSi Casmul komentarebs programis * * seqciis dasawyisis aRniSvnisaTvis * ********************************************************/ /*------------------------------------------------------*\ * es aris CarCos daxatvis sxva xerxi * \*------------------------------------------------------ */ /* * es aris seqciis dasawyisi * ^^^^ ^^ ^^^ ^^^^^^^^^ ^^ ^ ^^^^^^^ * Semdeg paragrafSi Cven avxsniT, ras warmoadgens seqcia * * da rogor muSaobs igi */ /* * saSualo donis komentari, romelic exeba programis * * momdevno ramodenime striqons. Tumca Cven ar gvaqvs msxvili Srifti, * Cven mainc SegviZlia **gamovyoT** sityvebi */ /* martivi komentari, romlebic exeba programis momdevno striqons*/
kodis formatireba wanacvlebis saSualebiT /************************************************** * programa gamoicnobs udris Tu ara ricxvi 5-s * * Author: Irina * *************************************************/ #include <stdio.h>/* standartuli Setana-gamotanis biblioTekis CarTva */ #include <stdlib.h> /* standartuli funqciebis biblioTekis CarTva */ int main() /* mTavari funqcia */ { int a; /* ganacxadi mTel ricxvze */ a=5;/* a-sTvis 5-is miniWeba */ /* amorCeva: ricxvis 5-Tan Sedareba */ if( a == 5 )/* Tu a udris 5-s, maSin */ { printf("Hello,\n"); /*ekranze gamoCndeba gzavnili Hello da*/ printf("a = 5\n"); /*Semdeg striqonSi gzavnili a = 5 */ } else /* Tu a ar udris 5-s, maSin */ { printf("I'm Program\n"); /*ekranze daibeWdeba I'm Program da */ printf("I know, a isn’t 5\n"); /*Semdeg striqonSi: I know, a isn’t 5*/ } system (“PAUSE”); /* ekranis gasaCereblad */ return 0; }
arsebobs wanacvlebis ori ZiriTadi stili. pirveli _ mokle formaa: int main() { int a; a=5; if( a == 5 ) { printf("Hello,\n"); printf("a = 5"); } else { printf("I'm Program\n"); printf("I know, a isn’t 5"); } system (“PAUSE”); return 0; }
meore stili figurul frCxilebs calke striqonebze svams: int main() { int a; a=5; if( a == 5 ) { printf("Hello,\n"); printf("a = 5"); } else { printf("I'm Program\n"); printf("I know, a isn’t 5"); } system (“PAUSE”); return 0; }
sicxade da simartive /* arcTu saukeTeso programa */ temp = x1; x1 = x2; x2 = temp; temp = y1; y1 = y2; y2 = temp;
/* * adgili gavucvaloT(swap) AdaB-s */ /* Xkoordinatebis gacvla*/ temp = x1; x1 = x2; x2 = temp; /* Ykoordinatebis gacvla*/ temp = y1; y1 = y2; y2 = temp;
programis daweris wesebi • ecadeT, Tqvens programas ar hqondes rTuli logika. dayaviT calkeul procedurebad da SeamcireT sirTulis xarisxi • grZel instruqciebs Tavi aarideT-programa ase ufro advili aRsaqmeli iqneba • ecadeT Tqveni programa iyos rac SeiZleba martivi da naTeli