用C ++计算矩阵 [英] Calculate matrices in C++

查看:75
本文介绍了用C ++计算矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了这段代码,但是有3个我无法修复的错误.
有人可以帮我吗?

I have written this code but have 3 errors I can''t fix.
Can anyone help me with this?

//this program will find the product of two matrices (2columns X 2rows)...
#include<iostream.h>
class A {
	int x ;
	A(){}
	A(int a){x=a;}
	void out(){cout<<"Enter the value of matrix a:\n";}
};
class B{
	int x;
	B(){}
	B(int a){x=a;}
	void out(){cout<<endl<<"Enter the value of matrix b:\n";}
};
class C{
int x;
	C(){}
	C(int a){x=a;}
	void out(){cout<<"The multiplied value is:\n";}
};


void main() {
int a[4][4],b[4][4],c[4][4];
int i,j,k;
  A a1();
  a1.out();

for(i=0;i<2;i++){

for(j=0;j<2;j++){

cin>>a[i][j];
}
}
B a2();
a2.out();

for(i=0;i<2;i++){

for(j=0;j<2;j++){

cin>>b[i][j];
}
}


C a3();
a3.out();

for(i=0;i<2;i++){

for(j=0;j<2;j++){

c[i][j]=0;
for(k=0;k<2;k++){

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
for(i=0;i<2;i++){

for(j=0;j<2;j++){

cout<<c[i][j]<<"  ";
}
cout<<"\n";
}
}</iostream.h>

推荐答案

您忘记了将类方法(包括构造函数)声明为public.例如:
You forgot to declare class methods (constructor included) as public. For example:
class A {
    int x ;
public:
    A(){}
    A(int a){x=a;}
    void out(){cout<<"Enter the value of matrix a:\n";}
};



您用于创建类实例的语法是错误的,例如use



The syntax you used for creating class instances is wrong, for instance use

A a1;


代替


instead of

2010年同期:

A a1();


这篇关于用C ++计算矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