Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be provided with a piece of text on Learning Central: called Asmtext.as

ID: 3850681 • Letter: Y

Question

You will be provided with a piece of text on Learning Central: called Asmtext.asm Open this file and copy its contents into the .data area of your program. You are then required to write the rest of the program to perform the following Prompt the user to type in a string of characters and then search the text for the string entered. Return the position of the string and print the message "found" and its position in the text onto the screen either in a Message Box or to the Console. If not found print "not found". in this context, the string searched can be part of a word. Find the longest word and print the word onto the screen. Count the number of words in the paragraph and print the number to the screen. You can assume that there is only one space between each word.

Explanation / Answer

c++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{

   cout << "Enter input file name ";
   string line,filename;
   cin >> filename;
   ifstream myfile (filename.c_str());
vector<string> tokens; // Create vector to hold our words
   if (myfile.is_open())
   {
   while ( getline (myfile,line) )
   {
   string buf; // Have a buffer string
   stringstream ss(line); // Insert the string into a stream
   while (ss >> buf)
   tokens.push_back(buf);
   }
   myfile.close();
   }
   else
   {
   cout << "Unable to open input file" << endl;
   exit(1);
   }      

   while(true)
   {
       string ss;
       cout << "Enter string to find in text ";
       cin >> ss;
       bool flag = false;
       for (int i = 0; i < tokens.size(); ++i)
       {
           string str = tokens[i];
               std::size_t found = str.find(ss);
               if (found!=std::string::npos)
               {
               std::cout << "first "<< ss << " found at: " << "position " << i+1 << endl;
               flag = true;
               break;
               }
       }
           if(flag == false)
           {
               cout << ss <<" Not found ";
           }
       }

   return 0;
}

Sample input.txt:

Following figure shows the value of S vs number of iterations (S is as defined in
quastion). You can see that as, number of iterations increase the value of S
decreases. So the Quality/goodness of clustering increases with number of
iterations

Sample Output:

Enter input file name
input.txt
Enter string to find in text
Follo
first Follo found at: position 1
Enter string to find in text
Quality
first Quality found at: position 34
Enter string to find in text
with
first with found at: position 38
Enter string to find in text
akash
akash Not found
Enter string to find in text

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote