2 کامیت‌ها 826d1ba2a5 ... 7abb4494b4

نویسنده SHA1 پیام تاریخ
  Adolser 7abb4494b4 Merge branch 'master' of https://notabug.org/SickShadow/look 2 ماه پیش
  Adolser 45a5e721ad TaSk4 2 ماه پیش
9فایلهای تغییر یافته به همراه317 افزوده شده و 0 حذف شده
  1. BIN
      cpp/task4/a.out
  2. 14 0
      cpp/task4/mai.cpp
  3. 41 0
      cpp/task4/task1.cpp
  4. 35 0
      cpp/task4/task2.cpp
  5. 43 0
      cpp/task4/task3.cpp
  6. 26 0
      cpp/task4/task4.cpp
  7. 71 0
      cpp/task4/task5.cpp
  8. 36 0
      cpp/task4/task6.cpp
  9. 51 0
      cpp/task4/task7.cpp

BIN
cpp/task4/a.out


+ 14 - 0
cpp/task4/mai.cpp

@@ -0,0 +1,14 @@
+#include <cstdlib>
+#include <vector>
+#include <iostream>
+
+
+int main()
+{
+	std::vector<int>  d = {
+		{RAND_MAX},
+		{RAND_MAX},
+		{RAND_MAX}
+	};
+	std::cout << d[];
+}

+ 41 - 0
cpp/task4/task1.cpp

@@ -0,0 +1,41 @@
+#include <iostream>
+#include <limits> 
+
+int main() {
+    int arr[3][3] = {
+        {2, 1, 10},
+        {2, 23, 23},
+        {200, 9, 5}
+    };
+
+    int sum = 0;
+    int minElement = std::numeric_limits<int>::max(); 
+    int maxElement = std::numeric_limits<int>::min(); 
+    int count = 0; 
+
+    for (int i = 0; i < 3; ++i) {
+        for (int j = 0; j < 3; ++j) {
+            int currentElement = arr[i][j];
+            sum += currentElement; 
+            count++;
+
+            if (currentElement < minElement) {
+                minElement = currentElement;
+            }
+
+            if (currentElement > maxElement) {
+                maxElement = currentElement;
+            }
+        }
+    }
+
+    double average = static_cast<double>(sum) / count;
+
+    std::cout << "Сумма всех элементов: " << sum << std::endl;
+    std::cout << "Среднее арифметическое: " << average << std::endl;
+    std::cout << "Минимальный элемент: " << minElement << std::endl;
+    std::cout << "Максимальный элемент: " << maxElement << std::endl;
+
+    return 0;
+}
+

+ 35 - 0
cpp/task4/task2.cpp

@@ -0,0 +1,35 @@
+#include <iostream>
+
+int main() {
+    int arr[3][4] = {
+        {3, 5, 6, 7},
+        {12, 1, 1, 1},
+        {0, 7, 12, 1}
+    };
+
+    int rowSum1 = 0, rowSum2 = 0, rowSum3 = 0;
+    int colSum1 = 0, colSum2 = 0, colSum3 = 0, colSum4 = 0;
+    int totalSum = 0;
+
+    for (int i = 0; i < 3; ++i) {
+        for (int j = 0; j < 4; ++j) {
+            totalSum += arr[i][j];
+            if (i == 0) rowSum1 += arr[i][j];
+            if (i == 1) rowSum2 += arr[i][j];
+            if (i == 2) rowSum3 += arr[i][j];
+            if (j == 0) colSum1 += arr[i][j];
+            if (j == 1) colSum2 += arr[i][j];
+            if (j == 2) colSum3 += arr[i][j];
+            if (j == 3) colSum4 += arr[i][j];
+        }
+    }
+
+    std::cout << arr[0][0] << " " << arr[0][1] << " " << arr[0][2] << " " << arr[0][3] << " | " << rowSum1 << std::endl;
+    std::cout << arr[1][0] << " " << arr[1][1] << " " << arr[1][2] << " " << arr[1][3] << " | " << rowSum2 << std::endl;
+    std::cout << arr[2][0] << " " << arr[2][1] << " " << arr[2][2] << " " << arr[2][3] << " | " << rowSum3 << std::endl;
+    std::cout << "--------------------" << std::endl;
+    std::cout << colSum1 << " " << colSum2 << " " << colSum3 << " " << colSum4 << " | " << totalSum << std::endl;
+
+    return 0;
+}
+

+ 43 - 0
cpp/task4/task3.cpp

@@ -0,0 +1,43 @@
+#include <iostream>
+#include <cstdlib>
+#include <ctime>
+
+int main() {
+    int arr1[5][10];
+    int arr2[5][5];
+
+    std::srand(static_cast<unsigned int>(std::time(0)));
+
+    for (int i = 0; i < 5; ++i) {
+        for (int j = 0; j < 10; ++j) {
+            arr1[i][j] = std::rand() % 51;
+        }
+    }
+
+    for (int i = 0; i < 5; ++i) {
+        arr2[i][0] = arr1[i][0] + arr1[i][1];
+        arr2[i][1] = arr1[i][2] + arr1[i][3];
+        arr2[i][2] = arr1[i][4] + arr1[i][5];
+        arr2[i][3] = arr1[i][6] + arr1[i][7];
+        arr2[i][4] = arr1[i][8] + arr1[i][9];
+    }
+
+    std::cout << "Первый массив (5x10):" << std::endl;
+    for (int i = 0; i < 5; ++i) {
+        for (int j = 0; j < 10; ++j) {
+            std::cout << arr1[i][j] << " ";
+        }
+        std::cout << std::endl;
+    }
+
+    std::cout << "Второй массив (5x5):" << std::endl;
+    for (int i = 0; i < 5; ++i) {
+        for (int j = 0; j < 5; ++j) {
+            std::cout << arr2[i][j] << " ";
+        }
+        std::cout << std::endl;
+    }
+
+    return 0;
+}
+

