| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 488 人关注过本帖
标题:矩阵相加
取消只看楼主 加入收藏
cwl168
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2012-12-14
结帖率:8.33%
收藏
 问题点数:0 回复次数:0 
矩阵相加
#include<iostream.h>

class Matrix
{
public:
    Matrix();
    void input();
    void display();
    friend Matrix operator +(Matrix &,Matrix &);
protected:
    int mat[2][3];
};
Matrix::Matrix()
{
    for(int i=0;i<2;i++)
        for(int j=0;i<3;j++)
            mat[i][j]=0;
}
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;
        }
}
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;
}
int main()
{
    Matrix a,b,c;
    cout<<"input a Matrix:"<<endl;
    a.input();
    b.input();
   
    cout<<endl<<"intput a Matrix:"<<endl;
    a.display();
    cout<<endl<<"intput b Matrix:"<<endl;

    b.display();
    c=a+b;
    cout<<endl<<"Matrix c=Matrix a+Matrix b:"<<endl;
    c.display;

    return 0;
}
搜索更多相关主题的帖子: public include display mat void 
2013-01-11 15:36
快速回复:矩阵相加
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013252 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved