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

Using C++ I am stuck getting the list to read one line at a time instead of as a

ID: 3913690 • Letter: U

Question

Using C++

I am stuck getting the list to read one line at a time instead of as a paragraph. Screenshots of what the finished product should look like are under the problem.

Thanks in advance.

Your friend is organizing a Halloween party, and would like to display some horror movies as background entertainment. This friend would like to poll some guests to find the three best movies to play during the party, and has provided a file with 30 movies to choose from. You are tasked with writing a program that will display the movies to choose from, and then give the user a chance to vote for the top three movies. In the interest of time, your friend will hand count the results to choose the films. Your file of films to choose from is here:

horror_movies.txt  

Your program should:

Prompt the user to review a list of 30 movies

Prompt the user to press any key to continue

Prompt the user to individually select or reject movies using 'y' or 'n'

Write each selection to an output file

Stop the selection process after the third movie is selected

Output the selections to the screen for the user to review

The program should utilize a minimum of four defined functions

Constraints:

Do not use any concepts beyond the current chapter, unless explicitly stated in the tasks below

Re-use a single string variable for each entry

Hint:

Each individual function should perform only one function.

You may call a function from within a function.

You may use a string value to represent the file name, instead of hard-coding. example,
string filename = "filename.txt"
file_input.open(filename);

Task 1: Setup Variables

Add horror_movies.txt to the resource files folder

Use preprocessor directives to include input/output, file input/output, and string variables.

Declare the input file variable you will use in place of cin for horror_movies.txt.

Declare the output file variable you will use inplace of cout for writing to party_selections.txt.

Declare a variable to contain a single movie title, of type string.

Declare a variable to contain the horror_movies.txt file, of type string.

Declare a variable to contain the party_selections.txt file, of type string.

Declare a variable to contain a count, of type int.

Declare a variable to contain a previous value of count, of type int.

Separate Task 1 from Task 2 by pressing ENTER on your keyboard. This provides a single line of whitespace in your code

Task 2: Input / Output Data

Use the variable from Task 1.3 to open the text file in Task 1.1.

Use the variables from Task 1.4 to open the text file indicated in Task 1.4.

Prompt the user to review the movie list, and then explain that the user is to choose three movies ( see sample run below ).

Display the original list of movies to the user, use a function that take a single string argument with the variable from Task 1.6.

Use a repetition control statement to handle user selection of individual films. This control statement should also count the number of selections.

This control statement should end when the count reaches 3.

Use a function that will take the current count, and a single movie title as an argument.

This function should prompt the user to " Press y to select " << mv << " or n to reject: " ( see second image for sample run below ).

The control statement should write to the output file from Task 1.4 each time the old count doesn't match the current count. Use a boolen returning function that takes old count and current count as arguments to handle this.

Separate Task 2 from Task 3 by pressing ENTER on your keyboard. This provides a single line of whitespace in your code

Task 3: Cleanup

Close the connection from the variable in Task 2.1.

Close the connection from the variables in Task 2.2.

Reset the screen with a "press any key to continue..." and "clear screen" command. Use a void function to handle this functionality.

Use the function from Task 2.4, but use the variable from Task 1.7. This will display the final selections.

Movie_list

Explanation / Answer

Answer:

#include<fstream>

#include<iostream>

#include<string>

using namespace std;

char prnt_mov(string mv , int n)

{

cout<<" Enter Y letter to select " << mv << " to reject Enter N: ";

char ch;

cin>>ch;

return ch;

}

bool lmts_chck(int count_value,int prev_v)

{

return (count_value-prev_v)==1 && (count_value==3 && prev_v==2);

}

void clr_scrn()

{

cout<<"press any key to continue...";

cin.get();

cout << string(50, ' ');

}

void showMovies(string s)

{

size_t last = 0;

size_t next = 0;

while ((next = s.find("?", last)) != string::npos)

{

cout<<s.substr(last,next-last)+" ";

last=next+1;

}

}

int main()

{

/*Task 1 start */

string movie_title;

string selected_movies;

string input_file="horror_movies.txt";

string output_file="party_selections.txt";

int count=0;

int prev_value=0;

/*Task 1 end */

/*Task 2 start */

ifstream horror_movies;

horror_movies.open(input_file);

ofstream party_selections;

party_selections.open(output_file);

string temp;

while( horror_movies>>temp )

{

movie_title+=temp+"?";

}

showMvs(movie_title);

cout<<"Review the movie list and choose three movies. ";

size_t last=0;

size_t next=0;

while ((next = movie_title.find("?", last)) != string::npos)

{

if(lmts_chck(count,prev_value))

{

break;

}

else

{

if(prnt_mov(movie_title.substr(last,next-last),count)=='y')

{

selected_movies=selected_movies+movie_title.substr(last,next-last)+"?";

party_selections<<movie_title.substr(last,next-last)<<" ";

last=next+1;

prev_value=count;

count+=1;

}

else

{

last=next+1;

}

}

}

/* Task 2 end */

/*Task 3 start */

horror_movies.close();

party_selections.close();

clr_scrn();

showMvs(selected_movies);

/* Task 3 end */

return 0;

}

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