0

I have had the displeasure of being saddled with a textbook that isn't written very well. As it stands, I went from enjoying C++ to being physically ill just thinking about it. However, I refuse to quit the class. So the long and short of it is I have a lab that asks the following:

Write a program that contains two arrays called actors and roles, each of size N. For each i, actors[i] is the name of an actor and roles[i] is a multiset of strings that contains the names of the movies that the actor has appeared in. The program reads the initial information for the these arrays from files in a format that you design. Once the program is running, the user can type in the name of an actor and receive a list of all the movies for that actor. Or the user may type the name of a movie and receive a list of all the actors in that movie.

Now, I don't want the answer. I just need to know what direction to start heading to. I feel pretty comfortable with standard arrays, but the way multisets are described in this textbook confuses me to no end. Any assistance (without just giving me the answer) would be appreciated.

kiddsupreme
  • 115
  • 1
  • 3
  • 13
  • In database theory this would me called a many to many mapping, if that helps. – Arif Burhan Mar 20 '16 at 03:08
  • find method will find a specific member, count method will count elements with a specific key. – Arif Burhan Mar 20 '16 at 03:15
  • A multiset (in the C++ standard library, at least, but I think in normal usage) is a set which can have repeated elements. C++ (multi)sets are not real mathematical sets, because they are ordered; since C++11, the standard library has also included unordered_sets and unordered_multisets. The very idea of a multiset might seem odd, but it's useful to remember that C++ (multi)sets can use an arbitrary function to compare objects which defines an equivalence relation. I still don't see why `roles[i]` would be a multiset rather than a set (can an actor appears twice in the same movie?) – rici Mar 20 '16 at 04:42

1 Answers1

0

The way its done is to have a third auxiliary multiset linking actors to films.

This third set only needs to contain pairs of unique integers. Say user picks actor 'wayne' first step is to form auxiliary subset of pairs of integers(actor_id,movie_id),each actor has an unique integer id, each movie has an unique integer id , then iterate through this set to obtain all movies as values to these keys.

Going the other way: if user picks film 'rawhide' again form subset of integers and iterate through this to find all actors as values to these keys.

Look up 'many to many relation' for further info.

Arif Burhan
  • 507
  • 4
  • 12
  • This may help, replacing tables with sets: **http://docs.oracle.com/cd/E23507_01/Platform.20073/RepositoryGuide/html/s0608manytomanyrelationships01.html** – Arif Burhan Mar 20 '16 at 03:29