Advertisement
gasaichan

Untitled

May 22nd, 2017
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.49 KB | None | 0 0
  1. #include<string.h>
  2. #include<clocale>
  3. #include<iostream>
  4. #include<fstream>
  5. #include<math.h>
  6. #include<conio.h>
  7. #include <stdio.h>
  8. #include <cstdio>
  9. #include <iomanip>
  10. #include <ctime>
  11. #include <windows.h>
  12.  
  13. #define PAYMENT 2000
  14.  
  15. using namespace std;
  16.  
  17. void Titul() {
  18.     HANDLE consoleOutput;
  19.     COORD cursorPos;
  20.     system("cls");
  21.     consoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);//
  22.     cursorPos.X = 25;
  23.     cursorPos.Y = 3;
  24.     SetConsoleCursorPosition(consoleOutput, cursorPos);
  25.     //
  26.     cout << static_cast<char>(218) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(191) << endl;
  27.     cursorPos.X = 25;
  28.     cursorPos.Y = 4;
  29.     SetConsoleCursorPosition(consoleOutput, cursorPos);
  30.     cout << static_cast<char>(179) << " LR 2.7 " << static_cast<char>(179) << endl;
  31.     cursorPos.X = 25;
  32.     cursorPos.Y = 5;
  33.     SetConsoleCursorPosition(consoleOutput, cursorPos);
  34.     cout << static_cast<char>(179) << " Samara University " << static_cast<char>(179) << endl;
  35.     cursorPos.X = 25;
  36.     cursorPos.Y = 6;
  37.     SetConsoleCursorPosition(consoleOutput, cursorPos);
  38.     cout << static_cast<char>(179) << "Faculty of electronic " << static_cast<char>(179) << endl;
  39.     cursorPos.X = 25;
  40.     cursorPos.Y = 7;
  41.     SetConsoleCursorPosition(consoleOutput, cursorPos);
  42.     cout << static_cast<char>(179) << " Boblak I. " << static_cast<char>(179) << endl;
  43.     cursorPos.X = 25;
  44.     cursorPos.Y = 8;
  45.     SetConsoleCursorPosition(consoleOutput, cursorPos);
  46.     cout << static_cast<char>(179) << " Group 5103 " << static_cast<char>(179) << endl;
  47.     cursorPos.X = 25;
  48.     cursorPos.Y = 9;
  49.     SetConsoleCursorPosition(consoleOutput, cursorPos);
  50.     //
  51.     cout << static_cast<char>(192) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(196) << static_cast<char>(217) << endl;
  52.     system("PAUSE");
  53. }
  54.  
  55.  
  56. void Lr1() {
  57.     printf("Формируем из исходного массива B массива A, каждый элемент которого есть\n сумма положительных элементов в соответствующей строке матрицы.");
  58.     const int ROWS = 4;
  59.     const int COLS = 3;
  60.     int B[ROWS][COLS], A[ROWS] = { 0, 0, 0, 0 };
  61.  
  62.     printf("\nArray B: \n");
  63.     for (int i = 0; i < ROWS; i++) {
  64.         for (int j = 0; j < COLS; j++) {
  65.             B[i][j] = rand() % 100 - 50;
  66.             printf("%d\t", B[i][j]);
  67.             if (B[i][j] > 0) {
  68.                 A[i] += B[i][j];
  69.             }
  70.         }
  71.         printf("\n");
  72.  
  73.     }
  74.  
  75.     printf("\nArray A\n");
  76.     for (int i = 0; i < ROWS; i++) {
  77.         printf("%d\t", A[i]);
  78.     }
  79.     system("PAUSE");
  80. }
  81.  
  82. // *arr - указатель на массив, n - количество элементов массива
  83. int* arrInit(int *arr, int n);
  84. // *arr - указатель на массив, n - количество элементов массива
  85. void arrOut(int *arr, int n);
  86. // *currentArr - указатель на исходный массив, *newArr - указатель на новый массив
  87. int* arrOrganise(int *currentArr, int *newArr, int n);
  88. // *arr - указатель на массив, n - количество элементов массива
  89. int* arrSort(int *arr, int n);
  90. //
  91. void arrOutExcel(int *arr1, int *arr2, int n);
  92.  
  93.  
  94. void Lr3() {
  95.     int arrSize = 0;
  96.     printf("****************************\n");
  97.     printf("\nEnter the array size: ");
  98.     scanf_s("%d", &arrSize);
  99.     printf("\n");
  100.     printf("\n****************************\n");
  101.  
  102.     int *B = new int[arrSize];
  103.     arrInit(B, arrSize);
  104.     printf("\n****************************\n");
  105.  
  106.     printf("Array B:\n ");
  107.     arrOut(B, arrSize);
  108.     printf("\n****************************\n");
  109.    
  110.     int *A = new int[arrSize];
  111.     arrOrganise(B, A, arrSize);
  112.  
  113.     // Вывод сразу сортированного массива A
  114.     arrSort(A, arrSize);
  115.     printf("Array A: \n");
  116.     arrOut(A, arrSize);
  117.     printf("\n****************************\n");
  118.  
  119.     //Вывод всех массивов в Excel
  120.     arrOutExcel(B, A, arrSize);
  121.     system("PAUSE");
  122. }
  123.  
  124. int* arrInit(int *arr, int n) {
  125.     printf("\n");
  126.     for (int i = 0; i < n; i++) {
  127.         // Введите элемент массива
  128.         printf("Enter an %d array cell: ", i + 1);
  129.         scanf_s("%d", &arr[i]);
  130.     }
  131.     return arr;
  132. }
  133.  
  134. void arrOut(int *arr, int n) {
  135.     for (int i = 0; i < n; i++) {
  136.         printf("%d\t", arr[i]);
  137.     }
  138. }
  139.  
  140. int* arrOrganise(int *currentArr, int *newArr, int n) {
  141.     for (int i = 0; i < n; i++) {
  142.         if (currentArr[i] % 2 == 0) {
  143.             newArr[i] = currentArr[i];
  144.         }
  145.         else {
  146.             newArr[i] = 0;
  147.         }
  148.     }
  149.     return newArr;
  150. }
  151.  
  152. int* arrSort(int *arr, int n) {
  153.     int min, kmin, temp;
  154.     for (int i = 0; i < n - 1; i++) {
  155.         min = arr[i];
  156.         kmin = i;
  157.         for (int j = i + 1; j < n; j++) {
  158.             if (arr[j] <= min) {
  159.                 min = arr[j];
  160.                 kmin = j;
  161.             }
  162.         }
  163.         temp = arr[i];
  164.         arr[i] = arr[kmin];
  165.         arr[kmin] = temp;
  166.     }
  167.  
  168.     return arr;
  169. }
  170.  
  171. void arrOutExcel(int *arr1, int *arr2, int n) {
  172.     ofstream fout;
  173.     fout.open("lab.csv");
  174.  
  175.     fout << "Array B" << endl;
  176.     for (int i = 0; i < n; i++) {
  177.         fout << i << ";" << arr1[i] << endl;
  178.     }
  179.     fout << endl;
  180.     fout << "Sorted array A" << endl;
  181.     for (int i = 0; i < n; i++) {
  182.         fout << i << ";" << arr2[i] << endl;
  183.     }
  184.     fout << endl;
  185.  
  186.     fout.close();
  187.  
  188. }
  189.  
  190. void Lr21() {
  191.     char s[100];
  192.     int i = 0, k = 0;
  193.  
  194.     printf("Введите строку:\n");
  195.     cin >> s;
  196.  
  197.     while (s[i] != '\0')
  198.     {
  199.         if ((s[i] == '.') || (s[i] == '!'))
  200.             k++;
  201.         i++;
  202.     }
  203.     printf("Введенная строка: %s\n", s);
  204.     printf("\n");
  205.     printf("Количество предложений в строке - %d", k);
  206.     system("PAUSE");
  207. }
  208.  
  209. void Lr22() {
  210.     const int m = 100;
  211.     int i = 0, j = 0, len;
  212.     char str[m], slovonach[m] = "", slovocon[m] = "", *con, *nach;
  213.  
  214.     printf("****************************\n");
  215.     printf("Введите строку:\n");
  216.     cin >> str;
  217.  
  218.     while (str[i] != ' ')
  219.     {
  220.         slovonach[i] = str[i];
  221.         i++;
  222.     }
  223.     len = strlen(str);
  224.  
  225.     for (i = len; i >= 0; i--)
  226.     {
  227.         if (str[i] == ' ')
  228.         {
  229.             for (j = 0; j<len - i + 1; j++)
  230.                 slovocon[j] = str[i + 1 + j];
  231.             break;
  232.         }
  233.     }
  234.  
  235.     printf("Исходная строка:");
  236.     puts(str);
  237.     printf("Первое слово строки:");
  238.     puts(slovonach);
  239.     printf("Последнее слово строки:");
  240.     puts(slovocon);
  241.  
  242.  
  243.     printf("нажмите любую клавишу");
  244.     system("PAUSE");
  245.  
  246. }
  247.  
  248. struct student {
  249.     char surname[100];
  250.     int marks[3];
  251.     double payment;
  252. };
  253.  
  254. void structInit(const int n, student *arr)
  255. {
  256.     for (int i = 0; i<n; i++)
  257.     {
  258.         printf("Информация о студенте № %d:\n", i + 1);
  259.         printf("Фамилия: ");
  260.         scanf_s("%s", &arr[i].surname, 100);
  261.         printf("Оценки за 3 предмета:\n ");
  262.         for (int j = 0; j < 3; j++) {
  263.             printf("Оценка за %d-й предмет: ", j + 1);
  264.             scanf_s("%d", &arr[i].marks[j]);
  265.         }
  266.  
  267.         if (arr[i].marks[0] == 5 && arr[i].marks[1] == 5 && arr[i].marks[2] == 5) {
  268.             arr[i].payment = PAYMENT*1.25;
  269.         }
  270.         else if (arr[i].marks[0] != 3 && arr[i].marks[1] != 3 && arr[i].marks[2] != 3) {
  271.             arr[i].payment = PAYMENT;
  272.         }
  273.         else {
  274.             arr[i].payment = 0;
  275.         }
  276.     }
  277.  
  278. }
  279.  
  280. void structOut(const int n, student *arr) {
  281.     for (int i = 0; i < n; i++) {
  282.         printf("\nСтудент %d:\n", i + 1);
  283.         //for (int s = 0; s < arr[i].surname.length(); s++) {
  284.         // cout » arr[i].surname[s];
  285.         //}
  286.         cout << arr[i].surname << endl;
  287.         printf("Оценки по 3-м предметам: \t");
  288.         for (int j = 0; j < 3; j++) {
  289.             printf("%d\t", arr[i].marks[j]);
  290.         }
  291.         printf("\nСтипендия студента: %f\n", arr[i].payment);
  292.     }
  293. }
  294.  
  295. void structOutExcel(const int n, student *arr) {
  296.     ofstream fout("arr.csv");
  297.     fout << "Список студентов" << endl;
  298.     fout << "№" << "Фамилия" << ";" << "Оценки" << ";" << "Стипендия" << endl;
  299.     for (int i = 0; i < n; i++) {
  300.         fout << i + 1 << ";" << arr[i].surname << ";";
  301.         for (int j = 0; j < 3; j++) {
  302.             fout << arr[i].marks[j] << " ";
  303.         }
  304.         fout << ";" << arr[i].payment << endl;
  305.     }
  306.     fout.close();
  307. }
  308.  
  309.  
  310.  
  311. void Lr4() {
  312.     setlocale(LC_ALL, "Russian");
  313.     int n, k = 0;
  314.     char s[100] = "";
  315.  
  316.     printf("Введите количество студентов: ");
  317.     scanf_s("%d", &n);
  318.  
  319.     student *Sk = new student[n];
  320.     if (Sk == NULL) {
  321.         printf("Ошибка");
  322.     }
  323.  
  324.     structInit(n, Sk);
  325.     structOut(n, Sk);
  326.     structOutExcel(n, Sk);
  327.  
  328.     system("PAUSE");
  329.  
  330. }
  331.  
  332.  
  333. void main() {
  334.  
  335.     setlocale(LC_ALL, "Russian");
  336.  
  337.     int N;
  338.  
  339.     do {
  340.  
  341.         system("cls");
  342.  
  343.         printf("1. Титульная рамка\n");
  344.         printf("2. Матрицы\n");
  345.         printf("3. Динамические массивы\n");
  346.         printf("4. Символьные строки 1\n");
  347.         printf("5. Символьные строки 2\n");
  348.         printf("6. Структура\n");
  349.         printf("7. Выход\n");
  350.         printf("\n\n Выберите пункт меню: ");
  351.  
  352.         scanf_s("%d", &N);
  353.  
  354.         switch (N) {
  355.  
  356.         case 1: printf("Выбран пункт 1\n"); Titul(); break;
  357.  
  358.         case 2: printf("Выбран пункт 2\n"); Lr1(); break;
  359.  
  360.         case 3: printf("Выбран пункт 3\n"); Lr3(); break;
  361.  
  362.         case 4: printf("Выбран пункт 4\n"); Lr21(); break;
  363.  
  364.         case 5: printf("Выбран пункт 5\n"); Lr22(); break;
  365.  
  366.         case 6: printf("Выбран пункт 6\n"); Lr4(); break;
  367.  
  368.         case 7:break;
  369.  
  370.         default: printf("Неизвестная операция\n"); break;
  371.  
  372.         }
  373.     }
  374.  
  375.     while (N != 0);
  376.  
  377. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement