Seal_of_approval

p43e11

Apr 5th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. template < typename create, typename create1 >
  7. create* CreateFun (int &n, ifstream &inp)
  8. {
  9. inp >> n;
  10. create *mas = new create [n];
  11. for (int i = 0; i < n; i++)
  12. {
  13. mas[i] = new create1 [n];
  14. for ( int j = 0; j < n; j++)
  15. inp >> mas[i][j];
  16. }
  17. return mas;
  18. }
  19.  
  20. template < typename print >
  21. void PrintFun (print *mas, int &n)
  22. {
  23. for (int i = 0; i < n; i++)
  24. {
  25. cout << endl;
  26. for ( int j = 0; j < n; j++)
  27. cout << mas[i][j] << " ";
  28. }
  29. }
  30.  
  31. template < typename X >
  32. void res (X **mas, int &n, float &z)
  33. {
  34. int count = 0;
  35. X result = 0;
  36. for (int i = 0; i < n-1; i++)
  37. for (int j = 0; j < n; j++)
  38. if (j > i)
  39. {
  40. result+=mas[i][j];
  41. count++;
  42. }
  43. z=(float)result/(float)count;
  44. }
  45.  
  46. int main(void)
  47.  
  48. {
  49. ifstream inp ("input.txt");
  50. int n;
  51. float z;
  52. int **mas = CreateFun <int*, int> (n, inp);
  53. PrintFun <int*> (mas, n);
  54. res <int> (mas, n, z);
  55. cout << endl << "Answer = " << z << endl;
  56. inp.close();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment