c++之学习程序Matrix_1
来源:互联网 发布:思迅商云网络断开 编辑:程序博客网 时间:2024/05/21 06:55
还是关于重载运算的程序,是对关于矩阵相加的"+"重载;不知道为什么有个问题还是出了点问题,同学来借用电脑,只好先放着,以后再思考吧。
#include<iostream>
using namespace std;
#define N 2
#define M 3
class Matrix
{
public:
Matrix();
friend Matrix operator+(Matrix &,Matrix &);
void input();
void display();
private:
int mat[N][M];
};
Matrix::Matrix()
{
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
mat[i][j]=0;
}
Matrix operator+(Matrix &a,Matrix &b)
{
Matrix c;
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
c.mat[i][j]=a.mat[i][j]+b.mat[i][j];
return c;
}
void Matrix::input()
{
cout<<"input value of the Matrix [N][M]"<<endl;
for(i=0;i<N;i++)
for(j=0;j<M;j++)
cin>>mat[i][j];
}
void Matrix::display()
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
cout<<mat[i][j]<<" ";
cout<<endl;
}
}
int main()
{
Matrix a,b,c;
a.input();
b.input();
c=a+b;
c.display();
return 0;
}
错误提示:
C:/Program Files/Microsoft Visual Studio/MyProjects/Matrix/Matrix.cpp(9) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
Matrix.obj - 1 error(s), 0 warning(s)
- c++之学习程序Matrix_1
- 【C#】C#学习笔记之程序集
- 我的c程序学习之路
- C语言程序学习之俄罗斯方块
- μc/GUI学习笔记之二第一个程序
- 03.IOS学习笔记之第一个C语言程序
- C++基础学习之7 - 与C程序对话
- 学习C程序
- c程序学习笔记
- C程序的学习
- C程序的学习
- C/C++学习之C提高-----文件操作,C程序读写文件、配置文件读写案例
- C语言学习之路之五------------C语言小程序
- C程序之早起
- C程序之初识C语言程序
- C语言程序编辑学习篇—编程者说之C语言
- 【黑马程序员】C语言学习笔记之第一个C程序及编译运行(一)
- 1、黑马程序员-C语言学习笔记之第一个C程序
- 北邮OJ上的题目——1435
- ASP.NET 2.0 绑定高级技巧
- Flex+java开发环境配置
- 层序遍历二叉树
- const与指针搭配使用总结
- c++之学习程序Matrix_1
- Winforms: Windows 7中Taskbar的新效果(3)——进度条
- pku 1087 A Plug for UNIX 网络流 解题报告
- 循环队列例程,vc++2008编译
- itoa()源码
- 初学ibatis,总结遇到的问题(一)
- MFC学习笔记(二)——简单绘图
- 汇编语言复习之--寻址方式1
- OO思想: 关于C++的接口类