avr39ripe

cppArrayExamples

Jul 7th, 2021
968
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3.  
  4. int main()
  5. {
  6.     int vag1{ 25 };
  7.     int vag2{ 5 };
  8.     int vag3{ 1 };
  9.     int vag4{ 10 };
  10.     int vag5{ 10 };
  11.  
  12.     int numElems{ 0 };
  13.  
  14.     //std::cin >> numElems;
  15.  
  16.     const int vagsSize{7 }; // compile time const
  17.     const int sizeRT{ numElems }; // run time const
  18.  
  19.     int maxPassangers{ 100 };
  20.     int minPassangers{};
  21.  
  22.  
  23.     //// BAAAD!!!
  24.     //const int size{ 10000 };
  25.     //int vags[size]{1, 2, 3, 4, 5, 6, 7};
  26.  
  27.     //int vagsLenth{};
  28.     //std::cin >> vagsLenth;
  29.  
  30.  
  31.     //for (int i{ 0 }; i < vagsLenth; ++i)
  32.     //{
  33.     //  std::cout << vags[i] << ' ';
  34.     //}
  35.  
  36.     //// BAAAD!!!
  37.     const int monthCount{ 12 };
  38.     int monthNumber;
  39.     const int months[monthCount]{ 31,28,31,30,31,30,31,31,30,31,30,31 };
  40.  
  41.     std::cin >> monthNumber;
  42.  
  43.     --monthNumber;
  44.  
  45.     std::cout << months[monthNumber] << '\n';
  46.  
  47.     int sum{ 0 };
  48.  
  49.     for (int i{ 0 }; i < vagsSize; ++i)
  50.     {
  51.         std::cout << vags[i] << ' ';
  52.     }
  53.     std::cout << '\n';
  54.  
  55.     for (int i{ 0 }; i < vagsSize; sum += vags[i++]);
  56.  
  57.     for (int i{ 0 }; i < vagsSize; ++i)
  58.     {
  59.         sum += vags[i];
  60.     }
  61.  
  62.  
  63.     for (int i{ 0 }; i < vagsSize; ++i)
  64.     {
  65.         std::cout << vags[i] << ' ';
  66.     }
  67.  
  68.     std::cout << '\n';
  69.  
  70.     std::cout << "Sum = " << sum << '\n';
  71.     //int day;
  72.     //int month;
  73.     //int year;
  74.  
  75.     //const int dateSize{ 3 };
  76.     //enum Date {day, month, year};
  77.     //int date[dateSize];
  78.  
  79.     //date[Date::year] = 1982;
  80.     //date[Date::day] = 31;
  81.     //date[Date::month] = 1;
  82.  
  83.     //// 0 -day, 1- month , 2 - year
  84.     //date[2] = 1982;
  85.     //date[0] = 31;
  86.     //date[1] = 1;
  87.  
  88.  
  89.     //date[0] = 1975;
  90.  
  91.  
  92.     //[0[][][][]][1[][][][]][2[][][][]][3[][][][]][4[][][][]][5[][][][]][6[][][][]]
  93.  
  94.     //[25][][][] [5][][][] [2][][][] [10][][][] [11][][][] [78][][][] [87][][][]
  95.     //100        104        108      112
  96.     //
  97.     //const int strLen{ 5 };
  98.     //char str[strLen]{'H',45,'l',36.6,false};
  99.  
  100.  
  101.     //for (int i{ 0 }; i < strLen; ++i)
  102.     //{
  103.     //  std::cout << str[i] << ' ';
  104.     //}
  105.     //std::cout << '\n';
  106.  
  107.     //vags[0] = 25;
  108.     //vags[1] = 5;
  109.     //vags[2] = 2;
  110.     //vags[3] = 10;
  111.     //vags[4] = 11;
  112.     //vags[5] = 78;
  113.  
  114.  
  115.     //maxPassangers = vags[0];
  116.     //minPassangers = vags[0];
  117.  
  118.     //vags[7] = 1;
  119.  
  120.     //for (int idx{ 0 }; idx < vagsSize; ++idx)
  121.     //{
  122.     //  std::cout << vags[idx] << '\n';
  123.     //  //maxPassangers = maxPassangers > vags[idx] ? maxPassangers : vags[idx];
  124.     //  //minPassangers = minPassangers < vags[idx] ? minPassangers : vags[idx];
  125.  
  126.     //  if (vags[idx] > maxPassangers) { maxPassangers = vags[idx]; }
  127.     //  if (vags[idx] < minPassangers) { minPassangers = vags[idx]; }
  128.     //}
  129.  
  130.     //std::cout << "max passangers is: " << maxPassangers << '\n';
  131.     //std::cout << "min passangers is: " << minPassangers << '\n';
  132.  
  133.     /*std::cout << vags[idx++] << '\n';
  134.     std::cout << vags[idx++] << '\n';
  135.     std::cout << vags[idx++] << '\n';
  136.     std::cout << vags[idx++] << '\n';
  137.     std::cout << vags[idx++] << '\n';*/
  138.  
  139.  
  140.  
  141.     //
  142.     //
  143.  
  144.     ////if (vag1 > vag2)
  145.     ////{
  146.     ////    maxPassangers = vag1;
  147.     ////}
  148.     ////else
  149.     ////{
  150.     ////    maxPassangers = vag2;
  151.     ////}
  152.  
  153.     ////(vag1 > vag2) ? maxPassangers = vag1 : maxPassangers = vag2;
  154.  
  155.     ////maxPassangers = vag1 > vag2 ? vag1 > vag3 ? vag1 : vag3 : vag2 > vag3 ? vag2 : vag3;
  156.  
  157.     //maxPassangers = vag1 > vag2 ? vag1 : vag2;
  158.     //maxPassangers = maxPassangers > vag3 ? maxPassangers : vag3;
  159.     //maxPassangers = maxPassangers > vag4 ? maxPassangers : vag4;
  160.     //maxPassangers = maxPassangers > vag5 ? maxPassangers : vag5;
  161.  
  162.  
  163.     ////maxPassangers = vag1 > vag2 ? vag1 : vag2;
  164.     ////minPassangers = vag1 < vag2 ? vag1 : vag2;
  165.  
  166.  
  167.     //std::cout << "max passangers is: " << maxPassangers << '\n';
  168.     ////std::cout << "min passangers is: " << minPassangers << '\n';
  169.  
  170. }
RAW Paste Data