2d array using txt file

so i have an assignment part as follows:-

Complete the class CAI:
Write the definitions of all the member functions, the
constructors and the de-constructor. In case of path finding the map is a 2D array and therefore you should allocate dynamically a 2D array in the constructor, in case of sorting 1D array is required. Also make sure that you de-allocate the memory properly in the de-constructor. The map or the numbers for sorting should be loaded from a text file. An example is provided both for path finding and sorting.

the .cpp code is as follows:-

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>

#include <fstream>
#include "AILib.h"
using namespace std;

CAI::CAI()
{
	// Add code here

}

CAI::CAI(int jxcols, int iyrows)
{
	// Add code here

}

CAI::~CAI()
{
	// Add code here


}
int CAI::getXCols()
{
	// Add code here

}
int CAI::getYRows()
{
	// Add code here
	
}
int ** CAI::getMap()
{
	// Add code here
	
}
void CAI::setMap(int ** uc_map)
{	
	// Add code here
	
}
	
int CAI::getMapPoint(int jcols, int irows)
{
	// Add code here
	
}

void CAI::setMapPoint(int pointVal, int jcols, int irows)
{
	// Add code here
	
}
	

int CAI::LoadCMap(char *mapName)
{
	// Add code here
	char header [100], *ptr;
	ifstream infile;
	infile.open(mapName);
	int cX=0,rY=0, nn=0;
	int i=0, j=0;
	
	if ( !infile )
	{
		cout << "Cannot open input file\n";
		return 0;//exit(1);
	}
	infile.getline(header,100,' ');
	cX=strtol(header,&ptr,0);
	//cout <<cX<<"\n";

	infile.getline(header,100,'\n');
	rY=strtol(header,&ptr,0);
	//cout <<rY<<"====\n";
	
	////////////////////
	cols=cX;
	rows=rY;
	map= new int*[rY];	
	for(int i=0; i<rY;++i)
		map[i]=new int[cX]; 
	for (int i=0;i<rY;i++)
		for (int j=0;j<cX;j++)
			map[i][j]=0;
	////////////////////

	for (i=0;i<rY;i++)
	{
		for (j=0;j<cX-1;j++)
		{
			infile.getline(header,100,' ');
			nn=strtol(header,&ptr,0);
			map[i][j]=nn;
			//cout <<map[i][j]<<" ";
			//cout <<nn<<" ";
			//cout <<i<<" "<<j<<"\n";
		}
		infile.getline(header,100,'\n');
		nn=strtol(header,&ptr,0);			
		map[i][j+1]=nn;
		//cout <<map[i][j+1]<<"\n";
		//cout <<nn<<"\n";
	}

	infile.close();

	return 1;
}
	
int CAI::WriteCMap(char *mapName)
{
	// Add code here	
	ofstream outfile;
	int cX=0,rY=0, nn=0;
	int i=0, j=0;

	cX=getXCols();
	rY=getYRows();
	outfile.open(mapName, ios::out);
	if (!outfile) {
		cout << "Can't open file: " << mapName << endl;
		return 0;//exit(1);
	}
	
	outfile << cX <<" "<< rY << "\n"<<endl;	
	for (i=0;i<rY;i++)
	{
		for (j=0;j<cX;j++)
		{
			outfile << getMapPoint(j, i)<<" ";
		}
		outfile << "\n";
	}	
	outfile.close();	
	return 1;
}


can anyone give me a heads up or point to wards the right direction cos i have no idea what to do :S im a total noob.

Thanks!
Topic archived. No new replies allowed.