Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 15

mecadineoba # 5

praqtikuli mecadineobis Temebi: laboratoriuli mecadineobis Temebi:


 while Setyobineba  failidan ricxvebis, striqonebis da
 veqtoris (vector) template- simboloebis wakiTxva
specializaciebi sxvadasxva tipisTvis  programis Sedegis failSi gamotana
amocanebi: amocanebi:
1. ricxvebis Cawera klaviaturidan veqtorSi
>>> 1. sami simbolos gadawera erTi failidan meoreSi
Sebrunebuli rigiT >>>
2. ricxvebis Cawera veqtorSi da maTi jamis
2. erT failSi Cawerili ricxvebis saSualo
gamoTvla >>>
ariTmetikulis dabeWdva sxva failSi >>>
3. amocana sort algoriTmis gamoyenebaze >>> 3. gvaris da saxelis gadawera erTi failidan
4. stringebis Cawera klaviaturidan vetorSi >>> meoreSi Sebrunebuli rigiT >>>
damoukidebeli samuSao >>> 4. erTi failidan meoreSi garkveuli Tvisebis mqone
ricxvebis gadawera >>>
damoukidebeli samuSao >>>

masala damoukideblad gacnobisaTvis:


1. magaliTebi while Setyobinebis gamoyenebaze:
# programis fragmenti Sedegi
1 int counter = 0;
while ( counter < 3 ){ Hello, Students!
cout << "Hello, Students!\n"; Hello, Students!
counter++; Hello, Students!
}
2 int number = 1;
while ( number <= 3 ){ number = 1
cout << "number = " << number << endl; number = 2
number++; number = 3
}
char aso = 'F';
while ( aso >= 'A' ){
3 cout << aso << ' '; F E D C B A
aso--;
}
while ( true ) //piroba yovelTvis WeSmaritia: //procesi ar
4
cout << "usasrulo ganmeoreba\n"; dasruldeba
int n = 7;
while ( true ){ n = 7
cout << "n = " << n <<endl; n = 6
5
n--; n = 5
if(n == 4) break;
}
int n = 2;
while ( n <= 6 ){ n = 2
6 cout << "n = " << n <<endl; n = 4
n += 2; n = 6
}
int n = 2;
while ( true ){ n = 2
cout << "n = " << n << endl; n = 4
7
if(n == 6) break; n = 6
n += 2;
}

კ. გელაშვილი, ი. ხუციშვილი 35
int counter = 1;
double x = 1.2; 1.2
while ( true ){ 1.3
cout << x << endl; 1.4
8
x += 0.1; 1.5
if(counter == 5) break; 1.6
counter ++;
}
while ( false ) ar Sesrulda
9 cout << "Sesruldeba?\n"; // piroba Tavidanve mcdaria:
cout << "ar Sesrulda\n"; //Setyobineba ar Sesruldeba

2. magaliTebi vector –is sxvadasxva specializaciis gamoyenebaze:


# programis fragmenti Sedegi
1 cout << "test #1 of vector" << endl; //carieli veqtori
vector<int> vect1; test #1 of vector
cout << "size of vect1 : " << vect1.size() size of vect1 : 0
<< endl;
2 cout << "test #2 of vector" << endl;
vector<int> vector1; test #2 of vector
//or elements vamatebT veqtorSi first element :7777
vector1.push_back(7777); second element :2345
vector1.push_back(2345);
cout << "first element is :" << vector1[0]
<< endl;
cout << "second element is :" << vector1[1]
<< endl;
cout << "test #3 of vector" << endl; //sami elementis adgili //ijavSneba
vector<int> vector1(3); da ivseba nulebiT
cout << "vector1.size() = " << vector1.size() test #3 of vector
<< endl; vector1.size()= 3
cout << "first element is:" << vector1[0] first element is:0
<< endl; second element is:0
3
cout << "second element is:" << vector1[1] 3-th element is:0
<< endl; //Debug Assetion
cout << "3-th element is:" << vector1[2] // Failed!
<< endl; // Expression: vector
cout << "4-rd element is:" << vector1[3] // subscript out of
<< endl; // range
cout << "test #4 of vector" << endl;
vector<double> vector1(2); test #4 of vector
vector1[0] = 11.11; first element: 11.11
vector1[1] = 22.22; second element: 22.22
4
cout << "first element: " << vector1[0]
<< endl;
cout << "second element: " << vector1[1]
<< endl;
cout << "test #5 of vector" << endl;
vector<double> vector1(2); test #5 of vector
vector1[0] = 11.1; vector1[0] = 11.1
vector1[1] = 22.2; vector1[1] = 22.2
vector1.push_back(77.77); vector1[2] = 77.77
5
vector1.push_back(23.45); vector1[3] = 23.45
cout << "vector1[0] = " << vector1[0] << endl;
cout << "vector1[1] = " << vector1[1] << endl;
cout << "vector1[2] = " << vector1[2] << endl;
cout << "vector1[3] = " << vector1[3] << endl;
6 cout << "test #6 of vector" << endl;
string str;
vector<string> a(2); test #6 of vector
a[0] = "Good "; Good By
a[1] = "By";
კ. გელაშვილი, ი. ხუციშვილი 36
str = a[0] + ' ' + a[1];
cout << str << endl;
cout << "test #7 of vector" << endl;
string str;
vector<string> vctr; test #7 of vector
7 vctr.push_back("Good"); Good By!
vctr.push_back("By!");
str = vctr[0] + ' ' + vctr[1];
cout << str << endl;

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++;
}
}
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;
while(i < v.size()){
sum += v[i];

კ. გელაშვილი, ი. ხუციშვილი 37
i++;
}
cout << "jami = " << sum << endl;
}

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;


}
programis Sesrulebis Sedegia:
9 14 0 -3 27 -15 8 9 25 *
udidesi = 27
Press any key to continue . . .

