1. #include
#include
#include
#include
#include
const unsigned short int _size = 20;
int main()
{
std::array arr;
std::uniform_int_distribution distrib(201, 300); // от 1 до 500 числа будут в массиве
std::default_random_engine gen;
std::for_each(arr.begin(), arr.end(), [&distrib, &gen](auto& var)
{
var = distrib(gen);
});
std::copy(arr.begin(), arr.end(), std::ostream_iterator(std::cout, " "));
std::cout << std::endl;</p>
std::cout << "Сумма = " << std::accumulate(arr.begin(), arr.end(), 0) << std::endl;</p>
return 0;
}
2.
#include
#include
#include
#include
#include
const unsigned short int _size = 20;
void bubble_sort(auto &array)
{
for(unsigned int i = 0; i < array.size(); i++)
for(unsigned int j = 0; j < array.size() - i - 1; j++)
{
if(array[j] < array[j + 1])
std::swap(array[j], array[j+1]);
}
}
int main()
{
std::array arr;
std::uniform_int_distribution distrib(201, 300); // от 1 до 500 числа будут в массиве
std::default_random_engine gen;
std::for_each(arr.begin(), arr.end(), [&distrib, &gen](auto& var)
{
var = distrib(gen);
});
std::copy(arr.begin(), arr.end(), std::ostream_iterator(std::cout, " "));
std::cout << std::endl;</p>
bubble_sort(arr);//Сортировка
std::copy(arr.begin(), arr.end(), std::ostream_iterator(std::cout, " "));
return 0;
}
3.
#include
#include
#include
struct Film
{
private:
std::string _name;
unsigned short int _year;
long int _money;
public:
void get() const
{
std::cout << _name << " - " << _year << " - " << _money << std::endl;</p>
}
void set()
{
std::cin >> _name >> _year >> _money;
}
long int getMoney()
{
return _money;
}
};
int main()
{
std::array arr;
for(auto& i : arr)
i.set();
std::cout << std::endl << std::endl;</p>
for(auto& i : arr)
i.get();
std::sort(arr.begin(), arr.end(), [](Film& var1, Film& var2)
{
return var1.getMoney() < var2.getMoney();
});
std::cout << std::endl << std::endl;</p>
for(auto& i : arr)
i.get();
return 0;
}