Muhammad Al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti AKT sohasida iqtisodiyot va menejment fakulteti SWD001-1 guruh talabasi Olimova Barchinoyning Dasturlash II fanidan 2-amaliyot ishi.
Amaliyot ishi №2.
STL kutubxonasi.
Konteynerlar. Array, vektor, ro'yxat, deque konteynerlar.
Vazifa .Quyidagilarni bajaring:
1. Vazifa variantiga muvofiq konteyner ob'ektini yarating va uni tasodifiy sonlar
generatori yordamida belgilangan miqdor va oraliqdagi ma'lumotlar bilan
to'ldiring, uning turi vazifa varianti bilan belgilanadi.
2. Konteynerni aniqlash.
3. Elementni olib tashlash orqali konteynerni o'zgartiring (tab.ga qarang).
4. Keyin elementni oxiriga qo'shing (tab.ga qarang).
5. Konteyner elementlariga kirish uchun iteratorlardan foydalaning.
6. Birinchi konteynerni undan N-7 elementlarni berilgan N gacha (agar N>8
bo‘lsa) yoki berilgan N dan keyin N+3 elementlarni chiqarib o‘zgartiring.
7. Xuddi shu sinfdagi ikkinchi konteyner yarating (6-bosqich tugagandan so'ng 1-
o'lchov bilan) va uni birinchi konteyner bilan bir xil turdagi ma'lumotlar bilan
to'ldiring.
8. Ikkala konteynerni solishtiring.
9. Kichigi kattasining oxiriga qo'shiladi.
10. Ikkala konteynerni ham iteratorlar orqali tashkil qiling
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include
#include
#include
#include
using namespace std;
int main()
{
vector v1;
vector v3;
vector::iterator iter;
int n;
for(int i=0; i<25; i++){
n=rand()%200-100;
// cout << n << " ";
v1.push_back(n);
v3.push_back(n);
}
cout<for(iter = v1.begin();iter!=v1.end();iter++){
cout << *iter << " ";
}
iter = v1.begin();
advance(iter,10);
v1.erase(iter);
cout<for(iter = v1.begin();iter!=v1.end();iter++){
cout << *iter << " ";
}
iter=v1.begin();
auto min=*iter;
for(iter=v1.begin();iter != v1.end();iter++){
if(min > *iter){
min = *iter;
}
}
v1.push_back(min);
cout<for(iter = v1.begin();iter != v1.end();iter++){
cout << *iter << " ";
}
iter=v1.begin();
advance(iter,12-7);
v1.erase(iter,v1.begin()+12);
cout<for(iter = v1.begin();iter != v1.end();iter++){
cout << *iter << " ";
}
cout<vector v2;
vector::iterator iter2;
v2.swap(v1);
cout<for(iter2 = v2.begin();iter2 != v2.end();iter2++){
v2.push_back(*iter);
}
for(iter = v2.begin();iter != v2.end();iter++){
cout << *iter << " ";
}
cout<if(v1 == v2){
cout<<"konteynerlar bir xil"<}
else if(v1 > v2){
for(iter = v1.begin();iter != v1.end();iter++){
v1.push_back(v2.at(*iter2));
}
}
// else if(v1 < v2){
// v2.assign(v2.end(),v1);
// for(iter = v2.begin();iter != v2.end();iter++){
// cout << *iter << " ";
// }
// }
return 0;
}
Dostları ilə paylaş: |