Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that contains two arrays called actors and roles, each of size N

ID: 652751 • Letter: W

Question

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 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.

ADDITION TO Programming Project 20

Add an option to your menu to allow the user to see the list of all the actors/actresses in the file

Requirements

For Programming Project 20, instead of designing the format for the file, use the attached file (movies.txt) wich, as you should be able to see, has the following format:

Each line in the file contains either the name of an actor or the title of a movie.

Lines that contain actors start with the symbol "#", followed by the name of the actor (the "#" is used as a mark to indicate the line correspond to an actor)

A line with the name of an actor will be followed by several lines corresponding to the movies in which the actor appears.

Here is a snapshot of the file:

Help and Tips

The attached program, movies.cpp, shows you how to read the actors and movies from the file. It simply prints out the information to screen. Your job, instead of printing the contents of the file to screen, will be to store the information in the arrays (actors and roles).

Here is how you would declare the arrays as dynamic arrays (so that they work with different number of actors as required above):

string* actors;

multiset* roles;

Here is how you allocate memory for the arrays once you know the number of actors in the file (n):

actors = new string[n];

roles = new multiset[n];

Here is how you would add an actor and a movie to those arrays using a counter pos for the position. pos should be initialized with 0 and increased everytime you read an actor (not a line) from the file:

actors[i] = line.substr(1); //take out the # character from the name

roles[i].insert(line);

Explanation / Answer

// to get number of actors and number of roles in the file

count = 0;

if (line.substr(1,1) == '35')

cout = count + 1;

string* actors;

multiset* roles;

actors = new string[count];

roles = new string[count];

int pos = 0;

actors[i] = line.substr(1);

pos++;

roles[i].insert(line);

P.S: I could not see the program movies.cpp. I tried to answer only based on the last part of the question.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote