https://pastein.ru/t/hr

  скопируйте уникальную ссылку для отправки



#include <iostream>
#include <string>
#include <Windows.h>
#include <ctime>
using namespace std;
template <class T>
T* massiv(int n)
{
	T *a;
	a = new T[n];
	for (int i = 0; i < n; i++)
	{
		a[i] = (T)(rand() % 10000 - 5000) / 100;
		cout << a[i] << "";
	}
	cout << endl;
	return a;
}
template <typename X>
X tapsyrma(const X *c, int i)
{
	X sum = 0;
	for (int j = 0; j < i; j++) if (c[j] >0) sum += c[j];
	return sum;
}
int main()
{
	srand(time(0));
	int *a;
	a = massiv<int>(5);
	cout << "sum(a) = " << tapsyrma <int>(a, 5) << endl;
	double *b;
	b = massiv <double>(4);
	cout << "sum(b) = " << tapsyrma <double>(b, 4) << endl;
	system("pause");
	return 0;
}