Advertisement
Kwwiker

Только переделай их пж

Dec 9th, 2020
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.12 KB | None | 0 0
  1. /*
  2. * ДЗ 4 Задача "Генератор случайных чисел"
  3. */
  4. void randGen() {
  5.     long s = 0;
  6.     long m1 = 37, m2 = 25173, i1 = 3, i2 = 13849, c1 = 64, c2 = 65537;
  7.     RAND:
  8.     cout << "Введите 1, чтобы получить случайное число" << endl;
  9.     int n;
  10.     cin >> n;
  11.     if (cin.fail()) {
  12.         defeat();
  13.         cout << "Введите число!" << endl;
  14.         goto RAND;
  15.     }
  16.     switch (n) {
  17.     case 1:
  18.         switch (rand() % 2) {
  19.         case 0:
  20.             s = (m1 * s + i1) % c1;
  21.             cout << "Новое рандомное число: " << s << endl;
  22.             break;
  23.         case 1:
  24.             s = (m2 * s + i2) % c2;
  25.             cout << "Новое рандомное число: " << s << endl;
  26.             break;
  27.         }
  28.         goto RAND;
  29.     default: return;
  30.     }
  31. }
  32.  
  33. /*
  34. * ДЗ 4 Задача "Умножение матриц"
  35. */
  36. void matrix() {
  37.     int objects[3][4];
  38.     cout << "Заполните таблицу товаров" << endl;
  39.     for (int i = 0; i < 3; i++) {
  40.         for (int j = 0; j < 4; j++) {
  41.             cout << "Продавец: " << i+1 << " Товар: " << j+1 << endl;
  42.             cout << "Количество: ";
  43.             int n;
  44.             MONEY:
  45.             cin >> n;
  46.             if (cin.fail()) {
  47.                 defeat();
  48.                 cout << "Введите число!" << endl;
  49.                 goto MONEY;
  50.             }
  51.             objects[i][j] = n;
  52.         }
  53.     }
  54.     cout << endl;
  55.     double prices[4][2];
  56.     cout << "Заполните таблицу цен" << endl;
  57.     for (int i = 0; i < 4; i++) {
  58.         for (int j = 0; j < 2; j++) {
  59.             cout << "Товар: " << i+1 << endl;
  60.             if (j == 0) {
  61.                 cout << "Цена: ";
  62.             }
  63.             else {
  64.                 cout << "Комиссионные: ";
  65.             }
  66.             double n;
  67.             PRICES:
  68.             cin >> n;
  69.             if (cin.fail()) {
  70.                 defeat();
  71.                 cout << "Введите число!" << endl;
  72.                 goto PRICES;
  73.             }
  74.             n = round(n * 100) / 100;
  75.             prices[i][j] = n;
  76.         }
  77.     }
  78.     double c[3][2];
  79.     for (int i = 0; i < 3; i++) {
  80.         for (int j = 0; j < 2; j++) {
  81.             c[i][j] = 0;
  82.         }
  83.     }
  84.     cout << "\nРезультат произведения матриц:" << endl;
  85.     for (int i = 0; i < 3; i++) {
  86.         for (int j = 0; j < 2; j++) {
  87.             for (int k = 0; k < 4; k++) {
  88.                 c[i][j] += objects[i][k] * prices[k][j];
  89.             }
  90.             cout << c[i][j] << " ";
  91.         }
  92.         cout << endl;
  93.     }
  94.     // 1) Больше всего денег с продажи
  95.     // 2) Наибольшие и наименьшие комиссионные
  96.     // 3) Общая сумма денег с продажи
  97.     // 4) Общая сумма комиссионных
  98.     // 5) 3+4
  99.     cout << endl;
  100.     double money[3];
  101.     double com[3];
  102.     for (int i = 0; i < 3; i++) {
  103.         money[i] = c[i][0];
  104.     }
  105.     for (int i = 0; i < 3; i++) {
  106.         com[i] = c[i][1];
  107.     }
  108.     for (int i = 0; i <3 ; i++) {
  109.         if (max(max(money[0],money[1]),money[2]) == money[i]) {
  110.             cout << "Больше всего денег с продажи выручил " << i+1 << " продавец" << endl;
  111.             cout << "Выручка составила: " << money[i] << endl;
  112.             break;
  113.         }
  114.     }
  115.     for (int i = 0; i < 3; i++) {
  116.         if (max(max(com[0], com[1]), com[2]) == com[i]) {
  117.             cout << "Больше всего комиссионных получил " << i+1 << " продавец" << endl;
  118.             cout << "Комиссионые составили: " << com[i] << endl;
  119.             break;
  120.         }
  121.     }
  122.     for (int i = 0; i < 3; i++) {
  123.         if (min(min(com[0], com[1]), com[2]) == com[i]) {
  124.             cout << "Меньше всего комиссионных получил " << i + 1 << " продавец" << endl;
  125.             cout << "Комиссионые составили: " << com[i] << endl;
  126.             break;
  127.         }
  128.     }
  129.     double sumMoney=0;
  130.     for (int i = 0; i < 3; i++) {
  131.         sumMoney += money[i];
  132.     }
  133.     cout << "Общая выручка всех продавцов составила: " << sumMoney << endl;
  134.     double sumCom=0;
  135.     for (int i = 0; i < 3; i++) {
  136.         sumCom += com[i];
  137.     }
  138.     cout << "Общие комиссионные всех продавцов составили: " << sumCom << endl;
  139.     cout << "Всего через продавцов прошло: " << (sumMoney + sumCom) << endl;
  140.  
  141.  
  142. }
  143.  
  144. /*
  145. * ДЗ 4 Задача "Системы счисления"
  146. */
  147. int translator(char c) {
  148.     switch (c) {
  149.     case '0': return 0;
  150.     case '1': return 1;
  151.     case '2': return 2;
  152.     case '3': return 3;
  153.     case '4': return 4;
  154.     case '5': return 5;
  155.     case '6': return 6;
  156.     case '7': return 7;
  157.     case '8': return 8;
  158.     case '9': return 9;
  159.     case 'A': return 10;
  160.     case 'B': return 11;
  161.     case 'C': return 12;
  162.     case 'D': return 13;
  163.     case 'E': return 14;
  164.     case 'F': return 15;
  165.     case 'G': return 16;
  166.     case 'H': return 17;
  167.     case 'I': return 18;
  168.     case 'J': return 19;
  169.     case 'K': return 20;
  170.     case 'L': return 21;
  171.     case 'M': return 22;
  172.     case 'N': return 23;
  173.     case 'O': return 24;
  174.     case 'P': return 25;
  175.     case 'Q': return 26;
  176.     case 'R': return 27;
  177.     case 'S': return 28;
  178.     case 'T': return 29;
  179.     case 'U': return 30;
  180.     case 'V': return 31;
  181.     case 'W': return 32;
  182.     case 'X': return 33;
  183.     case 'Y': return 34;
  184.     case 'Z': return 35;
  185.     default: return -1;
  186.     }
  187. }
  188.  
  189. string coder(int c) {
  190.     switch (c) {
  191.     case 0: return "0";
  192.     case 1: return "1";
  193.     case 2: return "2";
  194.     case 3: return "3";
  195.     case 4: return "4";
  196.     case 5: return "5";
  197.     case 6: return "6";
  198.     case 7: return "7";
  199.     case 8: return "8";
  200.     case 9: return "9";
  201.     case 10: return "A";
  202.     case 11: return "B";
  203.     case 12: return "C";
  204.     case 13: return "D";
  205.     case 14: return "E";
  206.     case 15: return "F";
  207.     case 16: return "G";
  208.     case 17: return "H";
  209.     case 18: return "I";
  210.     case 19: return "J";
  211.     case 20: return "K";
  212.     case 21: return "L";
  213.     case 22: return "M";
  214.     case 23: return "N";
  215.     case 24: return "O";
  216.     case 25: return "P";
  217.     case 26: return "Q";
  218.     case 27: return "R";
  219.     case 28: return "S";
  220.     case 29: return "T";
  221.     case 30: return "U";
  222.     case 31: return "V";
  223.     case 32: return "W";
  224.     case 33: return "X";
  225.     case 34: return "Y";
  226.     case 35: return "Z";
  227.     }
  228. }
  229.  
  230. void systems() {
  231.  
  232.     STR:
  233.     cout << "Введите систему счисления исходного числа (2-36): ";
  234.     int ss1;
  235.     cin >> ss1;
  236.     if (cin.fail()) {
  237.         defeat();
  238.         cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
  239.         goto STR;
  240.     }
  241.     if (ss1 > 36 or ss1 < 2) {
  242.         cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
  243.         goto STR;
  244.     }
  245.  
  246.     FIRST:
  247.     cout << "Введите исходное число: ";
  248.     string number1;
  249.     cin >> number1;
  250.     transform(number1.begin(), number1.end(), number1.begin(), toupper);
  251.     long l = 0;
  252.     long dss = 0;
  253.     for (long i = number1.size() - 1; i >= 0; i--) {
  254.         if (translator(number1[i]) == -1 or translator(number1[i]) >= ss1) {
  255.             cout << "В записи исходного числа использованы недопустимые знаки для выбранной системы счисления!" << endl;
  256.             goto FIRST;
  257.         }
  258.         else {
  259.             dss += pow(ss1, l) * translator(number1[i]);
  260.             l++;
  261.         }
  262.     }
  263.  
  264.     MDL:
  265.     cout << "Введите систему счисления итогового числа (2-36): ";
  266.     int ss2;
  267.     cin >> ss2;
  268.     if (cin.fail()) {
  269.         defeat();
  270.         cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
  271.         goto MDL;
  272.     }
  273.     if (ss2 > 36 or ss2 < 2) {
  274.         cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
  275.         goto MDL;
  276.     }
  277.  
  278.     cout << "Итоговое число: ";
  279.     string number2;
  280.     while (dss > 0) {
  281.         number2 = coder(dss % ss2) + number2;
  282.         dss /= ss2;
  283.     }
  284.     cout << number2 << endl;
  285. }
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement