Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ДЗ 4 Задача "Генератор случайных чисел"
- */
- void randGen() {
- long s = 0;
- long m1 = 37, m2 = 25173, i1 = 3, i2 = 13849, c1 = 64, c2 = 65537;
- RAND:
- cout << "Введите 1, чтобы получить случайное число" << endl;
- int n;
- cin >> n;
- if (cin.fail()) {
- defeat();
- cout << "Введите число!" << endl;
- goto RAND;
- }
- switch (n) {
- case 1:
- switch (rand() % 2) {
- case 0:
- s = (m1 * s + i1) % c1;
- cout << "Новое рандомное число: " << s << endl;
- break;
- case 1:
- s = (m2 * s + i2) % c2;
- cout << "Новое рандомное число: " << s << endl;
- break;
- }
- goto RAND;
- default: return;
- }
- }
- /*
- * ДЗ 4 Задача "Умножение матриц"
- */
- void matrix() {
- int objects[3][4];
- cout << "Заполните таблицу товаров" << endl;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 4; j++) {
- cout << "Продавец: " << i+1 << " Товар: " << j+1 << endl;
- cout << "Количество: ";
- int n;
- MONEY:
- cin >> n;
- if (cin.fail()) {
- defeat();
- cout << "Введите число!" << endl;
- goto MONEY;
- }
- objects[i][j] = n;
- }
- }
- cout << endl;
- double prices[4][2];
- cout << "Заполните таблицу цен" << endl;
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 2; j++) {
- cout << "Товар: " << i+1 << endl;
- if (j == 0) {
- cout << "Цена: ";
- }
- else {
- cout << "Комиссионные: ";
- }
- double n;
- PRICES:
- cin >> n;
- if (cin.fail()) {
- defeat();
- cout << "Введите число!" << endl;
- goto PRICES;
- }
- n = round(n * 100) / 100;
- prices[i][j] = n;
- }
- }
- double c[3][2];
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 2; j++) {
- c[i][j] = 0;
- }
- }
- cout << "\nРезультат произведения матриц:" << endl;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 2; j++) {
- for (int k = 0; k < 4; k++) {
- c[i][j] += objects[i][k] * prices[k][j];
- }
- cout << c[i][j] << " ";
- }
- cout << endl;
- }
- // 1) Больше всего денег с продажи
- // 2) Наибольшие и наименьшие комиссионные
- // 3) Общая сумма денег с продажи
- // 4) Общая сумма комиссионных
- // 5) 3+4
- cout << endl;
- double money[3];
- double com[3];
- for (int i = 0; i < 3; i++) {
- money[i] = c[i][0];
- }
- for (int i = 0; i < 3; i++) {
- com[i] = c[i][1];
- }
- for (int i = 0; i <3 ; i++) {
- if (max(max(money[0],money[1]),money[2]) == money[i]) {
- cout << "Больше всего денег с продажи выручил " << i+1 << " продавец" << endl;
- cout << "Выручка составила: " << money[i] << endl;
- break;
- }
- }
- for (int i = 0; i < 3; i++) {
- if (max(max(com[0], com[1]), com[2]) == com[i]) {
- cout << "Больше всего комиссионных получил " << i+1 << " продавец" << endl;
- cout << "Комиссионые составили: " << com[i] << endl;
- break;
- }
- }
- for (int i = 0; i < 3; i++) {
- if (min(min(com[0], com[1]), com[2]) == com[i]) {
- cout << "Меньше всего комиссионных получил " << i + 1 << " продавец" << endl;
- cout << "Комиссионые составили: " << com[i] << endl;
- break;
- }
- }
- double sumMoney=0;
- for (int i = 0; i < 3; i++) {
- sumMoney += money[i];
- }
- cout << "Общая выручка всех продавцов составила: " << sumMoney << endl;
- double sumCom=0;
- for (int i = 0; i < 3; i++) {
- sumCom += com[i];
- }
- cout << "Общие комиссионные всех продавцов составили: " << sumCom << endl;
- cout << "Всего через продавцов прошло: " << (sumMoney + sumCom) << endl;
- }
- /*
- * ДЗ 4 Задача "Системы счисления"
- */
- int translator(char c) {
- switch (c) {
- case '0': return 0;
- case '1': return 1;
- case '2': return 2;
- case '3': return 3;
- case '4': return 4;
- case '5': return 5;
- case '6': return 6;
- case '7': return 7;
- case '8': return 8;
- case '9': return 9;
- case 'A': return 10;
- case 'B': return 11;
- case 'C': return 12;
- case 'D': return 13;
- case 'E': return 14;
- case 'F': return 15;
- case 'G': return 16;
- case 'H': return 17;
- case 'I': return 18;
- case 'J': return 19;
- case 'K': return 20;
- case 'L': return 21;
- case 'M': return 22;
- case 'N': return 23;
- case 'O': return 24;
- case 'P': return 25;
- case 'Q': return 26;
- case 'R': return 27;
- case 'S': return 28;
- case 'T': return 29;
- case 'U': return 30;
- case 'V': return 31;
- case 'W': return 32;
- case 'X': return 33;
- case 'Y': return 34;
- case 'Z': return 35;
- default: return -1;
- }
- }
- string coder(int c) {
- switch (c) {
- case 0: return "0";
- case 1: return "1";
- case 2: return "2";
- case 3: return "3";
- case 4: return "4";
- case 5: return "5";
- case 6: return "6";
- case 7: return "7";
- case 8: return "8";
- case 9: return "9";
- case 10: return "A";
- case 11: return "B";
- case 12: return "C";
- case 13: return "D";
- case 14: return "E";
- case 15: return "F";
- case 16: return "G";
- case 17: return "H";
- case 18: return "I";
- case 19: return "J";
- case 20: return "K";
- case 21: return "L";
- case 22: return "M";
- case 23: return "N";
- case 24: return "O";
- case 25: return "P";
- case 26: return "Q";
- case 27: return "R";
- case 28: return "S";
- case 29: return "T";
- case 30: return "U";
- case 31: return "V";
- case 32: return "W";
- case 33: return "X";
- case 34: return "Y";
- case 35: return "Z";
- }
- }
- void systems() {
- STR:
- cout << "Введите систему счисления исходного числа (2-36): ";
- int ss1;
- cin >> ss1;
- if (cin.fail()) {
- defeat();
- cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
- goto STR;
- }
- if (ss1 > 36 or ss1 < 2) {
- cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
- goto STR;
- }
- FIRST:
- cout << "Введите исходное число: ";
- string number1;
- cin >> number1;
- transform(number1.begin(), number1.end(), number1.begin(), toupper);
- long l = 0;
- long dss = 0;
- for (long i = number1.size() - 1; i >= 0; i--) {
- if (translator(number1[i]) == -1 or translator(number1[i]) >= ss1) {
- cout << "В записи исходного числа использованы недопустимые знаки для выбранной системы счисления!" << endl;
- goto FIRST;
- }
- else {
- dss += pow(ss1, l) * translator(number1[i]);
- l++;
- }
- }
- MDL:
- cout << "Введите систему счисления итогового числа (2-36): ";
- int ss2;
- cin >> ss2;
- if (cin.fail()) {
- defeat();
- cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
- goto MDL;
- }
- if (ss2 > 36 or ss2 < 2) {
- cout << "Система счисления - целое число в диапазоне [2;36]!" << endl;
- goto MDL;
- }
- cout << "Итоговое число: ";
- string number2;
- while (dss > 0) {
- number2 = coder(dss % ss2) + number2;
- dss /= ss2;
- }
- cout << number2 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement