Question
In C++ 1. In this assignment, you will be implementing a simple AI that does the following a) accepts three arguments: i) first argument: a
In C++
1. In this assignment, you will be implementing a simple AI that does the following
a) accepts three arguments:
i) first argument: a text file that contains a list of tuples that are
ii) second argument: a text file that contains a N messages .
iii) third argument: a text file where the output will be stored.
b) After reading in the first text file, it will go through each message in the second file, and if the message contains one of the 'keywords' from the first file, it will immediately respond with the appropriate message (depending on whether the corresponding 'keyword' makes the AI happy or not), along with the corresponding 'response' word. If more than one 'keyword' is included in the message, multiple responses will be made.
c) Each response will be stored in the third text file.
2. We have provided a skeleton code that can be downloaded from the instructor's repo. Read it to gain an understanding of what the code does. READING AND UNDERSTANDING this new C++ code will be part of the assignment (but not specifically graded), and will be required to implement the required class definitions and implementations.
3. After understanding how the code works, implement the following:
a. HappyResponse class definition in response.h
b. bool Response::checkAndRespond(const string& inWord, ostream& toWhere) function
c. void Response::respond(ostream& toWhere)
d. AngryResponse method that 'responds' to a given output stream
e. HappyResponse method that 'responds' to a given output stream.
MORE DETAILS ARE PROVIDED IN THE SKELETON CODE COMMENTS. Look at equivalent class definitions and functions for hints. Remember that AngryResponse and HappyResponse inherit the Response class.
4. Test the function on ix-dev on the two given sets of input files to make sure your code is working properly.
input.txt contains the tuples, message.txt contains the messages, and result.txt contains the answer that should be produced by your code.
5. Thing to note:
a) Do not change ANY of the provided skeleton code.
b) Make sure your code compiles and runs on ix-dev with the provided Makefile
c) Look for "TODO" in the files - this is where the required classes and functions need to be implemented.
Code to copy:
/* Implementation of methods for classes Response, AngryResponse, HappyResponse */ #include #include #include
#include "response.h"
using namespace std;
/* Implementation of Word class Don't worry too hard about these implementations. If you'd like to learn more about STL see: https://www.geeksforgeeks.org/the-c-standard-template-library-stl/ */ string Word::upper() { string result(theWord); transform(result.begin(), result.end(), result.begin(), ::toupper); return result; }
string Word::lower() { string result(theWord); transform(result.begin(), result.end(), result.begin(), ::tolower); return result; }
/* Implementation of Response methods */ bool Response::checkAndRespond(const string& inWord, ostream& toWhere) { // TODO: // This method should check if the current object's keyword is in the // input message (inWord), and send the proper response to the toWhere // output stream }
void Response::respond(ostream& toWhere) { // TODO: // This method should 'insert' "I am neither angry nor happy: " followed by // the object's response word to the toWhere output stream, along with // a newline at the end }
// TODO: // Implement the 'respond' member function for the AngryResponse class so that // the angry rseponse "I am angry: " followed by the object's response word // is inserted to the toWhere output stream, along with a newline at the end /* Implementation of AngryReponse methods */
// TODO: // Implement the 'respond' member function for the HappyResponse class so that // the happy rseponse "I am happy: " followed by the object's response word // is inserted to the toWhere output stream, along with a newline at the end /* Implementation of HappyResponse methods */
input.txt
Good day 1 Leaving bye -1 Age Third 0 Weather raining -1 Sports Ducks 1
message.txt
Good day to you, sir What age is this, Gandalf? Good weather for football. My favorite sports are...
result.txt
I am happy: day I am neither angry nor happy: Third I am happy: day I am angry: raining I am happy: Ducks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started