BLOCK_TYPE_IS_VALID

Please help me
I'm a new programmer, so I am not strong in C++
This is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Chuong2_bai14.cpp : Defines the entry point for the console application.
/*
	Write a program : Input: an interger n, output: n rows of PasCal Triangel
	Example:
	1
	1 1
	1 2 1
	1 3 3 1
	1 4 6 4 1
*/

#include "stdafx.h"
#include "conio.h"
#include "iostream"

using namespace std;

class Pascal_Triangel
{
private:
	int** mang;
	int n;
public:
	~Pascal_Triangel()
	{
		delete[] mang;
		delete mang;
	}
	Pascal_Triangel(int n)
	{
		mang = new int* [n];
		for(int i=0;i<n;i++)
		{
			mang[i] = new int [n];
		}
		//Khoi tao tam giac
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
			{
				if(j>i)
					mang[i][j]=0;
				else if(j==0 || i==j)
						mang[i][j]=1;
					else
						mang[i][j]=mang[i-1][j-1]+mang[i-1][j];
			}
	}
	Pascal_Triangel()
	{
		cout<<"Nhap kich thuoc cua mang:";
		cin>>n;
		mang = new int* [n];
		for(int i=0;i<n;i++)
		{
			mang[i] = new int [n];
		}
		//Khoi tao tam giac
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
			{
				if(j>i)
					mang[i][j]=0;
				else if(i==0 || i==j)
						mang[i][j]=1;
					else
						mang[i][j]=mang[i-1][j-1]+mang[i-1][j];
			}
	}
	void Show()
	{
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
			{
				if(mang[i][j]==0)
                                        {
                                              if(j==n-1)
					      cout<<"\n";
					      continue;
                                        }
				else
					cout<<mang[i][j]<<"  ";
			}
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	int n;
	cout<<"Nhap so dong cua tam giac Pascal can hien thi:";cin>>n;
	Pascal_Triangel P(n);
	P.Show();
	return 0;
}


And this is a bug:
Debug Assesion failed!
Program: ...al Studio 2010/Projects/Chuong2_bai14/Debug/Chuong2_bai14.exe
File: f:\dd\vstools\crt_bld\self_x86\crt\src\dbgdel.cpp
Line:52
Expression:_BLOCK_TYPE_IS_VALID (pHead->nBlockUse)
Thanks for help
Last edited on
Change your deconstructor...
1
2
3
for (int i = 0; i < n; ++i)
   delete [] mang[i];
delete[] mang;
tks so much ^^
Topic archived. No new replies allowed.