Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- template < typename create, typename create1 >
- create* CreateFun (int &n, int &m, ifstream &inp)
- {
- inp >> n >> m;
- create *mus = new create [n];
- for (int i = 0; i < n; i++)
- {
- mus[i] = new create1[m];
- for ( int j=0; j < m; j++)
- inp >> mus[i][j];
- }
- return mus;
- }
- template < typename print >
- void PrintFun (print *mus, int &n, int &m)
- {
- for (int i = 0; i < n; i++)
- {
- cout << endl;
- for ( int j = 0; j < m; j++)
- cout << mus[i][j] << " ";
- }
- }
- template < typename rep, typename rep1 >
- void replace ( rep a, rep1 *mus, int n, int m)
- {
- for (int i=0; i < n; i++)
- for (int j = 0; j < m; j++)
- {
- if (mus[i][j] < a)
- mus[i][j] = a;
- }
- }
- int main()
- {
- ifstream inp ("massive.txt");
- ifstream in ("input.txt");
- int n, m;
- int **mus1 = CreateFun<int*, int> (n, m, inp);
- int a;
- cout << "enter number: ";
- cin >> a;
- replace <int,int*>(a, mus1, n, m);
- PrintFun <int*>(mus1, n, m);
- double b;
- cout << "enter number: ";
- cin >> b;
- double **mus2 = CreateFun<double*, double> (n, m, in);
- replace <double,double*>(b, mus2, n, m);
- PrintFun<double*>(mus2, n, m);
- inp.close();
- return 0;
- }
- 4 5
- 54 23 12 34 -9
- 32 12 3 -2 0
- 5 13 -56 0 18
- 67 87 2 1 90
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement