Keep the same filenames and add to the existing code in filework.cpp to complete the project. Leave the existing code unchanged, except for comments as instructed.
Add your name and the date to the file comment block at the top of the filework.cpp file, replacing the words Your Name with your first and last name and Date Here with the current date.
No user input is required for this project and do not add any. All data is read from the files.
Write the required functions, one per problem, as described by the function signature and comment block.
Do NOT change any of the function headers and do NOT make any changes to the main() function besides uncommenting code.
Write the function definitions below main(), and their prototypes above main().
Do not turn in code with cout in any function besides the cout statements already coded in main() and one cout statement for an error message if a file does not open.
You may add cout to debug code but please remove it before turning in your code.
Compile and run the code when finished with each function to verify correctness. Check the test results and make any alterations to your function definitions as necessary. Do NOT change any code in main() beyond removing comments to call the functions and do not change the function headers.
When you first start you will see warnings when compiling. Remember that code with warnings compiles but the warning is giving you hints about problems with the code.
Example Run: The outputs of the program must look exactly like the following for full credit, including the same order and format of the output. There is no user input.
*** Testing findLast42 ***
findLast42a should be 0: 0
findLast42b should be 3: 3
findLast42c should be 5: 5
findLast42d should be -1: -1
*** Testing findFirstCap ***
findFirstCap1 should be 0: 0
findFirstCap2 should be 2: 2
findFirstCap3 should be 4: 4
findFirstCap4 should be -1: -1
*** Testing findName ***
findName1 should be 0: 0
findName2 should be 3: 3
findName3 should be 4: 4
findName4 should be -1: -1
*** Testing deleteAt2 ***
deleteAt2a should be (42,3,2): 42,3,2
deleteAt2b should be (1,3,42,1): 1,3,42,1
deleteAt2c should be (1,3,42,42,42): 1,3,42,42,42
deleteAt2d should be (1,2,1,2): 1,2,1,2
*** Testing add7at2 ***
add7at2a should be (42,7,1,3,2): 42,7,1,3,2
add7at2b should be (1,7,42,3,42,1): 1,7,42,3,42,1
add7at2c should be (1,7,2,3,42,42,42): 1,7,2,3,42,42,42
add7at2d should be (1,7,1,2,1,2): 1,7,1,2,1,2
***End of Tests***
Remember that the commas represent newlines in the files your code outputs. Do not save commas in any file.
When all of the tests pass, upload your completed source code file with the rest of the assignment as described in Deliverables.
You do not need to submit the helper.cpp file as I have it already.
We continue to develop our song playlist application. We load our data from a file and save our vector of Song objects to a file so we keep the data between uses of the application. The data we work with is automatically loaded when the program starts and saved when the program exits.
When developing this program, use your Song class from Assignment 9 and your song playlist code from Assignment 11. We add new code for reading and writing files to store data for our application.
Using your songlist.cpp source code from assignment 11, save the file as songfile.cpp before updating the application to load and save the data of the song playlist in files.
Keep the Song class without adding non-specified variables or removing any of the required functions from the last two assignments. Adding member functions is allowed if appropriate. Make sure to correct any errors or problems identified in the last two assignments including incorrect style. Also, make sure to #include <climits> if you use INT_MAX and #include <cstdlib> if you use exit() to ensure the program compiles on all computers.
Your updated program must still operate like assignment 11. You must meet all the same specifications except for those changes described below.
Name the source code file of this assignment songfile.cpp and include all your code in this single file.
Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.
Add a secondread() member function to your Song class (keeping the original read() function from the last assignment) with the following function prototype exactly:
Loads data about this Song from the file stream parameter.
@param fin A file input stream connected to the files with the
data to load.
void read(ifstream& fin);
The functions reads a set of data from the file input stream parameter and stores the data into the member variables of the Song object in the following order:
title (string with spaces allowed)
artist (string with spaces allowed)
The function must not open or close the file stream. Opening and closing the stream is handled in the function calling read(). Also, this function must be able to read song titles and artists that include multiple words.
Hint: this function is like the read() function from assignment 11, except for the use of a file input stream (like fin) rather than cin. For an example see lesson lesson 12.3.5. Notice that a song's names may have spaces. Thus you must use getline() to read each song's name. Do not forget about using: fin >> ws to clear whitespace from the input buffer.
Add a non-member function (not part of the class) named loadData() to your program, that calls the read(ifstream&) function from the prior step, to input song data from a file and return the loaded data in a vector of Song objects. Use the following prototype exactly for this function:
Loads all song data from the specified fileName and
returns the data in a vector of Song objects.
@param list The list of songs read from the file.
@param fileName The name of the file read from.
void loadData(vector<Song>& list, string fileName);
Hint: for an example of reading file data into a vector of objects, see lesson lesson 12.3.5.
Remove your hard-coded songs and load from the data file instead. Call the loadData() function at the start of main() with an argument of "songs.txt" when the program starts so that it loads the file automatically before any menu code and without any user input.
Prepare and submit a songs.txt file that follows the format of this file: songs.txt. The data for each song is contained in groups of four lines each in the order:
song title (can be multiple words)
song artist (can be multiple words)
rating (decimal numbers)
length (integer numbers)
Make sure to save songs.txt in the UNIX file format with a blank line at the end of the file.
Hint: to save in the UNIX file format, see lesson 11.2.4. The easiest way is to download the example songs.txt file by right-clicking and saving the link directly without any copy-paste. If you update your file on Windows, be sure to save in a UNIX file format.
Add a write() member function to your Song class with the following function prototype exactly:
Writes information about this Song to the file stream.
@param fout A file output stream connected to the file in
which to save the data.
void write(ofstream& fout) const;
The function writes the member variables to a file output stream in the following order, each on a new line:
rating (one decimal place)
length (in seconds)
Add a non-member function named saveData() to your program that calls the write(ofstream&) from the prior step to save a vector of Song data into a file. Use the following prototype exactly for this function:
Writes song data to an output file.
@param list The vector of Song objects.
@param fileName The name of the file written.
void saveData(const vector<Song>& list, string fileName);
Hint: This function is like listing to the console but calls write(ofstream&) instead of print(). See lessons 10.4.1 and 10.4.2 for examples of printing and listing data with vectors.
Call the saveData() function when the program exits so that all the current catalog data is saved to a file named list.txt automatically without any user input.
The output of the saveData() function must save the data in the same format as the input file. Do NOT append the data and do NOT format the numbers differently. Notice the output file name is different than the input file name. The purpose of the different names is to help during program development and grading.
Submit this project with the rest of the assignment as described in Deliverables.
Complete the assignment using pair programming. (1 point)
Write a non-member function using the following prototype: (2)
Writes a report to an output file (extra credit).
@param list The vector of Song objects.
@param fileName The name of the file to which to write.
void writeReport(vector<Song> list, string fileName);
Add a new menu item 99 to main and call the writeReport() function from main() to produce another text file named report.txt formatted like the following:
Song playlist report:
# Title Artist/Band Rating Length
1 Happier Marshmello 4.4 3:34
2 Without Me Halsey 3.8 3:21
3 Head Above Water Avril Lavigne 5.0 3:40
Playlist length: 10:35
Average rating: 4.4
Calculate both the playlist length and average rating for the report.
Make certain that your README.txt file describes any extra credit attempted.
In preparation for next weeks lessons, complete the following:
Read the assigned reading in the textbook
Complete the Tutorial Exercises in CodeLab 12 before the specified due date.
Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available. You can look at solutions if you miss your first few attempts and are stuck by clicking the "Solution" tab.
The instructor will evaluate your assignment using the following criteria. Thus you should check your assignment against these criteria to maximize your score.
Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive. Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.
Your assignment must work as submitted, so submit all the files needed to complete your assignment. Remember to test and double check your files before submitting them. If you make a mistake, you can resubmit up to the deadline. If you resubmit, you must include all your assignment files in the last submission as Canvas hides prior submissions.