+ 26 - 0
cpp/task4/task4.cpp

@@ -0,0 +1,26 @@
+#include <iostream>
+
+int main() {
+    int arr[] = {12, 11, 13, 5, 6};
+    int n = sizeof(arr) / sizeof(arr[0]);
+
+    for (int i = 1; i < n; i++) {
+        int key = arr[i];
+        int j = i - 1;
+
+        while (j >= 0 && arr[j] > key) {
+            arr[j + 1] = arr[j];
+            j--;
+        }
+        arr[j + 1] = key;
+    }
+
+    std::cout << "Отсортированный массив: ";
+    for (int i = 0; i < n; i++) {
+        std::cout << arr[i] << " ";
+    }
+    std::cout << std::endl;
+
+    return 0;
+}
+

+ 71 - 0
cpp/task4/task5.cpp

@@ -0,0 +1,71 @@
+#include <iostream>
+
+int main() {
+    int grades[10];
+    int choice;
+    double average;
+
+    std::cout << "Введите 10 оценок студента:" << std::endl;
+    for (int i = 0; i < 10; ++i) {
+        std::cout << "Оценка " << (i + 1) << ": ";
+        std::cin >> grades[i];
+    }
+
+    do {
+        std::cout << "\nМеню:\n";
+        std::cout << "1. Вывод оценок\n";
+        std::cout << "2. Пересдача экзамена\n";
+        std::cout << "3. Проверка на стипендию\n";
+        std::cout << "4. Выход\n";
+        std::cout << "Выберите действие: ";
+        std::cin >> choice;
+
+        switch (choice) {
+            case 1:
+                std::cout << "Оценки студента: ";
+                for (int i = 0; i < 10; ++i) {
+                    std::cout << grades[i] << " ";
+                }
+                std::cout << std::endl;
+                break;
+
+            case 2: {
+                int index;
+                int newGrade;
+                std::cout << "Введите номер оценки для пересдачи (1-10): ";
+                std::cin >> index;
+                if (index >= 1 && index <= 10) {
+                    std::cout << "Введите новую оценку: ";
+                    std::cin >> newGrade;
+                    grades[index - 1] = newGrade;
+                } else {
+                    std::cout << "Неверный номер оценки." << std::endl;
+                }
+                break;
+            }
+
+            case 3:
+                average = 0;
+                for (int i = 0; i < 10; ++i) {
+                    average += grades[i];
+                }
+                average /= 10;
+                if (average >= 4.5) {
+                    std::cout << "Стипендия выходит." << std::endl;
+                } else {
+                    std::cout << "Стипендия не выходит." << std::endl;
+                }
+                break;
+
+            case 4:
+                std::cout << "Выход из программы." << std::endl;
+                break;
+
+            default:
+                std::cout << "Неверный выбор. Попробуйте снова." << std::endl;
+        }
+    } while (choice != 4);
+
+    return 0;
+}
+

+ 36 - 0
cpp/task4/task6.cpp

@@ -0,0 +1,36 @@
+#include <iostream>
+
+void quickSort(int arr[], int low, int high) {
+    if (low < high) {
+        int pivot = arr[high];
+        int i = low - 1;
+
+        for (int j = low; j < high; j++) {
+            if (arr[j] < pivot) {
+                i++;
+                std::swap(arr[i], arr[j]);
+            }
+        }
+        std::swap(arr[i + 1], arr[high]);
+        int partitionIndex = i + 1;
+
+        quickSort(arr, low, partitionIndex - 1);
+        quickSort(arr, partitionIndex + 1, high);
+    }
+}
+
+int main() {
+    int arr[] = {12, 11, 13, 5, 6, 7};
+    int n = sizeof(arr) / sizeof(arr[0]);
+
+    quickSort(arr, 0, n - 1);
+
+    std::cout << "Отсортированный массив: ";
+    for (int i = 0; i < n; i++) {
+        std::cout << arr[i] << " ";
+    }
+    std::cout << std::endl;
+
+    return 0;
+}
+

+ 51 - 0
cpp/task4/task7.cpp

@@ -0,0 +1,51 @@
+#include <iostream>
+#include <algorithm>
+
+void quickSort(int arr[], int low, int high) {
+    if (low < high) {
+        int pivot = arr[high];
+        int i = low - 1;
+
+        for (int j = low; j < high; j++) {
+            if (arr[j] < pivot) {
+                i++;
+                std::swap(arr[i], arr[j]);
+            }
+        }
+        std::swap(arr[i + 1], arr[high]);
+        int partitionIndex = i + 1;
+
+        quickSort(arr, low, partitionIndex - 1);
+        quickSort(arr, partitionIndex + 1, high);
+    }
+}
+
+int main() {
+    int arr[] = {12, -5, 3, 7, 8, -2, 4, 1, -1, 6};
+    int n = sizeof(arr) / sizeof(arr[0]);
+
+    double sum = 0;
+    for (int i = 0; i < n; i++) {
+        sum += arr[i];
+    }
+    double average = sum / n;
+
+    if (average > 0) {
+        quickSort(arr, 0, (2 * n / 3) - 1);
+    } else {
+        quickSort(arr, 0, (n / 3) - 1);
+    }
+
+    for (int i = (2 * n / 3); i < n; i++) {
+        std::swap(arr[i], arr[n - 1 - (i - (2 * n / 3))]);
+    }
+
+    std::cout << "Результат: ";
+    for (int i = 0; i < n; i++) {
+        std::cout << arr[i] << " ";
+    }
+    std::cout << std::endl;
+
+    return 0;
+}
+