1. C++ / Говнокод #25956

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    #include <random>
    using namespace std;
     
    int main()
    {
        setlocale(LC_ALL, "Rus");
        double n;
        cout << "Введите точность вычисления: ";
        cin >> n;
     
        while (n < 0.000001 || n > 1)
        {
            cout << "Веденное не соответствует условию" << "\nВведите точность вычислений: " << endl;
            cin >> n;
        }
     
        //Рандомные числа с промежутком
        random_device generator;
        uniform_real_distribution<double> distribution(-700, 700); //потому что функция "sinh" не считает > 700
        double x = distribution(generator);
        cout << "На множестве R выбран x, равный: " << x << "\n";
     
        //Подсчёт формулы
        double sum = 0.0;
        double a = x;
        double t = 1;
        while (abs(a) >= n)
        {
            sum += a;
            a *= (x * x / ((t + 1) * (t + 2)));
            t += 2;
        }
     
        //Функция, сравнение, погрешность
        double func = sinh(x);
        double diff = abs(sum - func);
        cout << setprecision(ceil(log10(1 / n))) << "Результат функции: " << func <<"\nРезультат просчета ряда: " << sum << endl;
        cout << "Погрешность составляет: " << diff << endl;   
        return 0;

    Brutallprincess, 16 Октября 2019

    Комментарии (0)
  2. C++ / Говнокод #25950

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    #include "pch.h"
    #include <iostream>
    #include <conio.h>
    #include <stdlib.h>
    #include <ctime>
    
    using namespace std;
    
    int main()
    {
    	setlocale(0, "rus");
    	int n, a[1000], max, c;
    	cout << "число элементов: "; cin >> n;
    	srand(time(0));
    	
    	cout << "\nчисла массива:\n";
    	for (int i = 0; i < n; i++) {
    		a[i] = rand() % 2000 -1000;
    		cout << a[i] << " ";
    		if (i == 0) max = abs(a[i]); else if (abs(a[i]) > max) max = abs(a[i]);
    	}
    	cout << "\n\nабс. максимум = " << max << endl;
    
    	for (int i = 0; i < n; i++) {
    		for (int j = n-1; j > 0; j--) {
    			if (a[j - 1] < a[j]) {
    				c = a[j - 1];
    				a[j - 1] = a[j];
    				a[j] = c;
    			}
    		}
    	}
    
    	cout << "\nотсортированный массив:\n";
    	for (int i = 0; i < n; i++) {
    		cout << a[i]<<" ";
    	}
    
    	_getch();
    	return 0;
    }

    maxrbs, 15 Октября 2019

    Комментарии (1)
  3. C++ / Говнокод #25930

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    // File icontact.h
    // Describes a contact in the address book
    class IContact
    {
    public:
        virtual ~IContact();
        virtual void ... 
        ... 
        void setContact(const QString& contact);
        ...
    private:
        QString m_contact;
        // ... other fields ...
    };
    
    // File icontact.cpp
    void IContact::setContact(const QString &contact)
    {
        m_contact = contact;
    }

    "Ну и че тут непонятного?" (Senior software developer, 8+ years of experience)

    salamon_style, 11 Октября 2019

    Комментарии (27)
  4. C++ / Говнокод #25927

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    In file included from /usr/include/c++/5.5.0/string:52:0,
                     from /usr/include/c++/5.5.0/bits/locale_classes.h:40,
                     from /usr/include/c++/5.5.0/bits/ios_base.h:41,
                     from /usr/include/c++/5.5.0/ios:42,
                     from /usr/include/c++/5.5.0/ostream:38,
                     from /usr/include/c++/5.5.0/iostream:39,
                     from 1.cpp:1:
    /usr/include/c++/5.5.0/bits/basic_string.h:5275:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
         operator<<(basic_ostream<_CharT, _Traits>& __os,
         ^
    /usr/include/c++/5.5.0/bits/basic_string.h:5275:5: note:   template argument deduction/substitution failed:
    1.cpp:16:18: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’

    давайте обсирать С++

    MAPTbIwKA, 11 Октября 2019

    Комментарии (15)
  5. C++ / Говнокод #25924

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    // File.cpp
    QString File::size() const
    {
        return QString::number(QFileInfo(m_path).size());
    }
    
    // ... somewhere in the code...
    
    File* message = ...
    ...
    if (message->size() == "0")
            return;

    Commit b1aef142 "Refactoring"
    Р - Рефакторинг

    salamon_style, 10 Октября 2019

    Комментарии (43)
  6. C++ / Говнокод #25911

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    #include <stdio.h>
    
    struct Gost {
       int x = 42;    
    };
    
    
    int main () {
        Gost gst;
        printf("%d\n", gst); // 42
    }

    http://ideone.com/fB26cs

    Уб ли это?

    OCETuHCKuu_nemyx, 06 Октября 2019

    Комментарии (71)
  7. C++ / Говнокод #25901

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // https://habr.com/ru/company/jugru/blog/469465/
    // Инициализация в современном C++ 
    // ...
    //Есть примеры ещё более странного поведения этого синтаксиса:
    
    std::string s(48, 'a'); // "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    std::string s{48, 'a'}; // "0a"

    > В первой строке создаётся строка из 48 символов «а», а во второй строка «0а». Это происходит потому, что конструктор string принимает на вход initializer_list из символов. 48 является целочисленным значением, поэтому оно преобразуется в символ. В ASCII число 48 — код символа «0». Это очень странно, потому что есть конструктор, принимающий именно такие аргументы, int и char. Но вместо вызова этого конструктора происходит совершенно неочевидное преобразование. В итоге получается код, который чаще всего ведёт себя не так, как мы ожидаем.

    КАК? Как можно было столько хуйни наворотить для такой простой вещи, как инициализация переменной? Чем они вообще думают?

    Не перестаю удивляться долбоебизму крестостандартизаторов

    j123123, 05 Октября 2019

    Комментарии (22)
  8. C++ / Говнокод #25898

    +1

    1. 1
    2. 2
    3. 3
    size_t 	nChLen = it_ch_end - it_ch;
    
    до меня дошло не сразу.

    OlegUP, 03 Октября 2019

    Комментарии (18)
  9. C++ / Говнокод #25888

    −8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    #include <iostream>
    using namespace std;
    int_main()
    {
        double a, c;
        char b;
        cout << "Enter the example: ";
        cin >> a, b, c;
        if (b == '+')
        {
            cout << a+c;
        }
        if (b == '-')
        {
            cout << a-c;
        }
        if (b == '*')
        {
            cout << a*c;
        }
        if (b == '/')
        {
            cout << a/c;
        }
        return 0;
    }

    Почему не работает парню на SO так и не ответили...

    EMWD, 30 Сентября 2019

    Комментарии (20)
  10. C++ / Говнокод #25883

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    #include "pch.h"
    #include <iostream>
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    
    using namespace std;
    
    int main()
    {
    	setlocale(0, "rus");
    	int a[100], min = 0, sum=0, n, k=0;
    	double sr;
    	cout << "введите количество элементов массива: "; cin >> n;
    	cout << "\n---элементы массива должны быть ЦЕЛЫМИ---\n\n";
    	
    	for (int i = 0; i < n; i++) {
    		cout << "a[" << i + 1 << "] = "; cin >> a[i];
    		if (a[i] > 0) {
    			k++;
    			sum += a[i];
    		}
    		else {
    			if (a[i] < min) min = a[i];
    		}
    	}
    	sr = (double)sum / k;
    	cout << "произведение минимального среди отрицательных (" << min << ") на среднее арифметическое всех положительных (" << sr << ") равно: " << min * sr;
    	
            _getch();
    	return 0;
    }

    Произведение минимального среди отрицательных на среднее арифметическое всех положительных.

    maxrbs, 30 Сентября 2019

    Комментарии (7)