Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <iomanip>
- using namespace std;
- using box_t = pair<int*, const size_t>;
- class Array {
- public:
- static void fill(box_t& box, const int a, const int b) {
- auto[sequence, length] = box;
- for (auto i = 0U; i < length; ++i) sequence[i] = generate(a, b);
- }
- static void show(const box_t& box, const streamsize width = 2U) {
- auto[sequence, length] = box;
- for (auto i = 0U; i < length; ++i) cout << setw(width) << sequence[i];
- cout.put('\n');
- }
- static void replace(box_t& box, const int dest, const int src) {
- auto[sequence, length] = box;
- for (auto i = 0U; i < length; ++i) if (sequence[i] == dest) sequence[i] = src;
- }
- private:
- static int generate(int a, int b) {
- if (a > b) swap(a, b);
- const uniform_int_distribution<> uid(a, b);
- random_device rd;
- mt19937 gen(rd());
- return uid(gen);
- }
- };
- int main() {
- int sequence[10U];
- box_t box{ sequence, size(sequence) };
- Array::fill(box, 7, 14);
- Array::show(box, 4U);
- Array::replace(box, 7, 0);
- Array::show(box, 4U);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement