Question

In: Computer Science

The user is going to cin a whole bunch of regular text. You store each word...

The user is going to cin a whole bunch of regular text. You store each word based on its first letter. Print out all the words they used by letter. Strip all punctuation and uncapitalize everything. :

- Project set up with stl includes, correct files, and turned in correctly. (Zipped project with no inner debug folder.)

- Basic data structure made. This requires at least two connected containers. More is okay if it makes sense to you, but no way this works with just one. Be sure to comment how it works so I understand it.

- Program planned out in English in inline comments in main. Think of it as you could read this to a programmer and they could do your homework for you. No code details belong in an outline; the person you are reading it to might not use C++. Fell free to mutter to yourself. You need someone else to understand what to do. But do not just comment every line; they know how to write in whatever language they choose. Don't forget - you can use any resource here short of other people and copying code of the internet. But if you can't remember how to use cin to pull words off a sentence, look it up. In the first page of search results I see three different ways to do it. No I'm not saying what they are.

- Parsing sentence down to words works

- Putting in your data structure works

- Removing punctuation and capital letters

Input: I asked my doctor how long I had to live. She said five. I said "Five what?" She said four...

Output: A asked B C D doctor E F five five four G H how had I I I I J K L long live M my N O P Q R S she said said she said T to U V W what X Y Z

Solutions

Expert Solution

The following program can be implemented in C++ as follows:

#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main()
{
    //creating a map of character and storing the string in a vector by the starting letter.
    map<char, vector<string>> m;
    
    
    // filestream variable file 
    fstream file; 
    string word, filename; 
  
    // filename of the file 
    filename = "file.txt"; 
  
    // opening file 
    file.open(filename.c_str()); 
  
    // extracting words from the file 
    while (file >> word) 
    { 
        // displaying content 
        m[toupper(word)].push_back(word); 
    }
    
    //traversing and printing
    map<char, vector<string>>:: iterator it;
    
    for(it = m.begin(); it != m.end(); it++)
    {
        cout<<it->first<<" ";
        for(int i = 0; i < it->second.size(); i++)
            cout<<it->second[i]<<" ";
        cout<<endl;
    }

    return 0;
}

Please upvote the answer if you find it helpful.


Related Solutions

Prompt the user to enter a string of their choosing. Store the text in a string....
Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and,...
Write a regular expressions that would match lines in text that contain word DATE: at the...
Write a regular expressions that would match lines in text that contain word DATE: at the beginning of a line followed by actual date in format YYYY-MM-DD. Space between colon ( : ) and date may or may not exist. In C, if you issue the following statement n << 2 where n is an integer, what will be value of n? In bash, if you define variable var = “date” and issue a statement echo `$var`, what output will...
Write a regular expressions that would match lines in text that contain word DATE: at the...
Write a regular expressions that would match lines in text that contain word DATE: at the beginning of a line followed by actual date in format YYYY-MM-DD. Space between colon ( : ) and date may or may not exist. In C, if you issue the following statement n << 2 where n is an integer, what will be value of n?
JAVA You will then prompt the user to enter each grocery item and store it in...
JAVA You will then prompt the user to enter each grocery item and store it in your array. Afterward, the program will ask the user to enter which grocery item they are looking for in the list, and return a message back on whether it was found or not found. (Hint: You will need two for-loops for this program - one for storing each element into the array and one for searching back through the array.) See below for example...
using python/IDLE (1) Prompt the user to enter a string of their choosing. Store the text...
using python/IDLE (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more...
Write a program that reads a line of text input by the user and places each...
Write a program that reads a line of text input by the user and places each word in a TreeSet. Print the elements of the TreeSet to the screen. This will cause the elements to be printed in ascending order. Using Eclipse for this. TreeSetUse.java.
Perform a sentiment analysis of a big text file in python Extract each word from the...
Perform a sentiment analysis of a big text file in python Extract each word from the file, transform the words to lower case, and remove special characters from the words using code similar to the following line:w=w.replace(':','').replace('?','').replace(',','').replace('.','').replace('"','').replace('!','').replace('(','').replace(')','').replace('\'','').replace('\\','').replace('/','') Utilize the lists of positive words, found in positive.txt to perform a sentiment analysis on the file (count how many positive words there are in a file) positive.txt crisp crisper cure cure-all cushy cute cuteness danke danken daring ... file.txt ...has a new...
You are to create a program to request user input and store the data in an...
You are to create a program to request user input and store the data in an array of structures, and then display the data as requested. The data you are collecting refers to a set of images. The images are OCT images taken of the lining of the bladder. The data you provide will help diagnose the image as cancerous or not, but your code does not need to do that at the moment. First, Define a global structure that...
You are to create a program to request user input and store the data in an...
You are to create a program to request user input and store the data in an array of structures, and then display the data as requested. The data you are collecting refers to a set of images. The images are OCT images taken of the lining of the bladder. The data you provide will help diagnose the image as cancerous or not, but your code does not need to do that at the moment. 1) Define a global structure that...
You are going to the store to get 14 cans of soda. There are 5 varieties...
You are going to the store to get 14 cans of soda. There are 5 varieties to choose from, and you are to bring back at least 1 of each variety. How many different assortments can you choose to come back with?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT