#include <iostream>
using namespace std;
class Matrix //定义Matrix类
{public:
Matrix(); //默认构造函数
friend Matrix operator+(Matrix &,Matrix &); //重载运算符“+”
void input(); //输入数据函数
void display(); //输出数据函数
private:
int mat[2][3];
};
Matrix::Matrix() //定义构造函数
{for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
mat[i][j]=0;
}
Matrix operator+(Matrix &a,Matrix &b) //定义重载运算符“+”函数
{Matrix c;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
{c.mat[i][j]=a.mat[i][j]+b.mat[i][j];}
return c;
}
void Matrix::input() //定义输入数据函数
{cout<<"input value of matrix:"<<endl;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
cin>>mat[i][j];
}
void Matrix::display() //定义输出数据函数
{for (int i=0;i<2;i++)
{for(int j=0;j<3;j++)
{cout<<mat[i][j]<<" ";}
cout<<endl;}
}
int main()
{Matrix a,b,c;
a.input();
b.input();
cout<<endl<<"Matrix a:"<<endl;
a.display();
cout<<endl<<"Matrix b:"<<endl;
b.display();
c=a+b; //用重载运算符“+”实现两个矩阵相加
cout<<endl<<"Matrix c = Matrix a + Matrix b :"<<endl;
c.display();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
C++ 习题答案 C++习题答案
共207个文件
cpp:177个
h:7个
dsp:3个
需积分: 38 16 下载量 52 浏览量
2011-04-17
11:30:53
上传
评论 1
收藏 918KB RAR 举报
温馨提示
C++ 习题答案 C++ 习题答案 C ++ 习题答案 C++习题答案 C++习题答案 C++习题答案 C++习题答案 C++习题答案C++习题答案C++习题答案
资源推荐
资源详情
资源评论
收起资源包目录
C++ 习题答案 C++习题答案 (207个子文件)
xt7-10-2.cpp 3KB
xt7-10-1.cpp 3KB
xt6-15.cpp 3KB
xt12-5.cpp 3KB
xt11-10.cpp 2KB
xt13-4.cpp 2KB
xt6-10-2.cpp 2KB
xt3-20-1.cpp 2KB
xt11-9.cpp 2KB
xt6-10.cpp 2KB
xt12-4.cpp 2KB
xt6-16.cpp 2KB
xt13-5.cpp 2KB
xt3-12.cpp 1KB
xt6-13.cpp 1KB
xt11-4.cpp 1KB
xt11-3.cpp 1KB
xt10-7.cpp 1KB
xt10-2.cpp 1KB
xt7-5.cpp 1KB
xt5-8.cpp 1KB
XT6-3.cpp 1KB
xt11-4-2.cpp 1KB
xt10-5.cpp 1KB
xt3-13-1.cpp 1KB
xt4-2.cpp 1021B
xt5-7.cpp 1004B
xt9-12.cpp 986B
xt7-1-1.cpp 941B
xt7-9.cpp 921B
xt10-3.cpp 912B
xt9-9.cpp 902B
xt5-9.cpp 870B
xt7-6-1.cpp 860B
xt7-4.cpp 856B
XT6-4.cpp 848B
xt5-2.cpp 821B
xt7-8.cpp 814B
xt5-10.cpp 796B
xt7-3.cpp 795B
xt7-2.cpp 778B
xt9-10.cpp 776B
xt11-1.cpp 752B
xt11-2.cpp 750B
xt6-19.cpp 750B
xt6-5.cpp 729B
xt14-2.cpp 725B
xt8-6-2.cpp 723B
xt6-20.cpp 708B
xt9-2.cpp 692B
xt3-13-2.cpp 690B
xt9-11.cpp 685B
xt13-6-1.cpp 682B
xt8-6-1.cpp 669B
xt13-6-2.cpp 667B
xt6-2-2.cpp 662B
xt12-1.cpp 662B
xt10-1.cpp 661B
xt11-7.cpp 638B
Cylinder.cpp 607B
xt7-1-2.cpp 600B
xt6-12.cpp 600B
xt6-8.cpp 597B
xt6-2-1.cpp 593B
xt6-7.cpp 590B
xt7-6-2.cpp 585B
xt6-14.cpp 578B
xt4-9.cpp 559B
xt5-12-5.cpp 556B
xt6-9.cpp 554B
xt5-4.cpp 551B
xt6-17.cpp 549B
xt3-15.cpp 549B
xt6-11-2.cpp 548B
xt9-5.cpp 548B
xt3-11.cpp 544B
xt11-5.cpp 543B
xt14-1.cpp 536B
xt13-1-2.cpp 534B
xt6-11-1.cpp 529B
xt3-2.cpp 521B
xt5-1.cpp 518B
xt10-6.cpp 517B
xt5-17.cpp 505B
xt6-11-3.cpp 504B
xt5-12-1.cpp 501B
xt12-3-2.cpp 493B
xt5-5.cpp 492B
xt3-10.cpp 485B
xt5-12-2.cpp 484B
xt9-3.cpp 478B
xt5-11-1.cpp 477B
xt4-1.cpp 474B
xt3-20-3.cpp 468B
xt11-6.cpp 467B
xt4-7.cpp 467B
xt3-14.cpp 467B
xt12-3-3.cpp 465B
xt9-4.cpp 463B
xt9-7-1.cpp 462B
共 207 条
- 1
- 2
- 3
资源评论
chuccdeccyincc
- 粉丝: 4
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功