0

hellooo.....
i wrote this code.. which is a part of a bigger code...
i have done this using structs..
now i have to do it with class but i dont know much about classes
need help urgently..... :(

#include<iostream>
#include<fstream>
using namespace std;

class cell
{
	bool visited;
	cell *back;
	cell *d[4];
};

int readIn( cell** path)
{
	cell *cells;
	int a;
	int b;
	int c;
	int d;
	ifstream fin;
	fin.open("file.txt");

	int size;

	fin>>size;
	cells= new cell[size];
	for(int i=0; i<size; i++)
	{
		cells[i].visited=false;
		cells[i].back= NULL;
		fin>>a>>b>>c>>d;

		if(a==-1)
			cells[i].d[0]=NULL;
		else
			cells[i].d[0]=&cells[a];

		if(b==-1)
			cells[i].d[1]=NULL;
		else
			cells[i].d[1]=&cells[b];

		if(c==-1)
			cells[i].d[2]=NULL;
		else
			cells[i].d[2]=&cells[c];

		if(d==-1)
			cells[i].d[0]=NULL;
		else
			cells[i].d[3]=&cells[d];
	}
	*path= cells;
	return size;
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Lerner
0

Congratulations! If you've done this using structs, then you've essentially done this using classes as well. The reason is that in C++ the only difference between a struct and a class is the default access rights to members of the class/struct. Structs have public access by default, whereas classes have private access by default. Therefore, reviewing the difference between private and public access by looking in your notes or your reference material otherwise should allow you to complete the conversion from struct to class.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.