|
Dasturlash II fanidan bajargan
|
tarix | 18.05.2023 | ölçüsü | 0,67 Mb. | | #116007 |
| Javohir dasturlash
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Infokommunikatsiya injiniringgi
1-bosqich 432-22-guruh talabasi
Joraqulov Javohirning
Dasturlash II
fanidan bajargan
mustaqil ishi
Topshirdi: Joraqulov Javohir
Tekshirdi: Ibragimova Kamila
Toshkent 2023
Variant
1-misol
#include
#include
#include
#include
using namespace std;
struct Talaba {
string familiya;
string ism;
string oilaviyAhvoli;
};
int main() {
int n;
cout << "Talabalar sonini kiriting: ";
cin >> n;
vector talabalar(n);
for (int i = 0; i < n; i++) {
cout << "Talaba #" << i + 1 << "ning ma'lumotlarini kiriting:\n";
cout << "Familiya: ";
cin >> talabalar[i].familiya;
cout << "Ism: ";
cin >> talabalar[i].ism;
cout << "Oilaviy ahvoli: ";
cin >> talabalar[i].oilaviyAhvoli;
}
string kvartira;
cout << "Qaysi kvartirada yashaydigan talabalar aniqlansin: ";
cin >> kvartira;
ofstream out("talabalar.txt");
int count = 0;
for (auto it = talabalar.begin(); it != talabalar.end(); it++) {
if (it->oilaviyAhvoli == kvartira) {
count++;
out << count << ". " << it->familiya << " " << it->ism << endl;
}
}
int uydaYashaydigan = 0;
int kvartiradaYashaydigan = 0;
for (auto it = talabalar.begin(); it != talabalar.end(); it++) {
if (it->oilaviyAhvoli == "Uy") {
uydaYashaydigan++;
} else if (it->oilaviyAhvoli == kvartira) {
kvartiradaYashaydigan++;
out << kvartiradaYashaydigan << ". " << it->familiya << " " << it->ism << endl;
}
}
cout << kvartiradaYashaydigan << " ta talaba " << kvartira << " kvartirasida yashaydi va ular talabalar.txt fayliga yozib qo'yildi.\n";
cout << uydaYashaydigan << " ta talaba uyda yashaydi.\n";
out.close();
cout << count << " ta talaba " << kvartira << " kvartirasida yashaydi va ular talabalar.txt fayliga yozib qo'yildi.\n";
out.close();
return 0;
}
Misol
#include
#include
#include
using namespace std;
struct complex {
double real;
double imag;
};
int main() {
int n;
cout << "N ni kiriting: ";
cin >> n;
complex numbers[n];
srand(time(0));
for (int i = 0; i < n; i++) {
cout << i+1 << "-chi complex sonning real qismini kiriting: ";
cin >> numbers[i].real;
numbers[i].imag = rand() % 10;
}
double maxSum = numbers[0].real + numbers[0].imag;
double minSum = numbers[0].real + numbers[0].imag;
for (int i = 0; i < n; i++) {
double sum = numbers[i].real + numbers[i].imag;
if (sum > maxSum) {
maxSum = sum;
}
if (sum < minSum) {
minSum = sum;
}
}
cout << "Natijalar: " << endl;
cout << "maxSum = " << maxSum << endl;
cout << "minSum = " << minSum << endl;
for (int i = 0; i < n; i++) {
double sum = numbers[i].real + numbers[i].imag;
if (sum == maxSum || sum == minSum) {
cout << i+1 << "-chi son: " << numbers[i].real << " + " << numbers[i].imag << "i" << endl;
}
}
return 0;
}
Misol
#include
#include
#include
#include
#include
using namespace std;
int main() {
// Random generator initialization
srand(time(0));
complex c(rand() % 10, rand() % 10);
double ildiz = abs(c);
cout << "Kompleks sonning ildizi: " << ildiz << endl;
valarray> va(10);
for (int i = 0; i < va.size(); i++) {
va[i] = complex(rand() % 10, rand() % 10);
}
slice s(0, va.size(), 3);
valarray> tasini = va[s];
cout << "Har 3 qadamdagilari tasini: ";
for (auto t : tasini) {
cout << t << " ";
}
cout << endl;
valarray> va2(20);
for (int i = 0; i < va2.size(); i++) {
va2[i] = complex(rand() % 10, rand() % 10);
}
int start = 2;
int step = 3;
int size = 3;
gslice gs(start, valarray{size}, valarray{step});
complex value(rand() % 10, rand() % 10);
va2[gs] = value;
cout << "2, 5, 8, ... dan boshlab 3 ta qiymatga yetishishda "
<< "3 qadam farq bilan " << value << " ga o'zgaradi: ";
for (auto v : va2) {
cout << v << " ";
}
cout << endl;
return 0;
}
Dostları ilə paylaş: |
|
|