Tags:
create new tag
view all tags

Final Project - Shakespeare

Due: May 3, 4:00pm

(No late submissions allowed)

Moodle Link

BIO_Mini-Bios_William-Shakespeare_SF_HD_768x432-16x9.jpg

Instructions

  • Turn in the code (a cpp file), and the run outputs as requested below.
  • Remember to format the code as described and the book and text, and to include comments including complete commetns at the beginning of the program.

Grading

Grading Table

Requirement Grading Comments Points Score
Easy to use user interface   5  
Functional decomposition: Program should be factored into functions to reduce complexity.
"main()" should not be one be function, but should be divided into supporting functions
(Like "readBooks(bookVector, filestream)".
  10  
Class Design: Classes have appropriate methods added as needed, new classes well designed   10  
Class Implementation : Logic is correctly implements in the each class methods   20  
C++ code includes comments, with project information at top, pre and post conditions
for each functions and other comments as needed.
  5  
The C++ code has good formatting, indentation, and organization.   5  
Good variable and function names, appropriate use of constants rather then literal numbers.   5  
Runs: Run of game works correct (Run for given test cases)   40  
Total   100  

Problem

Shakespeare Word Search

Your goal is to use Object Oriented techniques to read the complete works of Shakespeare from a file, and allow for word searches.

A complete version of all works of Shakespeare in a single file is available here: Shakespeare.txt.
If you right-click (ctrl-click on a Mac) on the lihk, you can download it to you computer. You can then copy it into the project folder for your c++ problem, and you will then be able to open it and use it from the project.

Your program must do at least the following:

  1. Read in the entire file of Shakespeare books, and parse it into Books, where Books is object the contains an entire book (definition below). Thus there will be an array of Books, and each Book will include a title plus an array of Lines.
  2. Display a list of the book titles.
  3. Ask the user for a word to search for, and then display a numbered list of the books that contain that word, along with the number of Lines in that book that contain that word. Make searches case insensitive (so searching for "king" matches "king", "King", and "KING", for example. Also remove special character from the search (you may use the code below developed in the Poem program (See program run example below)
  4. If the user enters in a number, show each matching line from that book.
  5. Repeat steps 2, 3 and 4 until the user is done.

What to turn in

For the basic program turn in the following:

  1. All the code, fully documented
  2. The output of runs with the following searches: Kenyon (should fail), college, king, ship, love.
  3. Complete documentaiton for any extra credit work, as described below.

Extra Credit

You will have a opportunity to get extra credit with this assignment. Extra credit will will be points added on to your final course grade. Thus, if you have a final course grade of85%, and you earn 3% extra credit, your overall grade will become 88%.

For the extra credit you must turn in all of the following:

  1. A word or text document clearing describing, in a numbered list, all of the extra credit functions you have added.
  2. A table describing each the extra credit features added, and the expected extra credit for it. For example
    Feature Credit
    1. Highlight the matching words. 1%
    4. Add support more two or more adjacent words, such as "Lady MacBeth " or "to be or not to be". 1%
    Total 2%
  3. At least one run for each feature clearly demonstrating it's operation.

Extra credit Options

Since this is the lass project you will have the opportunity to explore this problem, and add extra credit toward your overall grade. Following are a list of possible options, with a percent of how much it add to your OVERALL grade. You may propose additional improvements for extra credit by emailing me with a proposal, and I will decide if it can be approved, and how much it is worth. The maximum extra credit is 10%.

Some options:

  1. (1%) Highlight the matching words (bold or color).
  2. (1%) Add support for a second author or set of works. The second file must be at least 1Mb, and you will need to format it appropriately.*
  3. (2%) Add support for 5 or more additional books, and start with a menu listing the options, and allowing the user to select the works, then on to the other operations.*
  4. (1%) Add support more two or more adjacent words, such as "Lady MacBeth " or "to be or not to be".
  5. (2%) Add support to search for two or more words, not necessarily adjacent, in the same line. For example, find paragraphs that include the words "King", "Rosencrantz", and "Guildenstern".
  6. (1%) Add support to search for words within some specified numbers of word apart. E.g. search for lines with "King" and "Rosencrantz" with less then 3 words between (either order).
  7. (2%) Add Stemming (see instructor if you wish to try this)
  8. You propose your own!!

* You make get additional books here.

The Book Class definition

class Book {
private:
    string title;
    vector<string> lines;
    string searchWord;
    int searchPos;
    vector<string> getWords(string line);
    string removeSpecials(string str);
    int countMatchesInLine(string line, string word);
    
public:
    Book();
    void setTitle(string aTitle);    // Set the title of this book
    string getTitle();              // Get the title
    int countMatches(string word);  // Return the number of time word appears in a Book
    int size(); // Number of lines in book;
    void addLine(string line);      // add a line to the book;
    void clear();                   // Clear the contents and title of book  
    void startSearch(string word);  // Start a search for getNextMatch
    string getNextMatch();          // retrieve the next line that matches from the findWord
                                    // Return empty string when done
    bool searchDone();              // Return true if search is complete
};
 

Some private helper functions to use within Book

vector<string> Book::getWords(string line) {
    istringstream iss(line);
    vector<string> words;
    string s;
    do {
        iss >> s;
        if (s.length() > 0 && s != " ") {
            words.push_back(s);
            //cout << s << " ";
        }
        s = "";
    } while (iss);
    return words;

}

string Book::removeSpecials(string str) {
    int i = 0, len = str.length();
    while (i < len) {
        char c = str[i];
        if (((c >= '0')&&(c <= '9')) || ((c >= 'A')&&(c <= 'Z')) || ((c >= 'a')&&(c <= 'z')) || c == '\'' || c == ' ') {
            if ((c >= 'A')&&(c <= 'Z')) str[i] += 32; //Assuming dictionary contains small letters only.
            ++i;
        } else {
            str.erase(i, 1);
            --len;
        }
    }
    return str;
}
 

The program should have a vector of Book.

Processing

What you will need to do is complete and use the Book class as defined above. You should define and write helper functions as needed to break your work up into useful modules. For example, you could write a function to read the lines out of the file, and load them into the vector of books. You might also create a function to see if it is a book title, or an end of book line. Below is the process to load the books.

ShakespeareRead.png

Once the books are loaded, you should ask the user for a word to search for, and then call the Book class for each book to see how many matches are in each book, and then display the book names for each book.

Then ask for a word to search for. Then you can call Books countMatches() function to see, and display, the number of words matched in each book. The countMatches function should go through the lines in the book, remove the special characters and change to lower case using removeSpecials(), and then break the line into a vector of words using getWords(), and then count the number of words that match in the line, adding it to the total.

THen the user can select a book to show the lines matching in, and display them. This should be done by startSearch() command to set up the search. then call getNextMatch() to get the next line with a match. Use searchDone() to determine if the end of the book is reached. startSearch() needs only to set searchWord to the word to find, and searchPos to line 0 (the first line in the book). getNextMatch() can then look at each line, starting at searchPos, to check if countMatches() is non-zero. If so return that line. Also always increment searchPos to the next line. If the end of the book is reached, you can set the searchPos to -1 to single the search is done. Then searchDone() can return true is searchPos is -1;

Run Example

Number of books: 38
1. THE SONNETS
2. ALLS WELL THAT ENDS WELL
3. THE TRAGEDY OF ANTONY AND CLEOPATRA
4. AS YOU LIKE IT
5. THE COMEDY OF ERRORS
6. THE TRAGEDY OF CORIOLANUS
7. CYMBELINE
8. THE TRAGEDY OF HAMLET, PRINCE OF DENMARK
9. THE FIRST PART OF KING HENRY THE FOURTH
10. SECOND PART OF KING HENRY IV
11. THE LIFE OF KING HENRY THE FIFTH
12. THE FIRST PART OF HENRY THE SIXTH
13. THE SECOND PART OF KING HENRY THE SIXTH
14. THE THIRD PART OF KING HENRY THE SIXTH
15. KING HENRY THE EIGHTH
16. KING JOHN
17. THE TRAGEDY OF JULIUS CAESAR
18. THE TRAGEDY OF KING LEAR
19. LOVE'S LABOUR'S LOST
20. THE TRAGEDY OF MACBETH
21. MEASURE FOR MEASURE
22. THE MERCHANT OF VENICE
23. THE MERRY WIVES OF WINDSOR
24. A MIDSUMMER NIGHT'S DREAM
25. MUCH ADO ABOUT NOTHING
26. THE TRAGEDY OF OTHELLO, MOOR OF VENICE
27. KING RICHARD THE SECOND
28. KING RICHARD III
29. THE TRAGEDY OF ROMEO AND JULIET
30. THE TAMING OF THE SHREW
31. THE TEMPEST
32. THE LIFE OF TIMON OF ATHENS
33. THE TRAGEDY OF TITUS ANDRONICUS
34. THE HISTORY OF TROILUS AND CRESSIDA
35. TWELFTH NIGHT; OR, WHAT YOU WILL
36. THE TWO GENTLEMEN OF VERONA
37. THE WINTER'S TALE
38. A LOVER'S COMPLAINT
Enter a word to search for (* to end):rascal
1. THE SONNETS Matches: 0
2. ALLS WELL THAT ENDS WELL Matches: 1
3. THE TRAGEDY OF ANTONY AND CLEOPATRA Matches: 0
4. AS YOU LIKE IT Matches: 1
5. THE COMEDY OF ERRORS Matches: 0
6. THE TRAGEDY OF CORIOLANUS Matches: 1
7. CYMBELINE Matches: 3
8. THE TRAGEDY OF HAMLET, PRINCE OF DENMARK Matches: 1
9. THE FIRST PART OF KING HENRY THE FOURTH Matches: 9
10. SECOND PART OF KING HENRY IV Matches: 9
11. THE LIFE OF KING HENRY THE FIFTH Matches: 3
12. THE FIRST PART OF HENRY THE SIXTH Matches: 0
13. THE SECOND PART OF KING HENRY THE SIXTH Matches: 3
14. THE THIRD PART OF KING HENRY THE SIXTH Matches: 0
15. KING HENRY THE EIGHTH Matches: 0
16. KING JOHN Matches: 0
17. THE TRAGEDY OF JULIUS CAESAR Matches: 1
18. THE TRAGEDY OF KING LEAR Matches: 6
19. LOVE'S LABOUR'S LOST Matches: 0
20. THE TRAGEDY OF MACBETH Matches: 0
21. MEASURE FOR MEASURE Matches: 3
22. THE MERCHANT OF VENICE Matches: 0
23. THE MERRY WIVES OF WINDSOR Matches: 2
24. A MIDSUMMER NIGHT'S DREAM Matches: 0
25. MUCH ADO ABOUT NOTHING Matches: 0
26. THE TRAGEDY OF OTHELLO, MOOR OF VENICE Matches: 1
27. KING RICHARD THE SECOND Matches: 0
28. KING RICHARD III Matches: 0
29. THE TRAGEDY OF ROMEO AND JULIET Matches: 0
30. THE TAMING OF THE SHREW Matches: 4
31. THE TEMPEST Matches: 0
32. THE LIFE OF TIMON OF ATHENS Matches: 3
33. THE TRAGEDY OF TITUS ANDRONICUS Matches: 0
34. THE HISTORY OF TROILUS AND CRESSIDA Matches: 2
35. TWELFTH NIGHT; OR, WHAT YOU WILL Matches: 2
36. THE TWO GENTLEMEN OF VERONA Matches: 0
37. THE WINTER'S TALE Matches: 1
38. A LOVER'S COMPLAINT Matches: 0
To display the lines containing rascal enter the number of the book, or 0 to search for another word: 9
  Prince. I comes forward I Peace, ye fat-kidney'd rascal! What a
  Fal. I am accurs'd to rob in that thief's company. The rascal hath
    with the rogue's company. If the rascal have not given me
    action. Zounds, an I were now by this rascal, I could brain him
    rascal is this! an infidel! Ha! you shall see now, in very
  Fal. Well, that rascal hath good metal in him; he will not run.
  Prince. Why, what a rascal art thou then, to praise him so for
  Prince. This oily rascal is known as well as Paul's. Go call him
    whoreson, impudent, emboss'd rascal, if there were anything in

To display the lines containing rascal enter the number of the book, or 0 to search for another word: 30
    I bade the rascal knock upon your gate,
    While she did call me rascal fiddler
    And bring along these rascal knaves with thee?
    What dogs are these? Where is the rascal cook?

To display the lines containing rascal enter the number of the book, or 0 to search for another word: 29

To display the lines containing rascal enter the number of the book, or 0 to search for another word: 0
Enter a word to search for (* to end):brain
1. THE SONNETS Matches: 5
2. ALLS WELL THAT ENDS WELL Matches: 0
3. THE TRAGEDY OF ANTONY AND CLEOPATRA Matches: 5
4. AS YOU LIKE IT Matches: 3
5. THE COMEDY OF ERRORS Matches: 0
6. THE TRAGEDY OF CORIOLANUS Matches: 3
7. CYMBELINE Matches: 9
8. THE TRAGEDY OF HAMLET, PRINCE OF DENMARK Matches: 6
9. THE FIRST PART OF KING HENRY THE FOURTH Matches: 1
10. SECOND PART OF KING HENRY IV Matches: 4
11. THE LIFE OF KING HENRY THE FIFTH Matches: 1
12. THE FIRST PART OF HENRY THE SIXTH Matches: 0
13. THE SECOND PART OF KING HENRY THE SIXTH Matches: 2
14. THE THIRD PART OF KING HENRY THE SIXTH Matches: 0
15. KING HENRY THE EIGHTH Matches: 2
16. KING JOHN Matches: 1
17. THE TRAGEDY OF JULIUS CAESAR Matches: 0
18. THE TRAGEDY OF KING LEAR Matches: 2
19. LOVE'S LABOUR'S LOST Matches: 4
20. THE TRAGEDY OF MACBETH Matches: 4
21. MEASURE FOR MEASURE Matches: 0
22. THE MERCHANT OF VENICE Matches: 1
23. THE MERRY WIVES OF WINDSOR Matches: 2
24. A MIDSUMMER NIGHT'S DREAM Matches: 0
25. MUCH ADO ABOUT NOTHING Matches: 2
26. THE TRAGEDY OF OTHELLO, MOOR OF VENICE Matches: 2
27. KING RICHARD THE SECOND Matches: 1
28. KING RICHARD III Matches: 0
29. THE TRAGEDY OF ROMEO AND JULIET Matches: 3
30. THE TAMING OF THE SHREW Matches: 0
31. THE TEMPEST Matches: 2
32. THE LIFE OF TIMON OF ATHENS Matches: 0
33. THE TRAGEDY OF TITUS ANDRONICUS Matches: 0
34. THE HISTORY OF TROILUS AND CRESSIDA Matches: 9
35. TWELFTH NIGHT; OR, WHAT YOU WILL Matches: 3
36. THE TWO GENTLEMEN OF VERONA Matches: 0
37. THE WINTER'S TALE Matches: 2
38. A LOVER'S COMPLAINT Matches: 0
To display the lines containing brain enter the number of the book, or 0 to search for another word: 19
    That hath a mint of phrases in his brain;
    Other slow arts entirely keep the brain;
    Lives not alone immured in the brain,
    To weed this wormwood from your fruitful brain,

To display the lines containing brain enter the number of the book, or 0 to search for another word: 2

To display the lines containing brain enter the number of the book, or 0 to search for another word: 8
    Without more motive, into every brain
    Within the book and volume of my brain,
    And I do think- or else this brain of mine
    Fie upon't! foh! About, my brain! Hum, I have heard
    Queen. Sleep rock thy brain,
  Queen. This is the very coinage of your brain.

To display the lines containing brain enter the number of the book, or 0 to search for another word: 0
Enter a word to search for (* to end):*

Solution

Topic attachments
I Attachment History Action Size Date Who Comment
JPEGjpg BIO_Mini-Bios_William-Shakespeare_SF_HD_768x432-16x9.jpg r1 manage 71.7 K 2016-10-01 - 21:47 JimSkon  
PNGpng C_-_shakespeare.png r1 manage 18.8 K 2016-11-08 - 05:43 JimSkon  
Texttxt Shakespeare.txt r1 manage 5337.2 K 2016-11-16 - 20:47 JimSkon  
PNGpng ShakespeareRead.png r2 r1 manage 25.3 K 2017-11-29 - 15:31 JimSkon  
Edit | Attach | Watch | Print version | History: r34 < r33 < r32 < r31 < r30 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r34 - 2018-05-01 - JimSkon
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback