01.07.2016, 15:04. Просмотров 239. Ответов 6
Добрый день.
Необходимо сгенерировать матрицу и заполнить ее.
Написал вот такую функцию
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| float** GenerateNaturalNumbers(int & n, int & m, std::string &Name)
{
// rows
float **mass = new float*[m];
//colums
for (int count = 0; count < m; count++)
mass[count] = new float[n];
std::ofstream cout(Name);
for (int i = 0; i < n; i++) {
for (int j = 1; j <= m; j++) {
cout << n*i + j << " ";
mass[i][j] = n*i + j;
//std::cout << mass[i][j] << " ";
}
cout << std::endl;
}
return mass;
} |
|
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| #include<iostream>
#include"mode.h"
#include<string>
#include<fstream>
int main() {
std::cout << "Enter matrix's size: n m" << std::endl;
int m=1, n=1;
std::cin >> n >> m;
int mode = 0;
std::cout << "Enter mode:" << std::endl;
std::cout << " 0 - a sequence natural numbers." << std::endl;
std::cout << " 1 - a random numbers" << std::endl;
std::cin >> mode;
std::cout << "Enter name of output file for 1st matrix:" << std::endl;
std::string Matrix1stOut = "";
std::cin >> Matrix1stOut;
std::cout << "Enter name of output file for 2nd matrix:" << std::endl;
std::string Matrix2stOut = "";
std::cin >> Matrix2stOut;
float **A; float **B;
switch (mode)
{
case 0: {
A = GenerateNaturalNumbers(n, m, Matrix1stOut);
std::cout << A[0][0]; // выводит мусор
B = GenerateNaturalNumbers(n, m, Matrix2stOut);
break;
}
default:
break;
}
return 0;
} |
|
Далее, при вызове ее в main получаю в A и B мусор. Где я допустил ошибку? Спасибо.