#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++程序设计-习题程序
共49个文件
cpp:38个
h:3个
dat:2个
需积分: 0 11 下载量 12 浏览量
2008-12-10
16:09:29
上传
评论
收藏 25KB RAR 举报
温馨提示
谭浩强C++程序设计-习题程序,俺也是找了很久,终于找到了,分享给大家,希望能对大家有所用!
资源详情
资源评论
资源推荐
收起资源包目录
C++程序设计-习题程序.rar (49个子文件)
谭浩强C++程序设计-习题程序
xt1
xt1-8.cpp 139B
xt1-9.cpp 220B
xt1-6.cpp 154B
xt1-7.cpp 281B
xt1-5.cpp 135B
xt11
xt11-9.cpp 2KB
xt11-5.cpp 543B
xt11-4-2.cpp 1KB
xt11-6.cpp 467B
xt11-10.cpp 2KB
xt11-8.cpp 435B
xt11-3.cpp 1KB
xt11-2.cpp 750B
xt11-4.cpp 1KB
xt11-7.cpp 638B
xt11-1.cpp 752B
xt13
xt13-3.cpp 214B
xt13-5.cpp 0B
xt13-2-1.cpp 268B
xt13-4.cpp 2KB
f1.dat 23B
f2.dat 49B
xt13-2-2.cpp 259B
xt13-1-1.cpp 397B
xt13-1-2.cpp 534B
xt10
xt10-3.cpp 912B
xt10-5.cpp 1KB
xt10-2.cpp 1KB
xt10-7.cpp 1KB
xt10-4.txt 1KB
xt10-1.cpp 661B
xt10-6.cpp 517B
xt12
xt12-3-1.cpp 460B
xt12-4.cpp 2KB
xt12-1.plg 3KB
xt12-1.opt 48KB
xt12-1.dsw 537B
CIRCLE.H 310B
xt12-1.cpp 662B
xt12-1.ncb 33KB
Cylinder.cpp 607B
xt12-3-2.cpp 493B
xt12-3-3.cpp 465B
POINT.H 279B
CYLINDER.H 357B
POINT.CPP 253B
xt12-1.dsp 3KB
xt12-5.cpp 3KB
CIRCLE.CPP 457B
共 49 条
- 1
delphi308
- 粉丝: 146
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Q1.py
- 企业政府灵智电子政务网站系统-lingzhi.rar
- Thinkphp内核开发Lsky Pro兰空图床网站源码.rar
- 基于FPGA(XC6SLX9)+SDRAM+AD7829多通道数据采集板硬件(原理图+PCB)工程文件.zip
- 阿里巴巴精准测试体系:基于代码链路分析的性能优化方案
- mmexport1714217773503.jpg
- 【图片网盘外链系统5.0】全新前端UI界面设计 支持图片违规检测网站自适应H5源码.rar
- jsp+sql的BBS论坛系统.zip
- 网盘外链PHP开发彩虹网盘外链程序源码.rar
- 2023年最新文件快递柜系统网站源码 保护用户隐私的匿名口令分享和临时文件分享功能.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0