(C++ ONLY!!! and please write this program with vector!!!!!) Write a program tha
ID: 3910125 • Letter: #
Question
(C++ ONLY!!! and please write this program with vector!!!!!)
Write a program that allows the user to type in any one-line question and then answers that question. You should read the question and parse the questions to find keywords. Create a vector to store all answers in your file. Create another vector of record containing keyword and key. Keys will refer to the answers in the first vector. Sort keyword in a vector .There are some example answers:
{
I'm not sure, but I think you can leave your email and I will contact you ASAP.
She is a young lady.
I am a new student.
There are 45 students in this class.
School address is 3948 budfgs ave, hdfk.
} (Those are answers in a file)
These answers are stored in a file (one answer per line), and your program simply reads the next answer from the file and writes it out as the answer to
the question. After your program has read the entire file, it simply closes the file, reopens the file, and starts down the list of answers again.
If you have some smiliar answers, choose one randomly with a message that says "This is one answer." If you dont find the answer in the list, ask user to leave the email address and save the question and email address into a new file.
For example :
Input : How many student in this class?
Output : There are 45 students in this class.
Explanation / Answer
Implemented Source Code:-
-------------------------------------
#include<iostream>
#include<stdlib.h>
#include<fstream>
#include <string>
#include<ctime>
#include<vector>
using namespace std;
class AnswersClass
{
public:
string Answers[25];
int size;
public:
string GetAnswers(ifstream &infile)
{
int i=0,size=0;
string word;
infile.open("Answers.txt");
while(i<5)
{
std::getline(infile,word);
Answers[i]=word;
i++;
size++;
}
srand(time(NULL));
word=Answers[rand()%5];
infile.close();
return word;
}
};
int main()
{
AnswersClass obj;
ifstream infile;
string Question,getanswer;
int option;
while(true)
{
cout<<" -------------------------------"<<endl;
cout<<" 1.Please enter the Question "<<endl;
cout<<" 2.Quit"<<endl;
cout<<" Please select any choice:"<<endl;
cin>>option;
switch(option)
{
case 1:
cout<<" Enter your Question: "<<endl;
//std::getline(cin,Question);
cin>>Question;
getanswer=obj.GetAnswers(infile);
cout<<" Answer is:"<<getanswer<<endl;
break;
case 2:
exit(0);
default:
cout<<" Invalid Option try again"<<endl;
}
}
}
inputfile:-
----------------
I'm not sure, but I think you can leave your email and I will contact you ASAP.
She is a young lady.
I am a new student.
There are 45 students in this class.
School address is 3948 budfgs ave, hdfk.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.