The purpose of this lab is to practice some string operations, to reinforce using functions, and to reinforce control statements from previous chapters.

The media server project is going well, however the volume of files exceeds what a person could reasonably click through one at a time. To practice an automated task your friend asks if it is possible to evaluate and sort thousands of files at a time without user intervention Your friend would like to see a report that demonstrates the number of files to evaluate, and the end result count in each repository Your file of media is here unsorted media.txt

Your program should:

  • Display to the user the total number of media files in an unsorted text source
  • Determine by media file format which source destination to write the media file
  • Display a report of each source text file name and the total number of files in that source
  • The program should take no user intervention, however "Press any key to continue" is allowed
  • 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.

Hint:

  • Each individual function should perform only one function
  • You may call a function from within a function
  • You should use a string value to represent the file name, instead of hard-coding example, string media = "unsorted_media.txt", file_input.open(media);

Task 1: Setup Variables

1. Add "unsorted_media.txt","movies.txt","music.txt","images.txt","error.txt" to the resource files folder

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

3. Declare string variables for each item in Task 1.1.

4. Declare int variables to hold a count value for each line in Task 1.1.

5. Declare a single string variable to hold the current item from the input stream

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

Task 2: Setup Functions

1. Design a function to count each entry in file location.

  • This function should take a single string parameter to represent an item in Task 1.3
  • This function should take a single int parameter to represent an item in Task 1.4.

2. Design a function to determine the "format" of each item in the input file.

  • This function should take a single string parameter to represent the variable in Task 1.5.
  • HINT: you need string operations to find the last ".", and the characters following that last"."
  • make a string variable to hold those final characters, and return that value

3. Design a function to sort the media from the input file to each output file

  • This function should take as parameters each string variable from Task 1.1, and the string variable from Task 1.5.
  • This function will be the only function to open and close your input files and output files
  • Use this if statement, or one of your own design, to determine which text source to send the filename
if (ext == "avi" || ext == "mkv" || ext == "mov" || ext == "mp4" || ext == "wmv")
mov_out << file << endl;
else if (ext == "flac" || ext == "m4a" || ext == "mp3" || ext == "wav" || ext == "wma")
mus_out << file << endl;
else if (ext == "bmp" || ext == "gif" || ext == "jpg" || ext == "png" || ext == "tiff)
img_out << file << endl;
else
err_out << file << endl;

4. Design a function to print out the final report. It should output as the second example below.

  • This function should take as parameters each string variable from Task 1.1, and each int variable from Task 1.2.

5. Declare additional functions as needed to handle items such as exiting the program, clearing the screen, or other tasks that you perform often.

Task 3: 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 secton of code would accomplish

3. Is there a maths operation?

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

4. Is there a control statement?

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

5. Is there a defined function?

  • 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: see image.

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.