重载运算符"^"实现数组各对应元素相乘方,具体要求如下: 题目要求 重载运算符"^"实现数组各对应元素相乘方,具体要求如下: #include<iostream> #include<string> #include<iomanip> using namespace std; class A { private: int a[3]; public: A(int b[3]) { for (int i = 0; i < 3; i++) { a[i] = b[i]; } } A() { } friend A operator ^(A& b1, A& b2) { A b3; int c[3] = { 1,1,1 }, i, j; for (i = 0; i < 3; i++) { for (j = 0; j < b2.a[i]; j++) { c[i] = c[i] * b1.a[i]; } } for (i = 0; i < 3; i++) { b3.a[i] = c[i]; } return b3; } void printf() { for (int i = 0; i < 3; i++) { cout << setw(3) << a[i]; } cout << endl; } }; int main() { int a[3],b[3],i; for (i = 0; i < 3; i++) { cin >> a[i]; } for (i = 0; i < 3; i++) { cin >> b[i]; } A arr1(a), arr2(b); A arr3; arr3 = arr1 ^ arr2; arr1.printf(); arr2.printf(); arr3.printf(); return 0; }