I'm writing a program that creates a linear linked list from information in a txt file. I won't write my actual code nor the actual homework assignment, but I'll create a similar scenario.
We have a file called "movies.txt" and it contains this information:
Ironman:2008
Thor:2011
Avengers:2012
Guardians of the Galaxy:2014
I create two classes: a class (Movie) that will manage the information of ONE movie, and a class (MovieList) that will manage the linear linked list of movies.
I also have a struct called "node" containing Movie data member and a pointer to the next node.
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
|
class Movie
{
private:
char * title; //dynamically allocated
int year;
public:
Movie();
~Movie();
int createMovie(char * aTitle, int aYear)
int readMovie(char * title, int & year);
int copyMovie(Movie&);
}
struct node
{
Movie aMovie;
node * next;
}
class MovieList
{
private:
node * head;
public:
MovieList();
~MovieList();
int insertMove(Movie & addMovie);
}
int Movie::readMovie(char * title, int & year)
{
ifstream f;
f.open("movies.txt");
if(f){
f.get(title, 50, ':');
f.ignore(50, ':'); //ignore delimeter
while(!f.eof()){
f >> year;
f.ignore(50, '\n');
//read again in case more data
f.get(title, 50, ':');
f.ignore(50, ':');
}
}
return 1;
int main()
{
//temporary variables
char title[100];
int year;
return 0;
}
}
|
I've done more coding, but this seems to be the wall. I can successfully read information from a file, but HOW do I then put what I've read into the Movie class's data members? I want to build a linked list of Movie.
OR how do I read directly into a node?
Any suggestions? I've been stuck on this for a few days.