你的代码有错,更改如下,
头文件bcmul.h
#include
#include "math.h"
class cbcmul
{
public:
//t m,n,k;
void ccbcmul (double **ar,double **ai,double **br,double **bi, int m,int n,int k ,double **cr,double **ci)
{
int i,j,d;
double p,q,r,s;
p=0,q=0;
for (i=0; i<=m-1; i++)
{
for (j=0; j<=n-1; j++)
{
for (d=0; d<=k-1; d++)
{
p=ar[i][d]*br[d][j];
q=-1*ai[i][d]*bi[d][j];
r=ar[i][d]*bi[d][j];
s=ai[i][d]*br[d][j];
cr[i][j]=p+q;
ci[i][j]=r+s;
}
}
}
//return;
}
};
cpp文件
#include "bcmul.h" //复数的N次方根
using namespace std;
int main()
{
double cr[2][1],ci[2][1];
double ar[2][5]={
{1,3,2,2,3},
{0,4,5,5,1}
};
double ai[2][5]={
{1,0,2,2,3},
{0,4,-4,5,1}
};
double br[5][1]={
{5},{0},{0},{2},{1}
};
double bi[5][1]={
{5},{0},{0},{3},{-1}
};
cbcmul cal;
cal.ccbcmul (&(*ar),&(*ai),2,5,1,&(*cr),&(*ci)); //米这里的引用有错误
cout <
return 0;
};
class cbcmul
{
public:
//t m,n,k;
void ccbcmul (double **ar,double **ai,double **br,double **bi, int m,int n,int k ,double **cr,double **ci)
{
int i,j,d;
double p,q,r,s;
p=0,q=0;
for (i=0; i<=m-1; i++)
{
for (j=0; j<=n-1; j++)
{
for (d=0; d<=k-1; d++)
{
p=ar[i][d]*br[d][j];
q=-1*ai[i][d]*bi[d][j];
r=ar[i][d]*bi[d][j];
s=ai[i][d]*br[d][j];
cr[i][j]=p+q;
ci[i][j]=r+s;
}
}
}
return;
}///少了
};
////////////////
///main 函数}后的";"去掉
///////////////
///cal.ccbcmul (&(*ar),&(*ai),2,5,1,&(*cr),&(*ci));
这样的调用可能会参数类型不一致的
下面的矩阵类实现了+,-,++,--运算,你可参考写出×的运算
#include
#include
#include
using namespace std;
class matrix
{
public:
matrix()
{
m=0;n=0;
pmatrix=NULL;
}
matrix(int im,int in)
{
m=im;n=in;
pmatrix=new int[m*n];
}
matrix(matrix& c)
{
m=c.m;n=c.n;
pmatrix=new int[m*n];
for (int i=0;i
}
~matrix() { delete [] pmatrix; }
void input();
void showmatrix();
matrix& operator++();
matrix& operator++(int);
matrix& operator--();
matrix& operator--(int);
matrix& operator=(matrix c);
private:
int m,n,*pmatrix;
};
void matrix::input()
{
cout<<"请输入 "<
}
void matrix::showmatrix()
{
cout<<"当前矩阵元素为:"<
for (int j=0;j
}
matrix& matrix::operator ++()
{
for (int i=0;i
return *this;
}
matrix& matrix::operator ++(int)
{
matrix temp(*this);
for (int i=0;i
return temp;
}
matrix& matrix::operator --()
{
for (int i=0;i
return *this;
}
matrix& matrix::operator --(int)
{
matrix temp(*this);
for (int i=0;i
return temp;
}
matrix& matrix::operator=(matrix c)
{
m=c.m;n=c.n;
delete [] pmatrix;
pmatrix=new int[m*n];
for(int i=0;i
return *this;
}
int _tmain(int argc, _TCHAR* argv[])
{
int m,n;
cout<<"请输入矩阵的行和列数:"<
matrix A(m,n);
matrix B;
A.input();
A.showmatrix();
cout<<"++A后,";
++A;
A.showmatrix();
cout<<"A++后,";
A++;
A.showmatrix();
cout<<"--A后,";
--A;
A.showmatrix();
cout<<"A--后,";
A--;
A.showmatrix();
B=A;
cout<<"B=A后,B";
B.showmatrix();
return 0;
}