修正一点小问题

This commit is contained in:
iridiumR 2022-03-15 07:21:48 +08:00
parent 2762f48e39
commit f7d1dd1da3
2 changed files with 11 additions and 11 deletions

View file

@ -2,8 +2,8 @@
* @Author: iR * @Author: iR
* @Date: 2022-03-12 14:46:07 * @Date: 2022-03-12 14:46:07
* @LastEditors: iR * @LastEditors: iR
* @LastEditTime: 2022-03-12 17:13:51 * @LastEditTime: 2022-03-15 07:17:38
* @FilePath: \Code\1-2a\main.cpp * @FilePath: \Code\1-2\main.cpp
* @Description: * @Description:
* @custom_string_iR_Mail: Mail: i@iridium.cyou * @custom_string_iR_Mail: Mail: i@iridium.cyou
* @custom_string_iR_copyright: Copyright (c) ${now_year} by iR, All Rights Reserved. * @custom_string_iR_copyright: Copyright (c) ${now_year} by iR, All Rights Reserved.
@ -17,27 +17,27 @@ int main()
double data[] = {1, 2, 3, 4, 5, 6}; double data[] = {1, 2, 3, 4, 5, 6};
Matrix<double> a(3, 2, data); Matrix<double> a(3, 2, data);
std::cout << "a" << std::endl std::cout << "a" << std::endl
<< a.at(0, 0) << " " << a.at(1, 0) << a.at(2, 0) << std::endl << a.at(0, 0) << " " << a.at(1, 0) << " " << a.at(2, 0) << std::endl
<< a.at(0, 1) << " " << a.at(1, 1) << a.at(2, 2) << std::endl; << a.at(0, 1) << " " << a.at(1, 1) << " " << a.at(2, 1) << std::endl;
std::cout << "+=" << std::endl; std::cout << "+=" << std::endl;
Matrix<double> b(3, 2, data); Matrix<double> b(3, 2, data);
std::cout << "b" << std::endl std::cout << "b" << std::endl
<< b.at(0, 0) << " " << b.at(1, 0) << b.at(2, 0) << std::endl << b.at(0, 0) << " " << b.at(1, 0) << " " << b.at(2, 0) << std::endl
<< b.at(0, 1) << " " << b.at(1, 1) << b.at(2, 2) << std::endl; << b.at(0, 1) << " " << b.at(1, 1) << " " << b.at(2, 1) << std::endl;
std::cout << "Answer" << std::endl; std::cout << "Answer" << std::endl;
a += b; a += b;
std::cout << "a" << std::endl std::cout << "a" << std::endl
<< a.at(0, 0) << " " << a.at(1, 0) << a.at(2, 0) << std::endl << a.at(0, 0) << " " << a.at(1, 0) << " " << a.at(2, 0) << std::endl
<< a.at(0, 1) << " " << a.at(1, 1) << a.at(2, 2) << std::endl; << a.at(0, 1) << " " << a.at(1, 1) << " " << a.at(2, 1) << std::endl;
std::cout << "c=a+b" << std::endl; std::cout << "c=a+b" << std::endl;
Matrix<double> c = a + b; Matrix<double> c = a + b;
std::cout << "Answer" << std::endl; std::cout << "Answer" << std::endl;
std::cout << "c" << std::endl std::cout << "c" << std::endl
<< c.at(0, 0) << " " << c.at(1, 0) << a.at(2, 0) << std::endl << c.at(0, 0) << " " << c.at(1, 0) << " " << c.at(2, 0) << std::endl
<< c.at(0, 1) << " " << c.at(1, 1) << a.at(2, 0) << std::endl; << c.at(0, 1) << " " << c.at(1, 1) << " " << c.at(2, 1) << std::endl;
return 0; return 0;
} }

View file

@ -175,7 +175,7 @@ Matrix<T>::Matrix(int w, int h, const T elements[])
_width = w; _width = w;
_height = h; _height = h;
_mat = new Vector<T>; _mat = new Vector<T>(w * h);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
_mat->put(i, elements[i]); _mat->put(i, elements[i]);
} }