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

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?
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...
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 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?
Assignment in C programming class: read the text file line by line, and place each word,...
Assignment in C programming class: read the text file line by line, and place each word, in order, in an array of char strings. As you copy each word into the array, you will keep a running count of the number of words in the text file and convert the letters of each word to lower case. Assume tgat you will use no more than 1000 words in the text, and no more than the first 10 characters in a...
End user programs are designed for specific functions such as word processing or a game. You...
End user programs are designed for specific functions such as word processing or a game. You have installed a new piece of applications software onto a stand-alone PC. You then find that the printer attached to the PC fails to produce what can be seen on screen in that package. Explain clearly why this might happen.
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output...
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output please. A blank line (may contain spaces) Postal abbreviation (2 letters) for State followed by a space and then the 5-digit zip code A KU student username (Ex. lpork247) A “valid” email address (also explain how you defined “valid”) A SSN pattern (ddd-dd-dddd)
Although your product, a word game, has a list price of $12.95, each store is free...
Although your product, a word game, has a list price of $12.95, each store is free to set the price as it wishes. You have just completed a quick survey, and the marked prices at a random sample of stores that sell the product were as follows: $12.95, 9.95, 8.95, 12.95, 12.95, 9.95, 9.95, 9.98,13.00,9.95 a) Estimate the mean selling price you would have found had you been able to survey all stores selling your product. b) for a typical...
java question: How would you be able to store a matrix from a text file into...
java question: How would you be able to store a matrix from a text file into a linked or doubly linked list, if you cannot use 2D arrays? input example: 1 2 3 4 1 3 2 4 4 2 3 1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT