Статус: Офлайн
Реєстрація: 21.11.2010
Повідом.: 38
Реєстрація: 21.11.2010
Повідом.: 38
С++ помогите с классами
Нужно зделать обычную прогу с матрицами (сложение двух матриц).
вот мой класс:
class matrix_operations
{
int MO_a[10][10],MO_b[10][10],MO_c[10][10];
int MO_string,MO_rows;
public:
matrix_operations(int my_string, int my_rows,int my_a[10][10],
int my_b[10][10],int my_c[10][10]);
matrix(int matr[10][10],int string,int rows);
matrix_summ(int f_a[10][10],int f_b[10][10],int f_c[10][10]);
matrix_output(int ff_c[10][10]);
~matrix_operations();
};
matrix_operations::matrix_operations(int my_string, int my_rows,
int my_a[10][10],int my_b[10][10],int my_c[10][10])
{
MO_string=my_string;
MO_rows=my_rows;
for(int i=0;i<MO_string;i++)
{
for(int j=0;j<MO_rows;j++)
{
MO_a[j]=my_a[j];
MO_b[j]=my_b[j];
MO_c[j]=my_c[j];
}
}
};
int matrix_operations::matrix_summ(int f_a[10][10],int f_b[10][10],int f_c[10][10])
{
for (int i=0;i<MO_string;i++)
{
for(int j=0;j<MO_rows;j++)
{
cout<<"|c = "<<MO_a[j]<<" + "<<MO_b[j]<<"|";
MO_c[j]=MO_a[j]+MO_b[j];
}
}
return 0;
};
int matrix_operations::matrix_output(int ff_c[10][10])
{int i,j;
for(i=0;i<MO_string;i++)
{
cout<<endl;
for(j=0;j<MO_rows;j++)
{
cout<<ff_c[j];
cout<<" ";
}
}
};
int matrix_operations::matrix(int matr[10][10],int string,int rows)
{
int i,j;
char y;
for(i=0;i<string;i++)
{
for(j=0;j<rows;j++)
{
cout<<"enter a["<<i+1<<"]["<<j+1<<"]: ";
cin>>matr[j];
}
}
cout<<endl<<"hotite uvidet rezultat? (y/n) : ";
cin>>y;
if(y == 'y')
{
for(i=0;i<string;i++)
{
cout<<endl;
for(j=0;j<rows;j++)
{
cout<<matr[j];
cout<<" ";
}
}
}
return 0;
};
matrix_operations::~matrix_operations()
{};
вот файл майна:
#include<iostream.h>
//#include"..\..\MyIncludedFiles\add_matr.h"
#include"matrix_operations.h"
int s,r,a[10][10],b[10][10],c[10][10];
void main()
{
matrix_operations ob(s,r,a,b,c);
matrix_operations ob_summ(s,r,a,b,c);
do
{
cout<<" string and rows != 0!!!"<<endl;
cout<<"string = ";
cin>>s;
cout<<endl<<"rows = ";
cin>>r;
}
while(s==0 || r==0);
cout<<endl<<"creating a matrix a"<<endl;
ob.matrix(a,s,r);
cout<<endl<<"creating a matrix b"<<endl;
ob_summ.matrix_output(c);
ob_summ.matrix_summ(a,b,c);
ob.matrix(b,s,r);
//matrix(a,s,r);
cin;
}
Проблема в том, что все прекрасно работает, кроме "ob_summ.matrix_output(c);" и "ob_summ.matrix_summ(a,b,c);"
их прога как будто не видит (или молча игнорирует). В чем тут проблема?
ЗЫ. если их присоединить к объекту ob - то же самое
Нужно зделать обычную прогу с матрицами (сложение двух матриц).
вот мой класс:
class matrix_operations
{
int MO_a[10][10],MO_b[10][10],MO_c[10][10];
int MO_string,MO_rows;
public:
matrix_operations(int my_string, int my_rows,int my_a[10][10],
int my_b[10][10],int my_c[10][10]);
matrix(int matr[10][10],int string,int rows);
matrix_summ(int f_a[10][10],int f_b[10][10],int f_c[10][10]);
matrix_output(int ff_c[10][10]);
~matrix_operations();
};
matrix_operations::matrix_operations(int my_string, int my_rows,
int my_a[10][10],int my_b[10][10],int my_c[10][10])
{
MO_string=my_string;
MO_rows=my_rows;
for(int i=0;i<MO_string;i++)
{
for(int j=0;j<MO_rows;j++)
{
MO_a[j]=my_a[j];
MO_b[j]=my_b[j];
MO_c[j]=my_c[j];
}
}
};
int matrix_operations::matrix_summ(int f_a[10][10],int f_b[10][10],int f_c[10][10])
{
for (int i=0;i<MO_string;i++)
{
for(int j=0;j<MO_rows;j++)
{
cout<<"|c = "<<MO_a[j]<<" + "<<MO_b[j]<<"|";
MO_c[j]=MO_a[j]+MO_b[j];
}
}
return 0;
};
int matrix_operations::matrix_output(int ff_c[10][10])
{int i,j;
for(i=0;i<MO_string;i++)
{
cout<<endl;
for(j=0;j<MO_rows;j++)
{
cout<<ff_c[j];
cout<<" ";
}
}
};
int matrix_operations::matrix(int matr[10][10],int string,int rows)
{
int i,j;
char y;
for(i=0;i<string;i++)
{
for(j=0;j<rows;j++)
{
cout<<"enter a["<<i+1<<"]["<<j+1<<"]: ";
cin>>matr[j];
}
}
cout<<endl<<"hotite uvidet rezultat? (y/n) : ";
cin>>y;
if(y == 'y')
{
for(i=0;i<string;i++)
{
cout<<endl;
for(j=0;j<rows;j++)
{
cout<<matr[j];
cout<<" ";
}
}
}
return 0;
};
matrix_operations::~matrix_operations()
{};
вот файл майна:
#include<iostream.h>
//#include"..\..\MyIncludedFiles\add_matr.h"
#include"matrix_operations.h"
int s,r,a[10][10],b[10][10],c[10][10];
void main()
{
matrix_operations ob(s,r,a,b,c);
matrix_operations ob_summ(s,r,a,b,c);
do
{
cout<<" string and rows != 0!!!"<<endl;
cout<<"string = ";
cin>>s;
cout<<endl<<"rows = ";
cin>>r;
}
while(s==0 || r==0);
cout<<endl<<"creating a matrix a"<<endl;
ob.matrix(a,s,r);
cout<<endl<<"creating a matrix b"<<endl;
ob_summ.matrix_output(c);
ob_summ.matrix_summ(a,b,c);
ob.matrix(b,s,r);
//matrix(a,s,r);
cin;
}
Проблема в том, что все прекрасно работает, кроме "ob_summ.matrix_output(c);" и "ob_summ.matrix_summ(a,b,c);"
их прога как будто не видит (или молча игнорирует). В чем тут проблема?
ЗЫ. если их присоединить к объекту ob - то же самое

