Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i have written my own code to make the following output happen that i have attached below please kkndly help me to figure out what
i have written my own code to make the following output happen that i have attached below please kkndly help me to figure out what is missing from my code that is not letting me get the following output
- Microsoft Visual Studio Debug Console Modern: 1 and: 13 forwarding-thinking: 1 Ontario: 1 Tech: 1 University: 1 advances: 1 the: 5 discovery: 1 application: 1 of: 4 knowledge: 1 to: 5 accelerate: 1 economic: 1 growth: 1 regional: 1 development: 1 social: 2 Innovation: 1 we: 3 inspire: 1 equip: 1 our: 2 students: 2 graduates: 1 make: 1 a: 5 positive: 1 impact: 1 #include
#include
#include
#include
using namespace std;
bool isFound(vectorstring> v, string word)
{
/*this function is resposible for taking a vector of strings and just a word string
this function also returns true or false depending on if the word passed to the
function is already in the vector v ,maybe something like if word is in v retunr true
if word is not in v return false */
bool flag = false;
for (int i = 0; i v.size(); i++)
{
if (v[i] == word) //checks to see if word in index is duplicated
{
flag = true; //if //the word is duplicated we retunr a true
}
else
{
flag = false; //if the word is not duplicated we retunr a false
}
/*In line im trying to demonstrate that if the word is duplicate i want to increase count
*/
//how can i increase the count here
}
return flag;
}
void printReport(vectorstring> words, vectorint> counts)
{
//this function will be used to print out statements
for(int i=0;iwords.size();i++)
{
coutwords[i]":"counts[i]endl;
}
}
int main()
{
//First open the file and read through it word by word use a while loop to go through that
//if duplicate words identified increment count by one
string words;
ifstream file("data.txt");
vectorstring> v;
vectorint> counts;
while (file >> words)
{
if (isFound(v, words)) //as it reads the file word by word it comes here and checks to see if word has been inserted in the vector already and if yes this line gets eecuted
{
for (int i = 0; i v.size(); i++)//after the if found is executed it comes here and checks to see if the words are duplicate and if its true it increase the counter
{
if (v[i] == words)
{
counts[i]=counts[i]++;//if words is a duplicate then we add one to the count
}
}
}
else
{
v.push_back(words); //it goe to line 48 and checks to see if word has been pushed in vector if it fails it comes to line 52
counts.push_back(1); //along with inserting the number this keeps count of the word
}
}
file.close();
printReport(v,counts);//sending the counts and vector to print report function for display
return 0;
}
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