Task:

It is necessary to create matrices А and В type char dimension mxn and fill them with values ​​like

 str1 = "1.1 -3.3 44.6" str2 = "3.4 -44.8 5.0" 

Values ​​to enter from the keyboard, separating numbers with spaces. Fill one row of the matrix at a time. Then the string matrices need to be converted to double . Use the Split function to get individual lines, or the cin option. Calculate the expression С = ((А+В)^T)*(BA)

Questions:

  1. What is the Split function and how can I use it to solve this problem? I can not find a clear explanation. Both in video tutorials and on websites, strings are converted to double using cycles like

      for (int i =0; i< str1.length; i++){ if (str1[i] != ' ') { string intermidiate += str1[i]; } else { double dnum = atof (intermidiate.c_str()); intermidiate.clear() vector <double> vec1.push_back (dnum); } // Для последнего числа строки double dnum = atof (intermidiate.c_str); intermidiate.clear() vector <double> vec1.push_back (dnum); } 
  2. What would this for loop look like for a two-dimensional array?
  3. What is meant by "either cin capabilities"?

  4. Т is a two-dimensional array used to transpose a matrix (A+B) . How to implement it?

      #include <iostream> #include <cmath> #include <vector> #include <locale> #include <stdlib.h> #include <string> #include <windows.h> using namespace std; int main (void) { char *locale = setlocale (LC_ALL, ""); string str_a; cout << "Заполните первую строку матрицы А произвольными вещественными числами." << "В строке должно быть четыре числа. Разделите числа пробелами: \r\n"; getline(cin, str_a); string intermediate; double dnumA; vector <double> vecA1; for (int i = 0; i < str_a.length(); i++) { if (str_a [i] != ' ') { intermediate += str_a [i]; } else { dnumA = atof (intermediate.c_str()); intermediate.clear(); vecA1.push_back(dnumA); } } dnumA = atof (intermediate.c_str()); intermediate.clear(); vecA1.push_back(dnumA); 
  • IMHO, questions to clarify the task should be addressed to the author of this task. - αλεχολυτ
  • @alexolut The task is clear. It is not clear how to do it. I was able to translate a one-dimensional string array into double, but I don’t know how to do the same with the matrix. - Konstantin_SH
  • If one-dimensional could, then represent the matrix as a one-dimensional array, glued line by line. - αλεχολυτ
  • More? My code for the vector is adding in after the questions, thanks. - Konstantin_SH
  • Suppose there is a matrix of two rows: (1,2) and (3,4). Combine, we get (1,2,3,4) - one-dimensional array. - αλεχολυτ

0