#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());

}
number = 0;
while ( number < v.size() )
{
cout << v[number] << endl;
number ++;
cout << endl;
}

კ. გელაშვილი, ი. ხუციშვილი 38
<<< 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()){


a plan a map a dog
if(sentence[i-1] != sentence[i]) ^Z
Number of words = 6
cout << sentence[i] << endl; a
dog
++i; map
}
}
plan
Press any key to continue . . .
programis Sesrulebis Sedegia:

შეგვეძლო ესეც გაგვეკეთებინა ალგორითმის გარეშე:


#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;


int i(0);

while (i < sentence.size()) {


cout << sentence[i] << endl;
++i;
}
}

კ. გელაშვილი, ი. ხუციშვილი 39
<<< 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;

2. gaarCieT programa, romelic "temperature.in" failidan Semotanil saSualo Tviuri


temperaturis 12 maCveneblis (Tveebis) mixedviT beWdavs weliwadis saSualo temperaturas.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
double temps, S = 0;
ifstream fin ("temperature.in");
while( fin >> temps )
S += temps;
cout << "sashualo temperatura = "<< S/12 <<endl;
}
programis Sesrulebis Sedegia:
temperature.in faili gamosatani ekrani
12.5 15 14.5 16 18 25.5 35 32.5 34.5 sashualo temperatura = 22.375
28 20 17 Press any key to continue . . .

3. gaarCieT programa, romelic klaviaturidan Semotanil striqonSi iTvalis aso 'a'–s raodenobas.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string Str;
int counter(0), i(0);
char a;

კ. გელაშვილი, ი. ხუციშვილი 40
getline(cin, Str);
while (i < Str.size())
{
if (Str[i] == 'a')
counter++;
++i;
}
cout << "striqonSi aris " << counter
<< " aso 'a' " << endl;
}
a man a cat a dog
programis Sesrulebis Sedegia: striqonSi aris 5 aso 'a'
Press any key to continue . . .
eqsperimentebi:
a). SeasruleT programa ramdenime gansxvavebuli striqonisTvis da darwmundiT miRebuli
Sedegebis sisworeSi;
b). programaSi getline(cin, Str); Setyobineba SecvaleT cin >> Str; – iT da isev
SeasruleT programa. SegeqmnaT problema?
daimaxsovreT: Tu striqoni Sedgeba ramodenime sityvisagan (anu Seicavs sityvebis gamyofebs
- haris an/da tabulaciis - simboloebs) klaviaturidan mis Sesatanad gamoiyeneba funqcia
getline formatiT getline(cin, <striqonis saxeli>), radgan cin >> <striqonis saxeli>
-is SemTxvevaSi waikiTxeba mxolod pirveli sityva (pirvelive gamyof simbolomde).
4. klaviaturidan SeitaneT mTeli ricxvebi, CawereT saTanado veqtorSi da Semdeg dabeWdeT maTi
jamis meoTxedi.

vector<int> v;
int x(0);
double s(0);

while (cin >> x) {


v.push_back(x);

s += x;

}
cout << "meotxedia " << s / 4;

