Shukrullayev Jasurning Dasturlash 2 fanidan amaliy ishi
Download 145.12 Kb.
|
Shukrullayev jasurning Dasturlash 2 fanidan amaliy ishi
Shukrullayev Jasurning Dasturlash 2 fanidan amaliy ishi
#include <iostream> #include <fstream> #include <string> #include <vector> #include <algorithm> struct Table { std::string name; double price; double volume; }; bool compareTables(Table a, Table b) { return a.price < b.price; } int main() { std::ifstream file("table.txt"); std::vector<Table> tables; std::string name; double price, volume; while (file >> name >> price >> volume) { tables.push_back({name, price, volume}); } std::sort(tables.begin(), tables.end(), compareTables); for (const auto& table : tables) { std::cout << table.name << " - " << table.price << " so'm" << std::endl; } return 0; } 18. N ta complex son berilgan. Ularning real qismlari tasodifiy sonlar bilan, mavhum qismlari N ta murakkab (6=1+2+3 - bo'luvchilari yig'indisiga teng bo'lgan son) sonlar bilan to'ldirilsin hamda ushbu N ta complex sonlarni jadval ko'rinishida ekranga chiqarilsin. #include <bits/stdc++.h> #include "untiled-3.h" using namespace std; int main() { int N; cout << "N ni kiriting: "; cin >> N; // Randomly generate N complex numbers with random real parts and imaginary parts srand(time(0)); complex for (int i = 0; i < N; i++) { int real_part = rand()%1000 +i; // Random real part between 0 and 10 // Random imaginary part between 0 and 10 int imag_part = findPerfectNumbers(N*1000)[i]; complex_numbers[i] = complex<int>(real_part, imag_part); } // Print the table of complex numbers cout << "Complex numbers:" << endl; cout << "================" << endl; cout << "| Real | Imag |" << endl; cout << "================" << endl; for (int i = 0; i < N; i++) { cout << "| " << fixed << setprecision(3) << complex_numbers[i].real() << " | " << complex_numbers[i].imag() << "i |" << endl; } cout << "================" << endl; // Split the complex numbers into real and imaginary parts double real_numbers[N]; double imag_numbers[N]; for (int i = 0; i < N; i++) { real_numbers[i] = complex_numbers[i].real(); imag_numbers[i] = complex_numbers[i].imag(); } // Print the table of real numbers and imaginary numbers cout << "Real numbers:" << endl; cout << "============" << endl; for (int i = 0; i < N; i++) { cout << fixed << setprecision(3) << real_numbers[i] << endl; } cout << "============" << endl; cout << "Imaginary numbers:" << endl; cout << "=================" << endl; for (int i = 0; i < N; i++) { cout << fixed << setprecision(3) << imag_numbers[i] << endl; } cout << "=================" << endl; return 0; } #include <iostream> #include <vector> using namespace std; vector<int> findPerfectNumbers(int N) { vector for (int i = 2; i <= N; i++) { int sum = 1; for (int j = 2; j * j <= i; j++) { if (i % j == 0) { sum += j; if (j != i / j) { sum += i / j; } } } if (sum == i) { perfectNumbers.push_back(i); } } return perfectNumbers; }
#include <bits/stdc++.h> using namespace std; int main() { // 4) Ikki kompleks sonni ko'paytirish complex complex cout << "a * b = " << c << endl; // 5) Valarray massivining har 8-tasidan bir tasini aniqlash valarray for (int i = 0; i < 40; i++) { arr[i] = i; } valarray cout << "Every 8th element starting from 0th index: "; for (int i = 0; i < 5; i++) { cout << sub_arr[i] << " "; } cout << endl; // 6) Valarray massivini qiymatlarini o'zgartirish valarray for (int i = 0; i < 20; i++) { arr2[i] = i; } valarray<size_t> start{2, 5}, length{8, 8}, stride{1, 1}; gslice gs(2, length, stride); arr2[gs] = 18; cout << "After updating: "; for (int i = 0; i < 20; i++) { cout << arr2[i] << " "; } cout << endl; return 0; } #include <bits/stdc++.h> using namespace std; int main() { // 4) Ikki kompleks sonni ko'paytirish complex complex cout << "a * b = " << c << endl; // 5) Valarray massivining har 8-tasidan bir tasini aniqlash valarray for (int i = 0; i < 40; i++) { arr[i] = i; } valarray cout << "Every 8th element starting from 0th index: "; for (int i = 0; i < 5; i++) { cout << sub_arr[i] << " "; } cout << endl; // 6) Valarray massivini qiymatlarini o'zgartirish valarray for (int i = 0; i < 20; i++) { arr2[i] = i; } valarray<size_t> start{2, 5}, length{8, 8}, stride{1, 1}; gslice gs(2, length, stride); arr2[gs] = 18; cout << "After updating: "; for (int i = 0; i < 20; i++) { cout << arr2[i] << " "; } cout << endl; return 0; } Download 145.12 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling