Professional Documents
Culture Documents
Mecadineoba # 5: Praqtikuli Mecadineobis Temebi: Laboratoriuli Mecadineobis Temebi
Mecadineoba # 5: Praqtikuli Mecadineobis Temebi: Laboratoriuli Mecadineobis Temebi
saauditorio samuSao:
<<< 1. klaviaturidan SeitaneT 5 mTeli ricxvi da CawereT veqtorSi. Semdeg dabeWdeT
veqtoris elementebi indeqsebis CvenebiT:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> a;
int number, index = 0;
while(index < 5){
cin >> number;
a.push_back(number);
index++;
}
index = 0;
while(index < a.size()){
cout << "a[ " << index << " ] == " << a[index] << endl;
index++;
}
//system("pause");
return 0;
}
programis Sesrulebis Sedegia:
21 7 -100 73 -9
a[ 0 ] == 21
a[ 1 ] == 7
a[ 2 ] == -100
a[ 3 ] == 73
a[ 4 ] == -9
Press any key to continue . . .
<<< 2. klaviaturidan SeitaneT 10 namdvili ricxvi (Setana daamTavreT ’|’ simbolos
akrefiT) da CawereT veqtorSi. Semdeg ipoveT am ricxvebis jami da dabeWdeT.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<double> v;
double x;
while( cin >> x )
v.push_back(x);
double sum =0;
int i = 0;
კ. გელაშვილი, ი. ხუციშვილი 37
while(i < v.size()){
sum += v[i];
i++;
}
cout << "jami = " << sum << endl;
//system("pause");
return 0;
}
programis Sesrulebis Sedegia:
1.2 0.3 12.25 -11.25 3.0 20.5 -10 -5.5 0 2.125 |
jami = 12.625
Press any key to continue . . .
<<< 3. dawereT programa, romelic klaviaturidan Semotanil mTel ricxvebs Soris
ipovis da dabeWdavs udidess.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> v;
int number;
while( cin >> number )
v.push_back( number );
sort( v.begin(), v.end() );
cout << "udidesi = " << v[v.size()-1] << endl;
//system("pause");
return 0;
}
programis Sesrulebis Sedegia:
9 14 0 -3 27 -15 8 9 25 *
udidesi = 27
Press any key to continue . . .
<<< 4. klaviaturidan SemoitaneT winadadeba, romelSic sityvebi gamoyofilia hariT.
Setana daamTavreT axal striqonze Ctrl+z klaviSebis kombinaciis akrefiT. dabeWdeT
sityvebis raodenoba da yvela gansxvavebuli sityva.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
vector<string> sentence;
string word;
while( cin >> word )
sentence.push_back(word);
cout << "Number of words = " << sentence.size() << endl;
sort(sentence.begin(), sentence.end());
cout << sentence[0] << endl;
int i = 1;
while(i < sentence.size()){
if(sentence[i-1] != sentence[i])
cout << sentence[i] << endl;
კ. გელაშვილი, ი. ხუციშვილი 38
++i;
} a plan a map a dog
//system("pause"); ^Z
return 0; Number of words = 6
} a
programis Sesrulebis Sedegia: dog
map
plan
Press any key to continue . . .
<<< damoukidebeli samuSao:
1. ras dabeWdavs Semdegi fragmenti? axseniT da Semdeg SeamowmeT kompiuterze:
# programis fragmenti
int k = 1; char p = 'A';
while( k < 4 ){
1 cout << p++ << endl;
++k;
}
int x = 5;
while ( -25 || 0 ){
2 cout << "ar dasruldeba\n";
x++;
}
int x = 5;
while ( 10 - 10 && x > 7 ) {
3 cout << "ar shesruldeba\n";
x++;
}
int n = 7, s = 30;
while ( true ){
s -= n;
4 n--;
if(n == 4) break;
}
cout << "s = " << s << endl;
int n = 2, p = 1;
while( n <= 7 ){
++n;
5 if( n%2 == 0) continue;
p *= n;
}
cout << "p = " << p << endl;
კ. გელაშვილი, ი. ხუციშვილი 40
laboratoriuli samuSao:
<<< amocana 1. data.txt faili Seicavs 3 simbolos. dabeWdeT es simboloebi
output.txt failSi Sebrunebuli rigiT.
miTiTeba:
SeqmeniT proeqti lp5.1, daamateT faili 5-1.cpp, akrifeT programa.
daamateT proeqtSi teqsturi faili data.txt Semdegi gziT: Project -> Add
New Item -> Text File(.txt); Name velSi CawereT failis saxeli data
(gafarToebis gareSe) da daaWireT Add Rilaks (an Enter -s).
CawereT data.txt failSi 3 simbolo.
Sesabamis programas aqvs saxe:
/////////////////////////////////////////////////
// პროგრამა: ფაილიდან სიმბოლოების წაკითხვა და
// სხვა ფაილში შებრუნებული რიგით ჩაწერა
/////////////////////////////////////////////////
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char a, b, c;
ifstream ifs("data.txt");
ifs >> a >> b >> c;
ofstream ofs("output.txt");
ofs << c << ' ' << b << ' ' << a;
return 0;
}
programis gaSvebis Semdeg lp 5.1 proeqtis Siga lp 5.1 saqaRaldeSi avtomaturad
Seiqmneba output.txt faili. gaxseniT igi (magaliTad, File -> Open -> File an
akrefeT klaviSebis kombinacia Ctrl+o da gaxseniT output.txt faili), gaaanalizeT
programis muSaobis Sedegi. magaliTad,
faili data.txt faili output.txt
XYO O Y X
miTiTeba: erTdroulad gaxsnili ramodenime failis SemTxvevaSi CTRL+F6 klaviSebis
kombinacia axorcielebs gadarTvas maT Soris.
<<< amocana 2. monacemebi.in failSi Cawerilia 3 mTeli ricxvi. pasuxi.out
failSi dabeWdeT am ricxvebis saSualo ariTmetikuli.
Sesabamis programas aqvs saxe:
/////////////////////////////////////////////////
// პროგრამა: ფაილიდან წაკითხული მთელი რიცხვების
// საშუალო არითმეტიკულის სხვა ფაილში ბეჭდვა
/////////////////////////////////////////////////
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int a, b, c;
double average;
ifstream fin( "monacemebi.in" );
fin >> a >> b >> c;
კ. გელაშვილი, ი. ხუციშვილი 41
average = (a + b + c)/3.;
ofstream fout( "pasuxi.out" );
fout << a << ' ' << b << ' ' << c
<< " ricxvebis sashualo ariTmetikuli = "
<< average;
return 0;
}
SeasruleT programa ramdenimejer ricxvTa sxvadasxva sameulebisaTvis. SeamowmeT
pasuxi.out failSi miRebuli Sedegebi.
<<< amocana 3. input.in failis pirvel striqonSi Cawerilia studentis gvari,
meoreSi ki – misi saxeli. output.out failis pirvel striqonSi CawereT am
studentis saxeli, meoreSi ki gvari.
Sesabamis programas aqvs saxe:
//////////////////////////////////////////////
// პროგრამა: ფაილიდან წაკითხული სტრიქონების
// შებრუნებული რიგით ბეჭდვა სხვა ფაილში
//////////////////////////////////////////////
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string saxeli, gvari;
ifstream fin("input.in");
ofstream fout("output.out");
fin >> gvari >> saxeli;
fout << saxeli << endl << gvari;
fin.close();
fout.close();
return 0;
}
davaleba: gaarkvieT ra moxdeba, Tu input.in failSi gvari da saxeli Cawerilia erT
striqonSi, gamoyofilia hariT da gvinda davbeWdoT gvari da saxeli output.out
failSi Sebrunebuli rigiT: a). erT striqonad; b) or striqonad.
<<< amocana 4. ricxvebi.txt failSi Cawerilia 3 mTeli ricxvi. shedegi.txt
failSi gadaitaneT mxolod is ricxvebi, romlebic ekuTvnis [10,30] Sualeds.
Sesabamis programas aqvs saxe:
////////////////////////////////////////////////////////////////
// პროგრამა: ფაილის სტრიქონებში მოცემული რიცხვებიდან
// [10,30] შუალედში მოთავსებული რიცხვების სხვა ფაილში ბეჭდვა
////////////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
using namespace std;
int main(){
int ricxvi;
ifstream fin( "ricxvebi.txt" );
ofstream fout( "shedegi.txt" );
fin >> ricxvi;
if(ricxvi >= 10 && ricxvi <= 30) fout << ricxvi << endl;
fin >> ricxvi;
კ. გელაშვილი, ი. ხუციშვილი 42
if(ricxvi >= 10 && ricxvi <= 30) fout << ricxvi << endl;
fin >> ricxvi;
if(ricxvi >= 10 && ricxvi <= 30) fout << ricxvi << endl;
fin.close();
fout.close();
return 0;
}
davaleba:
1. SeasruleT programa da gaaanalizeT shedegi.txt faili.
2. gadawereT programa ganmeorebis Setyobinebis gamoyenebiT, SeasruleT igi da
gaaanalizeT Sedegi. miTiTeba: programaSi 3 –jer gameorebuli Setyobinebebi
fin >> ricxvi;
if(ricxvi >=10 && ricxvi <=30) fout << ricxvi << endl;
SecvaleT Semdegi fragmentiT:
int mTvleli = 1;
while( mTvleli <= 3 ){
fin >> ricxvi;
if(ricxvi >= 10 && ricxvi <= 30) fout << ricxvi << endl;
mTvleli++;
}
<<< damoukidebeli samuSao:
1. mocemuli faili Seicavs 3 simbolos. daadgineT simboloTa Soris umciresi da
dabeWdeT es simbolo da misi kodi sxva failSi.
2. mocemuli faili Sedgeba 2 striqonisgan. TiToeulSi Cawerilia mTeli ricxvi. meore
failSi CawereT am ricxvebis
a) jami;
b) namravli;
g) saSualo geometriuli (miTiTeba: a1 , a2 , . . . , an ricxvebis saSualo geometriuli
gamoiTvleba Semdegi formuliT: saSualo geometriuli n a1 a 2 a n ).
3. mocemuli faili Seicavs striqons. meore failSi CawereT am striqonis sigrZis
mniSvneloba.
4. erT failSi, saxelad weight.in weria sami saxis produqtis wona. meore failSi,
saxelad price.in weria am produqtebis fasebi. mesame failSi gamoitaneT
mocemuli raodenobis produqtebis SeZenaze daxarjuli Tanxis odenoba.
gaarCieT da gaaanalizeT Sesabamisi C++–programa:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
double a, b, c(0);
ifstream ifs1("weight.in");
ifstream ifs2("price.in");
while( ifs1 >> a, ifs2 >> b ) c += a*b;
ofstream ofs("answer.out");
ofs << c;
return 0;
}
programis muSaobis Sedegia:
faili weight.in faili price.in faili answer.out
100 50.5 200 3.5 10 7.5 2355
კ. გელაშვილი, ი. ხუციშვილი 43