5. klaviaturidan SeitaneT mTeli ricxvebi, CawereT saTanado veqtorSi da Semdeg dabeWdeT maTi
saSualo ariTmetikuli.

vector<int> v;
int x(0);
double s(0);

while (cin >> x) {


v.push_back(x);
s += x;
}
cout << "sashualoa " << s / v.size();

6. klaviaturidan SeitaneT simboloTa mimdevroba, CawereT saTanado veqtorSi da Semdeg


dabeWdeT Setanili simboloebis raodenoba.

char symbol;
vector<char> v;
int i;

while (cin >> symbol) {


კ. გელაშვილი, ი. ხუციშვილი 41
v.push_back(symbol);
}
i = 0;

while (i < v.size()) {


i++;
}
cout << "raodenoba simboloebis aris " << i;

7. klaviaturidan SeitaneT 12 mTeli ricxvi da dabeWdeT maTi saSualo ariTmetikuli.

int ricxvi,sum(0),index(0);
vector<int> vect;

while (index < 12) //index kovel jerze ertit izrdeba


{
cin >> ricxvi;
vect.push_back(ricxvi);
sum += ricxvi;
index ++;
}
cout << "12 ricxvis sashualoa " << sum /12.<<endl;
}
8 . klaviaturidan SeitaneT teqsti – wertiliT damTavrebuli ramodenime winadadeba, pirvel
*

winadadebaSi daadgineT: 'a' simbolo gvxvdeba metad Tu 'b'.

using namespace std;


int main()
{
string text;
char a,b;
int counter1(0), counter2(0),index(0);

cin >> text;


while (index<text.size())
{
if (text[index] == 'a')
counter1++;
else if (text[index] == 'b')
counter2++;
++index;
}
cout << "a = " << counter1 << " b = " << counter2 << endl;

9. klaviaturidan SeitaneT ricxvebis raodenoba - m, Semdeg m cali mTeli ricxvi da dabeWdeT maTi
namravli.

int m(0), nam(1);


vector<int>v;

while (cin>>m)
{
v.push_back(m);
nam *= m;
}
cout << nam << endl;

კ. გელაშვილი, ი. ხუციშვილი 42
10. klaviaturidan SeitaneT mTeli ricxvi m, Semdeg dabeWdeT m ricxvis faqtoriali. ra saxis
problema SeiZleba SegeqmnaT?

#include <iostream>;
#include <vector>;
#include<string>;

using namespace std;


int main()
{
int m(0), factor(1), index(0);
vector<int>v;

cin >> m;

while (m>0)
{
v.push_back(m);
m=m-1;
index++;
}

index = 0;
while (index < v.size())
{

factor *=v[index];
cout << factor << endl;
index++;

}
}

#include <iostream>;
#include <vector>;
#include<string>;

using namespace std;


int main()
{
int m(0), factor(1), index(0);
vector<int>v;
vector<int>p;

cin >> m;

while (m>0)
{
v.push_back(m);
m=m-1;
index++;
}

index = 0;
while (index < v.size())
{
factor *= v[index];
p.push_back(factor);
index++;

cout << p[p.size() - 1] << endl;


}

კ. გელაშვილი, ი. ხუციშვილი 43
}

#include <iostream>
#include <vector>
#include<string>

using namespace std;


int main()
{
int m(0), factor(1);
unsigned int i = 0;
vector<int>v;

cin >> m;

while (m > 0)
{
v.push_back(m);
m = m - 1;
}
while ( i < v.size())
{
factor *= v[i];
i++;
}
cout << factor << endl;
}

11*. auditoriuli samuSaos meoTxe amocanaSi, sentence.push_back(word); Setyobinebis nacvlad


jobia vweroT: sentence.push_back(move(word)); es imitom, rom word lokaluri cvladis
mimdinare mniSvneloba metad aRar gamoiyeneba da SegviZlia igi gamovacxadiT
sentence-is bolo elementad, nacvlad aslis gakeTebisa. gansxvavebis dasanaxad, igive
programa gavuSvaT orjer, Semdegi CanacvlebebiT:
while (cin >> word)
{
sentence.push_back(word); cout << word;
}

da
while (cin >> word)
{
sentence.push_back(move(word)); cout << word;
}

SevniSnoT, rom move–is gamoyenebas azri ara aqvs primitiuli tipebisTvis.


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
vector<string> sentence;

string word;

კ. გელაშვილი, ი. ხუციშვილი 44
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;

++i;
}
}

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
-> Utility -> 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 <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;
}
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.

