Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <math.h>
- #include <random>
- #include <algorithm>
- using namespace std;
- #define rand_min 0 // m1
- #define rand_max 100 // m2
- // генерирует случайное число в диапазоне от A до B
- int random_int(int a, int b) {
- return a + (rand() % ( b - a + 1 ) );
- }
- class Array {
- private:
- vector<double> arr;
- public:
- Array(int);
- void print();
- void firstTask();
- void secondTask();
- void thirdTask();
- };
- Array::Array(int size) {
- arr = vector<double>();
- for (int i = 0; i < size; i++)
- arr.push_back(random_int(rand_min, rand_max));
- }
- void Array::print() {
- for (int i = 0; i < arr.size(); i++)
- cout << arr[i] << " ";
- cout << endl;
- }
- bool gretter_10(int i) {
- return (i > 10);
- }
- // первое задание (количесов эл больше 10)
- void Array::firstTask() {
- int count = count_if(arr.begin(), arr.end(), gretter_10);
- cout << "Количество элементов со значениями больше 10: " << count << endl;
- }
- // второе задание (квадратный корень из всех элементов)
- void Array::secondTask() {
- double sqrt_sum = sqrt(accumulate(arr.begin(), arr.end(), 0));
- cout << "Квадратный корень из всех элементов: " << sqrt_sum << endl;
- }
- // третье задание (сумма всех элементов)
- void Array::thirdTask() {
- double sum = accumulate(arr.begin(), arr.end(), 0);
- cout << "Сумма всех элементов: " << sum << endl;
- }
- int main() {
- setlocale(LC_ALL, "rus");
- srand(time(NULL));
- int size;
- cout << "Введите размер массива: ";
- cin >> size;
- Array a = Array(size);
- cout << "\nИсходный массив: " << endl;
- a.print();
- a.firstTask();
- a.secondTask();
- a.thirdTask();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment