Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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(those are few answers, i will add more.):

{

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.

The office is located in dhfkg ave, OK city.

} (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.

This program have to compare each answer, then output the best answer in the file!!!!!!

For example :

Input : How many student in this class?

Output : There are 45 students in this class.

****I hvae a example code for this question, but I did not learn size_t and string::npos before. Could you please write the code with another way without size_t and string::npos. maybe you can create a void funtion to find the best answer not only with string function. And sstream and vector are very good section in this code. i just want to modify the search section !!! please !!!!!

(Please post whole code after modify)

#include #include #include #include #include

using namespace std;

string search(vector keywords, vector answers){ int max = 0; int index = 0; size_t found; //cout << answers.size() << endl; for (int i = 0; i max){ max = count; index = i; } } if (max > 0) return answers[index]; return ""; }

int main(){

vector answers; vector keywords; string line; string word; string email;

ofstream fout("email.txt");

ifstream fin("answers.txt"); if (!fin){ cout << "Error opening file "; return 0; } while (getline(fin,line)){ answers.push_back(line); } fin.close(); while(true){

cout << "Type a question or q to quit:" << endl; getline(cin,line); if (line == "q") break; stringstream ss(line); while (ss >> word){ keywords.push_back(word); } string ans = search(keywords,answers); if (ans == ""){ cout << "Please leave you email:"; getline(cin,email); fout << email; } else { cout << ans << endl; } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Write an expression for half-life and explain it with a diagram.

Answered: 1 week ago

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

Define "Rights Issue".

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago