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

    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
    #include "pch.h"
    #include <iostream>
    
    using namespace std;
    
    struct _Point {
    	double x, y, z;
    };
    
    void setPoint(_Point &, double = 0, double = 0, double = 0);
    
    void outPoint(const _Point &, char);
    
    int main()
    {
    	_Point A, B, C, D;
    	setPoint(A, 1, 5, 6.78);
    	setPoint(B);
    	setPoint(C, 8);
    	setPoint(D, 3, 4);
    
    	outPoint(A,'a');
    	outPoint(B,'b');
    	outPoint(C,'c');
    	outPoint(D,'d');
    }
    
    void setPoint(_Point &name, double a, double b, double c) {
    	name.x = a;
    	name.y = b;
    	name.z = c;
    }
    
    void outPoint(const _Point &name,char ch) {
    	
    	cout <<ch<< "(" << name.x << ", " << name.y << ", " << name.z << ")\n";
    }

    maxrbs, 07 Ноября 2019

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

    +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
    42. 42
    43. 43
    // reflection.h
    template <class T>
    QStringList getPropertyList(T)
    {
      const QMetaObject& metaObject = T::staticMetaObject;
      ...
      return properties;
    }
    
    // Copy-pasted, the parameter now is T*
    template <class T>
    QStringList getPropertyList(T*)
    {
      const QMetaObject& metaObject = T::staticMetaObject;
      ...
      return properties;
    }
    
    // In other headers
    class IMessage
    {
    public:
      virtual ~IMessage();
      ...
    };
    
    class File
      : public IMessage
    {
      ...
    };
    
    class Text
      : public IMessage
    {
      ...
    };
    
    // Usage of all this
    QStringList p;
    p << getPropertyList(File());
    p << getPropertyList(Text());
    p << getPropertyList(static_cast<IMessage*>(new File()));

    Работаю с шаблонами и теку

    salamon_style, 05 Ноября 2019

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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    //замена главной диагонали с n-м столбцом в матрице с менюшкой и печеньками
    
    #include "pch.h"
    #include <iostream>
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <ctime>
    #include <iomanip>
    
    using namespace std;
    
    int a[100][100], n = 3;
    
    void inputN();
    void filling(int);
    void manualfill(int);
    void showmass(int);
    void solving();
    void menu();
    
    int main()
    {
    	setlocale(0, "rus");
    	menu();
    	srand(time(NULL));
    	return 0;
    }
    
    void inputN() {
    	system("cls");
    	cout << "Введите n = "; cin >> n;
    	if (n < 3) {
    		cout << "\nИспользован стандартный размер массива 3х3\n\n";
    		n = 3;
    	}
    	showmass(2);
    	cout << "\n\n";
    	system("pause");
    }
    
    void filling(int n) {
    	system("cls");
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < n; j++) {
    			a[i][j] = rand() % 100 + 1;
    		}
    	}
    	showmass(3);
    }
    
    void manualfill(int n) {
    	system("cls");
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < n; j++) {
    			printf("  a[%d][%d] = ", i + 1, j + 1); cin >> a[i][j];
    		}
    	}
    	system("pause");
    }
    
    void showmass(int status) {
    	if (status == 2 or status == 3) cout << "\n\n";else system("cls");
    	
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < n; j++) {
    			cout << setw(5) << a[i][j];
    		}
    		cout << endl;
    	}
    	if (status==1 or status == 3)system("pause");
    }
    
    void solving() {
    	system("cls");
    	showmass(2);
    	int c = 0;
    	int stolb = 0;
    	cout << "\nКакой столбец меняем?\n>>"; cin >> stolb; 
    	stolb--;
    	for (int i = 0; i < n; i++) {
    		c = a[i][i];
    		a[i][i] = a[i][stolb];
    		a[i][stolb] = c;
    	}
    	printf("\n\n----гл. диагональ меняется с %d столбцом----\n\n",stolb+1);
    	showmass(3);
    
    	for (int i = 0; i < n; i++) {
    		c = a[i][i];
    		a[i][i] = a[i][stolb];
    		a[i][stolb] = c;
    	}
    }
    
    void menu() {
    	system("cls");
    	int ch = 0;
    	while (true) {
    		cout << "     МЕНЮ\n\n";

    ъуъ

    maxrbs, 05 Ноября 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    char (&getArray())[11] {
      static char arr[] = "1234567890";
      return arr;
    }

    Как вернуть массив из функции в C/C++

    На самом деле нет: возвращается ссылка

    Elvenfighter, 24 Октября 2019

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // This concept tests whether 't + u' is a valid expression
    template<typename T, typename U>
    concept can_add = requires(T t, U u) { t + u; };
     
    // The function is only a viable candidate if 't + u' is a valid expression
    template<typename T, typename U> requires can_add<T, U>
    auto add(T t, U u)
    {
     return t + u;
    }

    ого чо есть

    MAPTbIwKA, 24 Октября 2019

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

    +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
    #include <cstdio>
    
    class tag;
    
    template<class>
    struct type { friend constexpr auto get(type); };
    
    template<class TKey, class TValue>
    struct set { friend constexpr auto get(TKey) { return TValue{}; } };
    
    void foo() {            // never called
      if constexpr(false) { // never true
        if (false) {        // never true
            constexpr auto call = [](auto value) { std::printf("called %d", value); };
            void(set<type<tag>, decltype(call)>{});
        }
      }
    }
    
    int main() {
      get(type<tag>{})(42); // prints called 42
    }

    https://twitter.com/krisjusiak/status/1186363017329594368
    Какой C++20 )))

    j123123, 21 Октября 2019

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

    0

    1. 1
    А вот операторов сравнения между всеми типами умных указателей, я как понял, нету, и даже по стандарту.

    OlegUP, 21 Октября 2019

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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include "pch.h"
    #include <iostream>
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    
    using namespace std;
    
    int n=0, m=0, a[10][10];
    
    void inputSize();
    void input();
    void out(int);
    void problem();
    bool just(int);
    void menu();
    
    int main()
    {
    	setlocale(0, "rus");
    	menu();
    	return 0;
    }
    
    void inputSize() {
    	system("cls");
    	cout << "количество строк = "; cin >> n;
    	cout << "количество столбцов = "; cin >> m;
    }
    
    void input() {
    	system("cls");
    	if (n == 0 || m == 0) {
    		cout << "размер массива задан по умолчанию: 3х3";
    		n = m = 3;
    	}
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < m; j++) {
    			cout << "a[" << i + 1 << "][" << j + 1 << "] = "; cin >> a[i][j];
    		}
    	}
    }
    
    void out(int x = 0 ) {
    	system("cls");
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < m; j++) {
    			cout << setw(7) << a[i][j];
    		}
    	cout << endl;
    	}
    	cout << endl;
    	system("pause");
    }
    
    void problem() {
    	system("cls");
    	int sum = 0, k = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < m; j++) {
    			if (just(a[i][j])) {
    				cout << "a[" << i + 1 << "][" << j + 1 << "]   ";
    				sum += a[i][j];
    				k++;
    			}
    		}
    	}
    	if (sum == 0) cout << "нет простых чисел"; 
    	else if (sum % k == 0) cout << "ср. арифм. - целое"; else cout << "ср. арифм - не целое";
    	_getch();
    }
    
    bool just(int n) {
    	if (n == 1)return false;
    	int c = sqrt(n);
    	for (int i = 2; i <= c; i++) if (n%i == 0) return false;
    	return true;
    }
    
    void menu() {
    	system("cls");
    	int ch = 0;
    	while (ch != 5) {
    		cout << "     МЕНЮ\n\n";
    		cout << "1. ввод размера массива\n";
    		cout << "2. ввод массива\n";
    		cout << "3. вывод массива\n";
    		cout << "4. решение задачи\n";
    		cout << "5. выход\n\n";
    		cout << ">>"; cin >> ch;
    
    		if (ch == 1) inputSize();
    		if (ch == 2) input();
    		if (ch == 3) out();
    		if (ch == 4) problem();
    		if (ch == 5) break;
    		system("cls");
    	}
    }

    maxrbs, 17 Октября 2019

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

    0

    1. 1
    2. 2
    3. 3
    if (res / 2 < ans) {
        ans = res / 2;
    }

    yuras, 17 Октября 2019

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

    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
    #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

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