Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <random>
- #include <ctime>
- #include<vector>
- #include<iterator>
- using namespace std;
- class DAR{
- public:
- const int N = 15;
- int rch = 10;
- int *point = new int[N];
- DAR(){};
- DAR(int N, int rch){
- uniform_int_distribution<int> uid(10, 20);
- mt19937 gen(time(0));
- int *point = new int[N];
- for (int i = 0; i < rch; i++){
- point[i] = uid(gen);
- }
- };
- void Display(int*ptr, int n){
- for (int i = 0; i < n; ++i)
- {
- cout << "[" << i + 1 << "] - " << ptr[i] << endl;
- }
- }
- int fmin(int *a, int n)
- {
- int min = a[10];
- int imin = 0;
- for (int i = 0; i < n; i++)
- {
- if (a[i] < min)
- {
- min = a[i];
- imin = i;
- }
- }
- return imin;
- }
- void Add(int *arr, int n, int value){
- int k = fmin(arr, n);
- try{
- for (int i = 0; i < n; ++i)
- arr[i] = i + 1;
- ++n;
- int * temp = new int[n];
- for (int i = 0; i < n; ++i)
- {
- if (i < k - 1)
- temp[i] = arr[i];
- else if (i == k - 1)
- temp[i] = value;
- else
- temp[i] = arr[i - 1];
- }
- delete[] arr;
- *arr = *temp;
- for (int i = 0; i < n; ++i)
- arr[i] = temp[i];
- delete[]temp;
- }
- catch (out_of_range){ throw new exception; }
- system("pause");
- }
- ~DAR(){};
- };
- void main()
- {
- DAR r(15,10);
- int value;
- cin >> value;
- r.Add(r.point, r.rch, value);
- r.Display(r.point, r.rch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement