$29
CSE 241 Programming Assignment 6
Description • This is an individual assignment. Please do not collaborate • If you think that this document does not clearly describes the assignment, ask questions before its too late. This assignment is about using C++ STL, exception handling and/or creating Class templates. • Your program reads two files: – data.txt – commands.txt • According to content in data.txt, the program utilizes necessary STL classes and/or user-created classes for a catalog representation. • Your program creates a log file(output.txt) for certain steps of operations performed on catalog. data.txt • This file holds information about a catalog. A catalog can be one of the following: – Book catalog – Music catalog – Movie catalog • The type of the catalog is specified in the first line of data.txt Book Catalog • Each line in a book catalog keeps information about a book. • Format:
This command returns a list of sorted entries (ascending order)
• Example:
sort "title"
This returns the following lines:
1 "Cold Mountain" "Anthony Minghella" "2003" "Adventure, Drama, History" " Jude Law, Nicole
,→ Kidman, Renee Zellweger"
2 "Perfume: The Story of a Murderer" " Tom Tykwer" "2006" "Crime, Drama, Fantasy" "Ben Whishaw,
,→ Dustin Hoffman, Alan Rickman"
3 "The Lord of the Rings: The Fellowship of the Ring" "Peter Jackson" "2001" "Adventure, Drama,
,→ Fantasy" "Elijah Wood, Ian McKellen, Orlando Bloom"
4 "Twelve Monkeys" "Terry Gilliam" "1995" "Mystery, Sci-Fi, Thriller" " Bruce Willis, Madeleine
,→ Stowe, Brad Pitt"
output.txt
This file keeps the log of the operations. The following events should be recorded in the specified format:
• catalog read
• output of commands
catalog read
• First specify the type of the catalog.
• At the end, state the number of unique entries.
Catalog Read: music
4 unique entries
output of commands
• State the command.
• Append its output.
search "Joe" in "artists"
"Professor Satchafunkilus and the Musterion of Rock" "Joe Satriani" "2008" "Guitar Virtuoso"
Exceptions
• Your program should catch certain exceptions and create log entries for them.
• You need to catch the following exceptions:
Missing field exception
• If any of the field in any entries is missing your program should omit that line and create an exception record
in the log file.
Exception: missing field
3
Duplicate entry exception
• If the first field of any entries fully match, your program should create an exception for each repetition and log
these instances in the log file.
Exception: duplicate entry
Wrong command exception
• If the command is not in the expected format(unrecognized field name, extra information etc. . . ), log this
instance as an exception.
Exception: command is wrong
A full example.
• Suppose we are given the following data.txt file and commands.txt file:
• data.txt
1 movie
2 "The Lord of the Rings: The Fellowship of the Ring" "Peter Jackson" "2001" "Adventure, Drama,
,→ Fantasy" "Elijah Wood, Ian McKellen, Orlando Bloom"
3 "Twelve Monkeys" "Terry Gilliam" "1995" "Mystery, Sci-Fi, Thriller" " Bruce Willis, Madeleine
,→ Stowe, Brad Pitt"
4 "Twelve Monkeys" "" "" "Sci-Fi, Thriller" " Bruce Willis, Madeleine Stowe, Brad Pitt"
5 "Perfume: The Story of a Murderer" " Tom Tykwer" "2006" "Crime, Drama, Fantasy" "Ben Whishaw,
,→ Dustin Hoffman, Alan Rickman"
6 "Twelve Monkeys" "" "" "Mystery, Sci-Fi, Thriller" " Bruce Willis, Madeleine Stowe, Brad Pitt"
7 "Cold Mountain" "Anthony Minghella" "2003" "Adventure, Drama, History"
• commands.txt
1 search "Monkeys" in "title"
2 search "Spice" in "genre"
3 sort "year"
• The first line is movie. This means your application will going to run in movie organiser mode.
• Following is the log file for this example:
• output.txt
1 Catalog Read: movie
2 Exception: duplicate entry
3 "Twelve Monkeys" "" "" "Sci-Fi, Thriller" " Bruce Willis, Madeleine Stowe, Brad Pitt"
4 Exception: duplicate entry
5 "Twelve Monkeys" "" "" "Mystery, Sci-Fi, Thriller" " Bruce Willis, Madeleine Stowe, Brad Pitt"
6 Exception: missing field
7 "Cold Mountain" "Anthony Minghella" "2003" "Adventure, Drama, History"
8 3 unique entries
9 search "Monkeys" in "title"
10 "Twelve Monkeys" "Terry Gilliam" "1995" "Mystery, Sci-Fi, Thriller" " Bruce Willis, Madeleine
,→ Stowe, Brad Pitt"
11 Exception: command is wrong
12 search "Spice" in "genre"
13 sort "year"
14 "Twelve Monkeys" "Terry Gilliam" "1995" "Mystery, Sci-Fi, Thriller" " Bruce Willis, Madeleine
,→ Stowe, Brad Pitt"
4
15 "The Lord of the Rings: The Fellowship of the Ring" "Peter Jackson" "2001" "Adventure, Drama,
,→ Fantasy" "Elijah Wood, Ian McKellen, Orlando Bloom"
16 "Perfume: The Story of a Murderer" " Tom Tykwer" "2006" "Crime, Drama, Fantasy" "Ben Whishaw,
,→ Dustin Hoffman, Alan Rickman"
Remarks
• Be careful with the order of exceptions. If an entry has a missing field and it has the same first field with
another entry, you should throw missing field exception.
• Assume no other errors will be present in the files.
• Try to generalize your program. (you can use templates).
• Efficiency is important. (try to use the existing (STL) containers and their methods for sorting etc. . . )
Turn in:
• Source code of a complete C++ program and a suitable makefile. You should use c++11 standard. Your code
will be tested in a linux-gcc environment.
• A script will be used in order to check the correctness of your results. So, be careful not to violate the expected
output format.
• Provide comments unless you are not interested in partial credit. (If I cannot easily understand your design,
you may loose points.)
• You cannot get full credit if your implementation contradicts with the statements in this document.