Mecadineoba # 6: 1. Magalitebi Setyobinebis Gamoyenebaze: Programis Fragmenti Sedegi
Mecadineoba # 6: 1. Magalitebi Setyobinebis Gamoyenebaze: Programis Fragmenti Sedegi
კ. გელაშვილი, ი. ხუციშვილი 45
davbeWdoT veqtoris elementebi Sebrunebuli
rigiT*/ Elene
vector<string> words; Giorgi
words.push_back("Mariam"); Mariam
words.push_back("Giorgi");
words.push_back("Elene");
for(int i=words.size()-1; i>=0; i-- )
cout << words[i] << endl;
/* veqtorSi CavweroT sami namdvili ricxvi,
Semdeg daviTvaloT da davbeWdoT maTi jami */
vector<double> reals; jami = 8
reals.push_back(2.25);
4 reals.push_back(10.75);
reals.push_back(-5);
double sum =0;
for(int k=0; k<reals.size(); ++k )
sum += reals[k];
cout << "jami = " << sum << endl;
/* veqtorSi CavweroT 5 SemTxveviTi ricxi da
Semdeg davbeWdoT veqtoris elementebi*/
vector<int> vec; 41
int number; 18467
5 for(int count=1; count<=5; count++){ 6334
number =rand(); 26500
vec.push_back(number); 19169
}
for(int i=0; i<vec.size(); i++ )
cout << vec[i] << endl;
saauditorio samuSao:
<<< 1. veqtorSi CavweroT pirveli 10 naturaluri ricxvis kvadrati da Semdeg
davbeWdoT es veqtori.
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> vec;
for(int n=1; n<11; n++)
vec.push_back(n * n);
for(int i=0; i<vec.size(); i++)
cout << vec[i] << '\t';
cout<<endl;
//system("pause");
return 0;
}
programis Sesrulebis Sedegia:
1 4 9 16 25 36 49 64 81 100
Press any key to continue . . .
კ. გელაშვილი, ი. ხუციშვილი 48
}
cout << "s = " << s << '\n';
//system("pause");
return 0;
}
P programis Sesrulebis Sedegia:
s = 554810
Press any key to continue . . .
კ. გელაშვილი, ი. ხუციშვილი 50
laboratoriuli samuSao:
<<< amocana 1. SeqmeniT programa, romelic dabeWdavs sam striqons. pirvel striqonsi
daibeWdeba sami SemTxveviTi mTeli ricxvi, meoreSi - sami SemTxveviTi mTeli ricxvi
[0;100] Sualedidan, xolo mesameSi – sami SemTxveviTi namdvili ricxvi, aRebuli
[0.,1.0] Sualedidan.
Sesabamis programas aqvs saxe:
////////////////////////////////////////////
// ავტორი:
// პროგრამა: სამი შემთხვევითი რიცხვების ბეჭდვა
////////////////////////////////////////////
#include <iostream>
using namespace std;
int main(){
cout<<"Random numbers:\n";
cout << rand() << '\t' <<rand() << '\t' << rand() << endl;
cout<<"Random numbers from [0,100]:\n";
cout << rand()%101 << '\t' <<rand()%101 << '\t' << rand()%101
<< endl;
cout<<"Random real numbers from [0.0,1.0]:\n";
cout << (double) rand()/RAND_MAX << '\t'
<< (double) rand()/RAND_MAX << '\t'
<< (double) rand()/RAND_MAX << endl << endl;
//system("pause");
return 0;
}
davaleba: gadawereT programa ise, rom SesaZlebeli gaxdes [0;100] Sualedidan
aRebuli N cali SemTxveviTi ricxvis dabeWdva. N–is mniSvneloba SevitanoT
klaviaturidan.
<<< amocana 2. dawereT programa, romelic beWdavs mimdinare dros wamebSi da wuTebSi.
Sesabamis programas aqvs saxe:
///////////////////////////////////////
// ავტორი:
// პროგრამა: მიმდინარე დროის ბეჭდვა
///////////////////////////////////////
#include <iostream>
#include <ctime>
using namespace std;
int main(){
cout << "mimdinare dro (second): " << time(NULL)<<endl;
cout << "mimdinare dro (minute): " << time(NULL)/60<<endl;
//system("pause");
return 0;
}
davaleba: daamateT programaSi Setyobineba, romelic dabeWdavs mimdinare dros
saaTebSi.
კ. გელაშვილი, ი. ხუციშვილი 51
Sesabamis programas aqvs saxe:
///////////////////////////////////////////////////////////////////////////
// ავტორი: //
// პროგრამა: 10 შემთხვევითი რიცხვის შექმნა, მათი შესაბამისი სიმბოლოების ბეჭდვა //
///////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void printChar(vector<int> );
int main(){
vector<int> vec;
int code;
for(int count=1; count<=10; count++){
code = rand()%(91 -65) + 65;
vec.push_back(code);
}
printChar(vec);
sort( vec.begin(), vec.end() );
printChar(vec);
cout<<"umciresia " <<(char)vec[0]
<< " kodiT " << vec[0] << endl;
//system("pause");
return 0;
}
void printChar(vector<int> m){
for(int i=0; i<m.size(); i++ )
cout << (char)m[i]<<' ';
cout << endl;
}
davaleba: SecvaleT programa ise, rom man dabeWdos SemTxveviTi kodebis mqone
simboloebi dalagebuli klebadobiT.
miTiTeba: sort(vec.begin(), vec.end()); algoriTmi gamoiyeneT sxva saxiT:
sort( vec.rbegin(), vec.rend() );
Sesabamisad SecvaleT umcirebi simbolos da misi kodis beWdvis Setyobinebac.
კ. გელაშვილი, ი. ხუციშვილი 52