#include #include #include #include #include using namespace std; class Actor { public: string name; map movies; map years; }; class Movie { public: string name; int year; map actors; }; class Year { public: int year; map movies; map actors; }; main(int argc, char **argv) { ifstream fin; int i, j; string s; int year; Movie *m; map movies; map ::iterator mit; for (i = 1; i < argc; i++) { /* Open the movie file */ fin.open(argv[i]); if (fin.fail()) { cerr << "Problem opening " << argv[i] << endl; exit(1); } /* Construct the movie's name from the file name */ s = argv[i]; j = s.find(".txt"); if (j == string::npos) { cerr << "File does not have a .txt extension: " << s << endl; exit(1); } s.resize(j); for (j = 0; j < s.length(); j++) { if (s[j] == '-') s[j] = ' '; } /* Create the movie instance, read the year and insert the movie */ m = new Movie; m->name = s; fin >> year; if (fin.fail()) { cerr << "The first line of " << s << " should be the year\n"; exit(1); } getline(fin, s); m->year = year; movies.insert(make_pair(m->name, m)); /* Read the actors */ while (!fin.fail()) { getline(fin, s); if (!fin.fail()) { j = s.find(" - "); if (j == string::npos) { cerr << "Actor specifications should be actor name '-' role name\n"; cerr << "S: " << s << endl; exit(1); } while (s[j] == ' ') j--; s.resize(j+1); } } fin.close(); fin.clear(); } /* Print out the movies */ for (mit = movies.begin(); mit != movies.end(); mit++) { m = mit->second; cout << "Movie: " << m->name << ". Year: "<< m->year << ".\n"; } }