კ. გელაშვილი, ი. ხუციშვილი 45
<<< amocana 2. monacemebi.in failSi Cawerilia 3 mTeli ricxvi. pasuxi.out failSi
dabeWdeT am ricxvebis saSualo ariTmetikuli.
Sesabamis programas aqvs saxe:
/////////////////////////////////////////////////
// პროგრამა: ფაილიდან წაკითხული მთელი რიცხვების
// საშუალო არითმეტიკულის სხვა ფაილში ბეჭდვა
/////////////////////////////////////////////////
#include <fstream>
using namespace std;
int main()
{
int a, b, c;
double average;
ifstream fin( "monacemebi.in" );
fin >> a >> b >> c;
average = (a + b + c)/3.;
ofstream fout( "pasuxi.out" );
fout << a << ' ' << b << ' ' << c
<< " ricxvebis sashualo ariTmetikuli = "
<< average;
}

SeasruleTprograma ramdenimejer ricxvTa sxvadasxva sameulebisaTvis. SeamowmeT


pasuxi.out failSi miRebuli Sedegebi.

#include <fstream>
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
double average;
ifstream fin("monacemebi.in");
fin >> a >> b >> c;
average = (a + b + c) / 3.;
ofstream fout("pasuxi.out");
fout << a << ", " << b << " da" << c
<< " ricxvebis sashualo ariTmetikuli = "
<< average;
cout << a << ", " << b << " da" << c
<< " ricxvebis sashualo ariTmetikuli = "
<< average<<endl;
}

<<< 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 <fstream>
#include <string>
using namespace std;
int main()
{
კ. გელაშვილი, ი. ხუციშვილი 46
string saxeli, gvari;
ifstream fin("input.in");
ofstream fout("output.out");
fin >> gvari >> saxeli;
fout << saxeli << endl << gvari;
fin.close();
fout.close();
}
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 <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;
if(ricxvi >= 10 && ricxvi <= 30) fout << ricxvi << endl;
fin >> ricxvi;
if(ricxvi >= 10 && ricxvi <= 30) fout << ricxvi << endl;
fin.close();
fout.close();
}

#include <fstream>
#include <iostream>
using namespace std;
int main()
{
int ricxvi;
ifstream fin("monacemebi.in");
ofstream fout("shedegi.txt");
int mtv(0);

while(mtv<12){

fin >> ricxvi;


if (ricxvi >= 10 && ricxvi <= 896)
fout << ricxvi << endl;
mtv++;
}

fin.close();
fout.close();

კ. გელაშვილი, ი. ხუციშვილი 47
}
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.
char a,b,c;
ifstream read("input.in");
ofstream write("output.in");

read >> a >> b >> c;

if (a < b && a < c)


write << a << (int)a;

else if (b < a && b < c)


write << b << (int)b;
else
write << c << (int)c;

2. mocemuli faili Sedgeba 2 striqonisgan. TiToeulSi Cawerilia mTeli ricxvi. meore failSi
CawereT am ricxvebis
a) jami;

int line1, line2, sum, namravli, index(0);


double progresia;
ifstream read("input.in");
ofstream write("output.in");

read >> line1 >> line2;


write << line1 + line2;

b) namravli;

read >> line1 >> line2;


write << line1 *line2;

g) saSualo geometriuli (miTiTeba: a1 , a 2 , . . . , a n ricxvebis saSualo geometriuli


gamoiTvleba Semdegi formuliT: saSualo geometriuli  n a1  a 2    a n ).

read >> line1 >> line2;


write << sqrt(line1 * line2);

3. mocemuli faili Seicavs striqons. meore failSi CawereT am striqonis sigrZis mniSvneloba.

კ. გელაშვილი, ი. ხუციშვილი 48
string striqoni;

ifstream read("input.in");
ofstream write("output.in");

read >> striqoni;


write << striqoni.size();

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 <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;
}
programis muSaobis Sedegia:
faili weight.in faili price.in faili answer.out
100 50.5 200 3.5 10 7.5 2355

5. daaprogrameT praqtikuli mecadineobis amocanebi. Semdeg, ganxilul amocanebSi


ganacxadi vector<T> SecvaleT deque<T> -Ti, gamocvaleT biblioTekis failis saxelic da
SeadareT Sesrulebis Sedegebi.

კ. გელაშვილი, ი. ხუციშვილი 49

You might also like