Скачиваний:
84
Добавлен:
15.06.2014
Размер:
1.82 Кб
Скачать
#include <iostream>
#include <conio.h>
#include <math.h>
#include <time.h>
#include <iomanip>
using namespace std;

class massiv
{
public:
	float** create(int, int);
	void zadanie(float**, int, int);
	void delet(float**, int, int);
};

void main()
{
	int M, N;
	float **arra;
	 cin.exceptions(std::cin.failbit);
 
        while ( true ){
                try {
	cout << "Vvedite kol-vo stroc"<<endl;
	cin >> M;
	cout <<endl<< "Vvedite kol-vo stolbcov"<<endl;
	cin >> N;
	cout<<endl;
	     if ((M>0)&&(N>0)) break;
		 else cout<< endl<< "Nugni chisla > 0"<<endl;
                }
                catch( std::istream::failure e ){
                        cerr << "Vvedite tolko chisla!" << endl;
                        cin.clear();
                        cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
                }
        }
	massiv obj;
	arra=obj.create(M,N);
	obj.zadanie(arra,M,N);
	obj.delet(arra,M,N);
	_getch();
}

float** massiv::create(int m, int n)
{
	float **ar = new float*[m];
	for (int i = 0; i < m; i++) 
		ar[i] = new float[n];
	cout << "zadan massiv" << endl;
		srand(time(NULL));
	for (int i=0; i<m; i++)
	{	for (int j=0;j<n; j++)
		{			                   
			ar[i][j]=(float)(rand()%10000)/1000;
			cout<<setw(6)<<ar[i][j];
		}
	cout<<endl;
	}
	return ar;
}

void massiv::zadanie(float **a,int m, int n)
{
	float sum=0;
	for (int i=0; i<m; i++)
		for(int j=0; j<n; j++)
			sum+=a[i][j];
	float sr=sum/((float)m*n);
	float ss=0;
	for (int i=0; i<m; i++)
		for(int j=0; j<n; j++)
			ss=ss+((float)a[i][j]-sr)*((float)a[i][j]-sr);
	float def=ss/((float)m*n-1);
	cout << endl<< "Srednee "<< sr;
	sr=0;
	cout<< endl<< "Dispersia "<< def;
	def=0;
}

void massiv::delet(float **a,int m, int n)
{
	delete[]a;
}
Соседние файлы в папке Laba3_Shakur_4
  • #
    15.06.20141.82 Кб84Laba3_Shakur_4.cpp
  • #
    15.06.20143.93 Кб82Laba3_Shakur_4.vcxproj
  • #
    15.06.2014963 б81Laba3_Shakur_4.vcxproj.filters
  • #
    15.06.2014143 б81Laba3_Shakur_4.vcxproj.user