Muhammad Al-Xorazmiy nomidagi Toshkent Axborot Texnologiyalari universiteti Telekommunikatsiya texnologiyalari fakulteti 413-20 guruh talabasi Abdullayev Suhrobjonning Dasturlash 2 fanidan 2-labaratoriya ishisi.
2-variant.
2)
Yangi konteynerlar hosil qiling, uni standart funksiyalar yordamida elementlar bilan to’lating find funksiyasi yordamida amallar bajaring;
Iteratorlardan foydalanib deque konteyneri ustida amallar bajaring;
malloc () funksiyasidan foydalanib xotirani dinamik taqsimlashni amalga oshiring.
a)Find funkisyasini qo’llab ko’ramiz.
Dastur Kodi.
//a)Yangi konteynerlar hosil qiling, uni standart funksiyalar yordamida elementlar bilan to’lating
//find funksiyasi yordamida amallar bajaring;
//Abdullayev Suhrob 413-20 || itarotorlar bo'yicha find funksiyasini qo'llab ko'ramiz.
#include
#include
#include
#include
using namespace std;
int main() {
vector v;
for (int i = 0; i < 10; i++) {
v.push_back(rand() % 100);
}
for (vector::iterator it = v.begin(); it != v.end(); it++) {
cout << *it << endl;
}
cout << "Nusxalashni o'rnatish...... " < sets;
copy(v.begin(), v.end(), inserter(s, s.begin()));
for (set::iterator it = s.begin(); it != s.end(); it++) {
cout << *it << endl;
}
vector::iterator it;
cout << "Find " << endl;
it = find(v.begin(), v.end(), 41);
cout << *it << endl;
sort(v.begin(), v.end());
for (vector::iterator it = v.begin(); it != v.end(); it++) {
cout << *it << endl;
}
}
b) Deque containerini sinab ko’ramiz.
Dastur Kodi.
//Deque containerini sinab ko’ramiz.
// Abdullayev Suhrobjon 413-20 guruh talabasi.
#include
#include
using namespace std;
int main() {
deque d(5); /* d nomli to'plam olamiz*/
for (int i = 0; i < 5; i++) {
d[i] = i + 1;
}
d.push_back(10); // orqasidan 10 ni qo'shamiz.
d.push_front(0); // oldidan 0 ni qo'shamiz.
for (int i = 0; i < 7; i++) {
cout << d[i] << endl;
}
}
c)malloc funkisyasini qo’llab ko’ramiz.
Dastur Kodi.
//c) malloc () funksiyasidan foydalanib xotirani dinamik taqsimlashni amalga oshiring.
// Abdullayev Suhrobjon 413-20 guruh talabasi.
#include
#include
using namespace std;
int main() {
int i, n;
printf("Enter the number of integers: ");
scanf ("%d", &n);
int *ptr = (int*)malloc(n * sizeof(int));
if (ptr == NULL) {
printf("Memory not avilable");
exit(1);
}
for (i = 0; i < n; i++) {
printf("Enter an integer : ");
scanf("%d", ptr + i);
}
for (i = 0; i < n; i++)
printf("%d", *(ptr + i));
return 0;
2.Complex sinfidan foydalanib, ikkita kompleks sonlarni ayiring
Dastur Kodi.
// 2. Complex sinfidan foydalanib, ikkita kompleks sonlarni ayiring
// Abdullayev Suhrobjon 413-20 guruh talabasi.
#include
using namespace std;
class Complex
{
public:
int real, img;
//ikkita complex ni ayrish uchun funksiya qo'shamiz.
void sub(Complex c1, Complex c2)
{
int x, y;
x = c1.real - c2.real;
y = c1.img - c2.img;
cout << "\n(" << c1.real << "-" << c1.img << "i)-(" << c2.real << "-" << c2.img << "i)=(" << x << "-" << y << "i)";
}
};
int main()
{
Complex a, b, c, d, e;
cout << "\nBirinchi kopleks sonni real va imaginar qismini kiriting: ";
cin >> a.real >> a.img;
cout << "\nIkkinchi kompleks sonni real va imaginar qismini kiriting: ";
cin >> b.real >> b.img;
c.sub(a, b);
}
Do'stlaringiz bilan baham: |