编程基础篇:有两个矩阵a和b,均为2行3列。求两个矩阵之和。(C++重载)

 

 有两个矩阵a和b,均为2行3列。求两个矩阵之和。重载运算符“+”,使之能用于矩阵相加,如c=a+b。重载流插入运算符“<<”和流提取运算符“>>”,使之能用于该矩阵的输入和输出 

 

这题很简单,不需要赘述

 


 

#include 
using namespace std;
class qua {
	public :
		friend ostream& operator<<(ostream&,qua&);
		friend istream& operator>>(istream&,qua&);
		friend qua operator + (qua & c1,qua & c2);
		qua();
	private :
		int Q[2][3];
};
qua::qua() {
	for(int i=0; i<2; i++)
		for(int j=0; j<3; j++)
			Q[i][j]=0;
}
ostream & operator <<(ostream & output,qua& c) {
	for (int i=0; i<2; i++) {
		for (int j=0; j<3; j++)
			output<>(istream & input,qua& c) {
	for (int i=0; i<2; i++)
		for (int j=0; j<3; j++)
			input>>c.Q[i][j];
	return input;
}
qua operator +(qua & c1,qua & c2) {
	qua c3;
	for (int i=0; i<2; i++)
		for (int j=0; j<3; j++)
			c3.Q[i][j]=c1.Q[i][j]+c2.Q[i][j];
	return c3;
}
int main() {
	qua c1,c2,c3;
	cin>>c1>>c2;
	c3=c1+c2;
	cout<

 

你可能感兴趣的:(C++编程,数据结构学习笔记)