Заполнить массив из пятнадцати элементов случайным
образом:
а) вещественными значениями, лежащими в диапазоне от 0
до 1;
б) вещественными значениями х (22 ≤ х < 23);
в) вещественными значениями х (0 ≤ х < 10);
г) вещественными значениями х (–50 ≤ х < 50);
д) целыми значениями, лежащими в диапазоне от 0 до 10
включительно.
C/C++
Помогите пожалуйста решить задачку по C++, напишите полный текст кода пожалуйста
#include <iostream>
#include <random>
using namespace std;
class Random {
public:
Random() {
random_device device;
gen.seed(device());
gen_64.seed(device());
}
int next(int first, int last) {
uniform_int_distribution<int> range(first, last);
return range(gen);
}
double next(double first, double last) {
uniform_real_distribution<double> range(first, last);
return range(gen_64);
}
private:
mt19937 gen;
mt19937_64 gen_64;
};
struct Array {
static void fill(int* begin, int* end, int a, int b) {
if (a > b) swap(a, b);
Random rand;
while (begin != end) *begin++ = rand.next(a, b);
}
static void fill(double* begin, double* end, double a, double b) {
if (a > b) swap(a, b);
Random rand;
while (begin != end) *begin++ = rand.next(a, b);
}
static void show(double* begin, double* end, char delim) {
while (begin != end) cout << *begin++ << delim;
puts("");
}
static void show(int* begin, int* end, char delim) {
while (begin != end) cout << *begin++ << delim;
puts("");
}
};
int main() {
cout.setf(ios::fixed);
cout.precision(15U);
const auto n = 15U;
double a[n];
Array::fill(a, a + n, 0, 1);
Array::show(a, a + n, '\n');
Array::fill(a, a + n, 22, 23);
Array::show(a, a + n, '\n');
Array::fill(a, a + n, 0, 10);
Array::show(a, a + n, '\n');
Array::fill(a, a + n, -50, 50);
Array::show(a, a + n, '\n');
int b[n];
Array::fill(b, b + n, 0, 10);
Array::show(b, b + n, ' ');
system("pause > nul");
}
#include <random>
using namespace std;
class Random {
public:
Random() {
random_device device;
gen.seed(device());
gen_64.seed(device());
}
int next(int first, int last) {
uniform_int_distribution<int> range(first, last);
return range(gen);
}
double next(double first, double last) {
uniform_real_distribution<double> range(first, last);
return range(gen_64);
}
private:
mt19937 gen;
mt19937_64 gen_64;
};
struct Array {
static void fill(int* begin, int* end, int a, int b) {
if (a > b) swap(a, b);
Random rand;
while (begin != end) *begin++ = rand.next(a, b);
}
static void fill(double* begin, double* end, double a, double b) {
if (a > b) swap(a, b);
Random rand;
while (begin != end) *begin++ = rand.next(a, b);
}
static void show(double* begin, double* end, char delim) {
while (begin != end) cout << *begin++ << delim;
puts("");
}
static void show(int* begin, int* end, char delim) {
while (begin != end) cout << *begin++ << delim;
puts("");
}
};
int main() {
cout.setf(ios::fixed);
cout.precision(15U);
const auto n = 15U;
double a[n];
Array::fill(a, a + n, 0, 1);
Array::show(a, a + n, '\n');
Array::fill(a, a + n, 22, 23);
Array::show(a, a + n, '\n');
Array::fill(a, a + n, 0, 10);
Array::show(a, a + n, '\n');
Array::fill(a, a + n, -50, 50);
Array::show(a, a + n, '\n');
int b[n];
Array::fill(b, b + n, 0, 10);
Array::show(b, b + n, ' ');
system("pause > nul");
}
Юрий Савенков
Здравствуйте, можно ли вас попросить пожалуйста сделать код чуточку легче, спасибо
Похожие вопросы
- Помогите пожалуйста решить задачки c++
- Помогите пожалуйста решить задачу на C ИЛИ C#
- Помогите пожалуйста решить задачу на C++
- Помогите пожалуйста написать код на c++, выводящий имя, фамилию и дату рождения нескольких человек
- Помогите пожалуйста написать код на C++
- Помогите, пожалуйста, написать код на C (Си)
- Помогите, пожалуйста решить на C++, используя многомерные статические массивы
- Помоги пожалуйста написать программу на C++
- Помогите пожалуйста! Нужен код на C++
- Помогите, пожалуйста, написать программу на C++ (массивы)