Assignment 2

  • Worth: 10%

  • DUE: March 21th, 2022 at 11:55pm; submitted on MOODLE.

Warning

For this assignment, you may not work with anyone else.

You need to work independently.

How to submit your work

You need to submit your C++ (.h/.cpp) files directly on moodle. The first two lines of the C++ file should be as follows:

// Student name:
// Student number:

Instructions

  • In this assignment you will calculate the overall sentiment of a text.

  • There are multiple techniques, but we will focus on a very simple one.

  • The analysis will be done by words.

    • The scale is going from -5 (very negative) to 5 (very positive).

  • You will create a first hash table based on the file sentiments.txt

    • This file is adapted from AFINN.

    • This hash table will map each word the corresponding value.

  • After that you need to take the input from a user.

    • Concretly a text.

    • I am giving you a csv file containing book reviews from Amazon that you can you use. Reviews.csv

    • You need to calculate the total sentiment of the text and the average.

    • Then you print the total sentiment of the text and the average.

    • The average sentiment give us an idea if the text is posutive, negative or neutral.

Structure of your program

The program should contain the following files:

  • main.cpp

  • Analysis.h/.cpp : It’s the main class of the program.

  • Sentiment.h/.cpp : The sentiment database that will contain only the words and their sentiment value.

main.cpp

  • This file should take two arguments from the console:

SentimentAnalysis <sentiment_database>

SentimentAnalysis is the name of the executable.

  • Then it should create the class Analsyis.

  • Then it asks the user to enter a text.

  • The program ends when the user type “quit”.

Analysis

  • The principal class of your program.

  • The constructor should take the sentiment file as an argument of the constructor.

  • With the file it should create the class Sentiment.

  • It should have a method taking the text entered by the user and sent by main.cpp.

  • It will calculate the total sentiment of the text. To do that it sum the sentiment of each word in the text.

  • It will also calculate the average sentiment (total sentiment / number of words).

  • Finally, it will print these values.

Sentiment

  • This class must be a Hash Table.

  • The hash must be done on the word.

  • It must contain a find methods that will return the value of the word. And 0 if the word doesn’t exist.

  • You can use the hash function that you want.

  • The way you handle collision also is up to you, but it needs to be explained in the comments.

Some marking details

Warning

Having the correct outputs doesn’t mean that you will obtain a perfect mark.

The marking will depend on:

  • Correctness.

  • Comments

  • Variable names

  • Style

  • etc.

General FAQ:

  • Does my text file have enough details?
    • Probably. The shorter the better.

  • Do I have enough comments?
    • I don’t know, maybe? If you’re looking at code and have to ask if you should comment it… just comment it. That said, don’t write me a book.

  • Can I work with my friend?
    • No.

  • If our code/functions are identical, you won’t really call this cheating, would you?
    • Yes.

  • Moodle was totally broken, it’s not my fault it’s late.
    • Nice try.

  • I accidentally submitted the wrong code. Here is the right code, but it’s late. But you can see that I submitted the wrong code on time! You’ll still accept it, right?
    • No.