The purpose of this lab is to gain practice using control statements.

Your friend is interested in being able to sort a media collection. There will be a file containing media, and the request is to accept or delete each entry in the media file. File is attached here: movie_list.txt

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:

  • Examine the input text file. You will be repeating the steps below for each record.

Task 1: Setup Variables

1. Add your input text file to the resource files folder

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

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

4. Declare the output file variable you will use in place of cout for keep file output.

5. Declare the output file variable you will use in place of cout for delete file output.

6. Declare a variable to contain movie titles, of type string

7. Declare a variable to contain a user keystroke choice, of type char.

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

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

2. Use the variable from Task 1.3 to assign value to Task 1.6.

3. Use a control statement to determine if the variable from Task 1.6 has value.

4. If Task 2.2 returns TRUE, prompt to either keep or discard the media identified by the string variable. The user decision will be stored in the variable from Task 1.7.

5. Use a control statement ( cannot be the same kind of control statement from Task 2.2 ) to read the variable from Task 1.7.
If it is the case that the user enters 'Y' for yes, write variable from Task 1.6 to the variable from Task 1.4.
If it is the case that the user enters 'N' for no, write the variable from Task 1.6 to the variable from Task 1.5.
If it is the case that the user enters any other variable, notify the user the input is invalid, then write the variable from Task 1.6 to the variable from Task 1.4.

6. Store an empty string to the variable from Task 1.6

7. Repeat Task 2.1 - 2.5 for each entry in movie_list.txt

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

1. Close the connection from the variable in Task 2.3.

2. Close the connection from the variable in Task 2.4.

3. Close the connection from the variable Task 2.5.

Task 4: Comment Your Program

1. Determine appropriate locations to comment your code.

2. Is there a confusing section of code?

  • Consider if there is a less confusing way to structure your code
  • If not, briefly explain the what the section of code would accomplish

3. Is there a math operation?

  • If so, briefly explain the purpose of the math operation

4. Is there a control statement?

  • If so, briefly explain your control statement with a comment.

5. Is there a defined function?

  • There should not be, that is not current material.
  • When the time comes, you should explain your defined function with a comment.

6. You should not include "teaching comments" to explain:

  • Basic functionality
  • Existing commands
  • Declaring variables
  • Outputting to the screen
  • Preprocessor directives

Sample Output:

Program run: see image.

Movies to Keep:
Army_of_Darkness_(1992).avi
Donnie_Darko.mp4
Life_of_Brian_(1979).avi
Lock,_Stock_and_Two_Smoking_Barrels_(1998).avi
National_Lampoon's_Christmas_Vacation_2_Cousin_Eddie's_Island_Adventure_(2003).mkv
Spaceballs_(1987).mkv

Movies to Discard:
Batman_&_Robin_(1997).m4v
Dr._Strangelove_or_How_I_Learned_to_Stop_Worrying_and_Love_the_Bomb_(1964).m4v
Repo!_The_Genetic_Opera_(2008).mkv
To_Wong_Foo_Thanks_for_Everything,_Julie_Newmar.mp4
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.