diff --git "a/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/C++\347\250\213\345\272\217\350\256\276\350\256\241\345\256\236\351\252\214-\347\254\25403\346\254\241\345\256\236\351\252\214\351\242\230\347\233\256.doc" "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/C++\347\250\213\345\272\217\350\256\276\350\256\241\345\256\236\351\252\214-\347\254\25403\346\254\241\345\256\236\351\252\214\351\242\230\347\233\256.doc" new file mode 100644 index 0000000..305489a Binary files /dev/null and "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/C++\347\250\213\345\272\217\350\256\276\350\256\241\345\256\236\351\252\214-\347\254\25403\346\254\241\345\256\236\351\252\214\351\242\230\347\233\256.doc" differ diff --git "a/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\200\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\346\225\260\347\273\204\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\346\225\260\344\271\230.cpp" "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\200\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\346\225\260\347\273\204\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\346\225\260\344\271\230.cpp" new file mode 100644 index 0000000..b057c16 --- /dev/null +++ "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\200\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\346\225\260\347\273\204\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\346\225\260\344\271\230.cpp" @@ -0,0 +1,41 @@ +#include +#include //用于输出格式控制的库 +using namespace std; +void fun2(int*& M, int n1, int n2) //n1,n2为矩阵的行数和列数,M为指向矩阵的指针 +{ + cout << "Please input the number that the Matrix will multipy:"; //提示用户输入乘数 + int number; + cin >> number; + for (int i = 0; i < n1 * n2; i++) //遍历矩阵中的每一个元素 + { + M[i] = M[i] * number; //将元素乘上用户输入的乘数 + cout << setw(3) << M[i] << right; //输出格式控制:每个元素占3个字符宽度,右对齐 + if ((i + 1) % n2 == 0)cout << endl; //每输出完一行就换行 + } +} + +void fun1(int n1, int n2) +{ + cout << "Please input the elements of the Matrix:"; //提示用户输入矩阵元素 + int* M = new int[n1 * n2]; //动态分配一维数组,用于存放矩阵元素 + for (int i = 0; i < n1 * n2; i++) //遍历数组,输入元素 + { + int temp; + cin >> temp; + M[i] = temp; + cout << setw(3) << M[i] << right; //输出格式控制:每个元素占3个字符宽度,右对齐 + if ((i + 1) % n2 == 0)cout << endl; //每输出完一行就换行 + } + fun2(M, n1, n2); //调用fun2函数,对矩阵进行乘法运算 +} + + + +int main() +{ + int n1, n2; + cout << "Please input the dimension of the Matrix:"; //提示用户输入矩阵的行数和列数 + cin >> n1 >> n2; + cout << endl; + fun1(n1, n2); //调用fun1函数,输入矩阵元素并进行乘法运算 +} \ No newline at end of file diff --git "a/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\211\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\346\225\260\347\273\204\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\350\275\254\347\275\256.cpp" "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\211\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\346\225\260\347\273\204\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\350\275\254\347\275\256.cpp" new file mode 100644 index 0000000..7f623f4 --- /dev/null +++ "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\211\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\346\225\260\347\273\204\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\350\275\254\347\275\256.cpp" @@ -0,0 +1,97 @@ +#include +#include // 用于输出格式控制的库 +using namespace std; + +void rotate90DegreesClockwise(int**& M, int& n1, int& n2) +{ + int** temp = new int* [n2]; // 创建临时二维数组 + for (int i = 0; i < n2; i++) + { + temp[i] = new int[n1]; + } + + // 顺时针旋转矩阵 + for (int i = 0; i < n1; i++) + { + for (int j = 0; j < n2; j++) + { + temp[j][n1 - i - 1] = M[i][j]; + } + } + + // 释放原矩阵内存 + for (int i = 0; i < n1; i++) + { + delete[] M[i]; + } + delete[] M; + + // 更新行列数和矩阵指针 + swap(n1, n2); + M = temp; +} + +void fun2(int**& M, int n1, int n2, int angle) // n1,n2为矩阵的行数和列数,M为指向矩阵的指针,angle为旋转角度 +{ + if (angle % 90 != 0 || angle < 0 || angle >= 360) // 检查角度是否是90的倍数且在有效范围内 + { + cout << "旋转角度必须是90度的倍数且在0到360度之间。" << endl; + return; + } + + int rotations = angle / 90; // 计算需要旋转的次数 + + while (rotations > 0) + { + rotate90DegreesClockwise(M, n1, n2); + rotations--; + } + + // 打印旋转后的矩阵 + for (int i = 0; i < n1; i++) + { + for (int j = 0; j < n2; j++) + { + cout << setw(3) << M[i][j] << right; // 输出格式控制:每个元素占3个字符宽度,右对齐 + } + cout << endl; // 每输出完一行就换行 + } +} + +void fun1(int n1, int n2) +{ + cout << "Please input the elements of the Matrix:"; // 提示用户输入矩阵元素 + int** M = new int* [n1]; // 动态分配二维数组,用于存放矩阵元素 + for (int i = 0; i < n1; i++) + { + M[i] = new int[n2]; // 为每一行分配内存 + for (int j = 0; j < n2; j++) // 遍历数组,输入元素 + { + int temp; + cin >> temp; + M[i][j] = temp; + cout << setw(3) << M[i][j] << right; // 输出格式控制:每个元素占3个字符宽度,右对齐 + } + cout << endl; // 每输出完一行就换行 + } + + int angle; + cout << "请输入旋转角度(必须是90度的倍数):"; // 提示用户输入旋转角度 + cin >> angle; + fun2(M, n1, n2, angle); // 调用fun2函数,对矩阵进行旋转 + for (int i = 0; i < n1; i++) // 释放分配的内存 + { + delete[] M[i]; + } + delete[] M; +} + +int main() +{ + int n1, n2; + cout << "Please input the dimension of the Matrix:"; // 提示用户输入矩阵的行数和列数 + cin >> n1 >> n2; + cout << endl; + fun1(n1, n2); // 调用fun1函数,输入矩阵元素并进行旋转 + return 0; +} diff --git "a/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\351\223\276\350\241\250\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\346\225\260\344\271\230.cpp" "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\351\223\276\350\241\250\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\346\225\260\344\271\230.cpp" new file mode 100644 index 0000000..af7ad79 --- /dev/null +++ "b/11522105-\345\217\266\344\277\212\346\263\275-\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\351\241\271\344\275\234\344\270\232\357\274\214\345\210\251\347\224\250\351\223\276\350\241\250\345\256\236\347\216\260\347\232\204\347\237\251\351\230\265\346\225\260\344\271\230.cpp" @@ -0,0 +1,60 @@ +#include +#include +using namespace std; + +typedef struct my +{ + int p; + struct my* next; +}Matrix; + + +void fun(Matrix*& M, int n1, int n2) +{ + cout << "Please input the number that the Matrix will multipy:"; //提示用户输入乘数 + int number; + cin >> number; + Matrix* r = M->next; + for (int i = 0; r != NULL && i < n1 * n2; r = r->next, i++) + { + r->p = r->p * number; + cout << setw(3) << r->p << right; //输出格式控制:每个元素占3个字符宽度,右对齐 + if ((i + 1) % n2 == 0)cout << endl; //每输出完一行就换行 + } +} + + + + +void Creat(Matrix*& M, int n1, int n2) +{ + Matrix* r = M; + cout << "Please input the elements of the Matrix:"; + for (int i = 0; i < n1 * n2; i++) + { + int temp; + cin >> temp; + Matrix* myma = new Matrix; + myma->p = temp; + cout << setw(3) << temp << right; //输出格式控制:每个元素占3个字符宽度,右对齐 + if ((i + 1) % n2 == 0)cout << endl; //每输出完一行就换行 + myma->next = r->next; + r->next = myma; + r = myma; + } + fun(M, n1, n2); +} + + + +int main() +{ + int n1, n2; + cout << "Please input the dimension of the Matrix:"; //提示用户输入矩阵的行数和列数 + cin >> n1 >> n2; + cout << endl; + Matrix* M; + M = new Matrix; + M->next = NULL; + Creat(M, n1, n2); +} \ No newline at end of file