Hey all, i am working on a project in which i read thw following data file:

6
CSCI240 CSCI241
CSCI241 CSCI340
CSCI340 CSCI480
CSCI480 CSCI580
CSCI340 CSCI580
CSCI463 CSCI480

This data file, consists of the size of array (6) to be created, and then lists the classes, with the prerequisite in the left column, and the class next in line after... for ex:

to take 241, you need to have taken 240, to take 580, you need to have taken 480 (with the assumption that if the student took 480, he would have taken 340, 241, and 240).

My code currently looks like:

fstream inFile;
        string file;
        //below line goes in the Graph.h file???
	list<string> * reqList;

	cout << "Enter prereq file name: ";
	cin >> file;
    inFile.open(file.c_str());

	if (!inFile)
	{
		cout << "Can't open " << file << ", program terminated." << endl;
	}
	
	int size = 0, arrayCount = 0, sub1 = 0, sub2 = 1;
	string course1, course2;

	inFile >> size;

	reqList = new list<string>[6];

	string courseID[6];

inFile >> course1;
courseID[sub1] = course1;
sub1+=2;
inFile >> course2;
courseID[sub2] = course2;
reqList[sub2].push_back(course1);
sub2++;
	while (inFile)
	{
		int i = sub2;
		inFile >> course1;
		inFile >> course2;
		if (i <= 5)
			reqList[i].push_back(course1);
		i++;
		if (searchArray(courseID, course1, size))
		{
			courseID[sub1] = course1;	
			sub1++;
		}
		if (searchArray(courseID, course2, size))
		{
			courseID[sub1] = course2;
			sub1++;
		}
	}	
inFile.close();
for (int i = 0; i <= 5; i++)
	cout << courseID[i] << endl;

So i read in from file insert the class if it doesnt exist in the first array (this array is just for all the courseID's, with no duplicates ...thats why i created the below function:)

bool Registration::searchArray(string arr[], string item, int size)
{

	int i = 0;
	while (i != 6)
	{
		if (arr[i] == item)
			return false;
		i++;
	}
	return true;
}

As for now... i believe i am correctly inserting the data into the second list, the preReq list, but have absolutely no idea how i can get to print through the list to check if it worked. Eventually i will need to search through it (to see if a student can take, say 340... so it would go to the 340 list, see what the prereq is, then search the students prior courses to see if its in the the list), so printing/searching pretty much the same, except instead of cout, i check for == .

Hopefully this makes sense and someone can take a looky and see how i can get this preReq list to print. My asumption is that i need to use iterators ... but then again, im pretty clueless right now.

Thanks a ton

reqList = new list<string>[6];

I doubt this code.

list<string> reqList(6);

might be the correct way to do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.