| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 539 人关注过本帖
标题:[求助]这个程序有问题。建立对象时有问题还是声明类时有问题?
取消只看楼主 加入收藏
xinghe69
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-10-28
收藏
 问题点数:0 回复次数:1 
[求助]这个程序有问题。建立对象时有问题还是声明类时有问题?

// 求助各位大虾。这个程序建立对象时有问题还是声明类时有问题?
//程序目的是求矩阵的和。
// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "iostream.h"

class matrix
{
public:
int x[3][3];
int y[3][3];
public:
matrix(int xx[3][3],int yy[3][3]){x[3][3]=xx[3][3];y[3][3]=yy[3][3];};
~matrix(){};
void set(int xx[3][3],int yy[3][3]);
void sum();

};

void matrix::set(int xx[3][3],int yy[3][3])
{
x[3][3]=xx[3][3];
y[3][3]=yy[3][3];
}

void matrix::sum()
{
int i,j;
int c[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
c[i][j]=x[i][j]+y[i][j];
cout<<c[i][j];
}
}

void main()
{
int i,j;
int m[3][3];
int n[3][3];
cout<<"please enter the first matrix number\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>m[i][j];
}
cout<<"\nplease enter the second matrix number\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>n[i][j];
}


matrix add(m[3][3],n[3][3]);

add.sum();

}

搜索更多相关主题的帖子: 声明 对象 时有 
2006-11-19 10:39
xinghe69
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-10-28
收藏
得分:0 

// test.cpp : Defines the entry point for the console application.
//最后经过同学帮忙
//改成这样就能运行了。 除了上边各位帮忙指出的问题。还有负值的问题。谢谢各位的帮忙

// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "iostream.h"

class matrix
{
private:
int (*x)[3];
int (*y)[3];
public:
matrix(int (*xx)[3],int (*yy)[3])
{
x=xx;
y=yy;
}
~matrix(){};
// void set(int xx[3][3],int yy[3][3]);
void sum();

};
/*
void matrix::set(int xx[3][3],int yy[3][3])
{
x[3][3]=xx[3][3];
y[3][3]=yy[3][3];
}
*/
void matrix::sum()
{
int i,j;
int c[3][3];
int t=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=(*(*(x+i)+j)+*(*(y+i)+j));
}
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<c[i][j]<<endl;
}
}
}

void main()
{
int i,j;
int m[3][3];
int n[3][3];
cout<<"please enter the first matrix number\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>m[i][j];
}
cout<<"\nplease enter the second matrix number\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>n[i][j];
}


matrix add(m,n);
// add.set(m,n);

add.sum();

}


2006-11-19 14:37
快速回复:[求助]这个程序有问题。建立对象时有问题还是声明类时有问题?
数据加载中...
 
   



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

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