Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- From: usman911@xxxxxxxxx
- Date: 23 Feb 2006 23:46:36 -0800
//goal: to make a 2 dimentional dynamic array and use it in matrix
multiplication plz help me, //i am using VC++
#include<iostream.h>
class Matrix
{
private:
int *e;
int m,n,sz;
static char count;
char name;
public:
Matrix(int mx = 0,int nx = 0):m(mx),n(nx)
{
sz = m*n;
e = new int[sz];
for(int i = 0;i<sz;i++) //initiaklize d array elements to 0
e[i] = 0;
count++;
name = count; //to have a naming convention of objects, etc A,B,C
}
void insert (int i,int j,int v) //to insert an element in the 2D array
{
if(i<=m && j<=n) //check is refference is ok then insert the item.
e[i * n + j] = v; //convert 2D indexes to one dimention.
else
cout<<"order violation, the matrix has order:"<<m<<'x'<<n<<endl;
}
//returns value of a particular pos /**********I get error in this
function i think*****/
int & pull (int i,int j) //retuns the number after converting 2D
indexes to one D index
{
if(i<=m && j<=n)
{
return e[i * n + j]; //conversion of 2D indexes to 1D, n is the 2nd
Dimention
}
else
{
cout<<"order violation, the matrix has order:"<<m<<'x'<<n<<endl;
return e[0];
}
}
//will store its order into two varables passes as refference by the
calling func
void order(int &M,int&N)
{
M = m;
N = n;
}
Matrix operator * (Matrix B) // matrix multiplication, works fine but
error comes in this
//block when pull is
called
{
if(n == B.m)
{
Matrix C(m,B.n);
for(int i=0;i<m;i++)
for(int j=0;j<B.n;j++)
for(int k=0;k<n;k++)
C.insert(i,j,C.pull(i,j) + this->pull(i,k) * B.pull(k,j));
return C;
}
else
{
Matrix null(m,B.n);
cout<<"order mismatch"<<endl;
return null;
}
}
void setMatrix()
{
int temp;
for(int i = 0;i<m;i++)
for(int j= 0;j<n;j++)
{
cout<<"Enter values of Matrix "<<name<<' '<<m<<'x'<<n<<" matrix at:
"<<i+1<<','<<j+1<<" :";
cin>>temp;
this->insert(i,j,temp);
}
}
void show()
{
for(int i = 0;i<m;i++)
{
for(int j = 0;j<n;j++)
cout<<this->pull(i,j)<<'\t';
cout<<endl;
}
}
~Matrix()
{
delete []e;
count--;
}
};
char Matrix::count = 64;
/********************************************************************************/
int main (void)
{
Matrix A(2,3),B(3,2),C(2,2);
A.setMatrix();
B.setMatrix();
C = A*B;
C.show();
A.show();
cout<<endl;
B.show();
cout<<endl;
C.show();
return 0;
}
///PLEASE any help will be greatly apriciated, i get error of
//Assertation falure at line 47 of dbgdl.cpp
//Expression:_block_type_is_valid(phead->nBlockType)
.
- Follow-Ups:
- Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- From: Heinz Ozwirk
- Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- From: David Wilkinson
- Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- From: Heinz Ozwirk
- Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- Prev by Date: Slight Newbie Has A Question About The "Stdafx.h" And The "Stdafx.cpp" Files
- Next by Date: boost (Can it generate hash keys)
- Previous by thread: Slight Newbie Has A Question About The "Stdafx.h" And The "Stdafx.cpp" Files
- Next by thread: Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- Index(es):
Relevant Pages
|