valenki13

lesson_321_23

Oct 23rd, 2023
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include "Header.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int glob_sad = 12;
  7. //int glob_sad = 15;
  8.  
  9.  
  10.  
  11. int sum(int a, int b, int c = 0) {
  12.     return a + b + c;
  13. }
  14.  
  15. void say_hello() {
  16.     static int n = 0;  
  17.     switch (n)  {
  18.         case 0: cout << "Good morning" << endl; break;
  19.         case 1: cout << "Good arternoon" << endl; break;
  20.         case 2: cout << "Good evening" << endl; break;
  21.         case 3: cout << "Good night" << endl; break;
  22.  
  23.         default: break;
  24.     }
  25.     //n = ++n % 3;
  26.     n = n + 1;
  27.     n = n % 4;
  28. }
  29.  
  30. void task_hello() {
  31.     char ch = 'y';
  32.     while (ch != 'n') {
  33.         cin >> ch;
  34.         say_hello();
  35.     }
  36. }
  37.  
  38. /// <summary>
  39. /// copy_invert
  40. /// </summary>
  41. /// <param name="size"></param>
  42. /// <param name="arr"></param>
  43. /// <param name="copy_arr"></param>
  44. void copy_invert(int size, int* arr, int* copy_arr) {
  45.     for (int k = 0; k < size; k++) {
  46.         *(copy_arr + k) = *(arr + size - 1 - k);
  47.     }
  48. }
  49.  
  50. void test_copy_invert() {
  51.     int arr[]{ 88,89,90,91,92 };
  52.     int copy_arr[5];
  53.     copy_invert(size(arr), arr, copy_arr);
  54.  
  55.     if (copy_arr[0] == 92 &&
  56.         copy_arr[1] == 91 &&
  57.         copy_arr[2] == 90 &&
  58.         copy_arr[3] == 89 &&
  59.         copy_arr[4] == 88) {
  60.         cout << "OK" << endl;
  61.     }
  62.     else {
  63.         cout << "BAD" << endl;
  64.     }
  65. }
  66.  
  67. void show_arr(int size, int* arr) {
  68.     for (int k = 0; k < size; k++) {
  69.         cout << arr[k] << " ";
  70.     }
  71.     cout << endl;
  72. }
  73.  
  74. template <typename T>
  75. void my_swap(T& x, T& y) {
  76.     T temp = x;
  77.     x = y;
  78.     y = temp;
  79. }
  80.  
  81. void task_copy_invert() {
  82.     int arr[]{ 1,2,4,1,4,3,5,6,2,3,4 };
  83.     int copy[size(arr)];
  84.     copy_invert(size(arr), arr, copy);
  85.     show_arr(size(arr), arr);
  86.     show_arr(size(arr), copy);
  87.     int temp = copy[0];
  88.     copy[0] = copy[1];
  89.     copy[1] = temp;
  90.     show_arr(size(arr), copy);
  91. }
  92.  
  93. int main() {
  94.     //test_copy_invert();
  95.     //task_copy_invert();
  96.    
  97.     int x = 3, y = 4;
  98.     cout << "x: " << x << " y: " << y << endl;
  99.     my_swap(x, y);
  100.     cout << "x: " << x << " y: " << y << endl;
  101.    
  102.     double w = 55.6, v = 23.12;
  103.     cout << "w: " << w << " v: " << v << endl;
  104.     my_swap(w, v);
  105.     cout << "w: " << w << " v: " << v << endl;
  106.  
  107.     char ch1 = 'f', ch2 = 'a';
  108.     cout << "ch1: " << ch1 << " ch2: " << ch2 << endl;
  109.     my_swap(ch1, ch2);
  110.     cout << "ch1: " << ch1 << " ch2: " << ch2 << endl;
  111.    
  112.     //task_hello();
  113.     /*
  114.     cout << glob_sad << endl;
  115.  
  116.     glob_sad++;
  117.     glob_sad = glob_sad;
  118.  
  119.     cout << sum(1, 2, 3) << endl;
  120.     cout << sum(1, 2) << endl;
  121.     cout << sum(1, 2, 0) << endl;
  122.  
  123.     my_fun();
  124.     */
  125.     return 0;
  126. }
  127.  
  128.  
Advertisement
Add Comment
Please, Sign In to add comment