Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #include <fstream>
 - #include <iostream>
 - #include <complex>
 - using namespace std;
 - void createReal(int sizes[], int n) {
 - char filenameA[256], filenameB[256];
 - int N;
 - for (int i = 0; i < n; i++) {
 - N = sizes[i];
 - sprintf_s(filenameA, "matrixA%d.txt", N);
 - sprintf_s(filenameB, "matrixB%d.txt", N);
 - ofstream matrixA(filenameA);
 - ofstream matrixB(filenameB);
 - if (!matrixA.is_open() || !matrixB.is_open()) {
 - cout << "Ошибка записи в файл" << endl;
 - return;
 - }
 - double* matrA = new double[N];
 - double* matrB = new double[N];
 - for (int i = 0; i < N; i++) {
 - double sum = 0.0;
 - for (int j = 0; j < N; j++) {
 - matrA[j] = rand() % 100;
 - sum += matrA[j];
 - }
 - matrA[i] = sum + 1.0;
 - for (int j = 0; j < N; j++) {
 - matrixA << matrA[j] << "\t";
 - }
 - matrixA << endl;
 - matrB[i] = rand() % 100;
 - matrB[i] = rand() % 100;
 - matrixB << matrB[i] << "\t";
 - }
 - matrixA.close();
 - matrixB.close();
 - delete[] matrA;
 - delete[] matrB;
 - }
 - }
 - void createComplex(int sizes[], int n) {
 - char filenameA[256], filenameB[256];
 - int N;
 - for (int i = 0; i < n; i++) {
 - N = sizes[i];
 - sprintf_s(filenameA, "matrixAComplex%d.txt", N);
 - sprintf_s(filenameB, "matrixBComplex%d.txt", N);
 - ofstream matrixA(filenameA);
 - ofstream matrixB(filenameB);
 - if (!matrixA.is_open() || !matrixB.is_open()) {
 - cout << "Ошибка записи в файл" << endl;
 - return;
 - }
 - complex<double>* matrA = new complex<double>[N];
 - complex<double>* matrB = new complex<double>[N];
 - for (int i = 0; i < N; i++) {
 - complex<double> sum = 0.0;
 - for (int j = 0; j < N; j++) {
 - matrA[j].real(rand() % 100);
 - matrA[j].imag(rand() % 100);
 - sum += matrA[j];
 - }
 - matrA[i] = sum + 1.0;
 - for (int j = 0; j < N; j++) {
 - matrixA << matrA[j] << "\t";
 - }
 - matrixA << endl;
 - matrB[i].real(rand() % 100);
 - matrB[i].imag(rand() % 100);
 - matrixB << matrB[i] << "\t";
 - }
 - matrixA.close();
 - matrixB.close();
 - delete[] matrA;
 - delete[] matrB;
 - }
 - }
 - int main()
 - {
 - int matrixsize[3] = { 100, 250, 500 };
 - createReal(matrixsize, 3);
 - createComplex(matrixsize, 3);
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment