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?
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?
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
Respond in a single Word doc (or comparable text editor). Henrietta’s Pine Bakery Background You are...
Respond in a single Word doc (or comparable text editor). Henrietta’s Pine Bakery Background You are an Analyst for the professional service firm, FINACC LLP. Your firm specializes in providing a wide variety of internal business solutions for different clients. Given the outstanding feedback you received on your first engagement working for Big Spenders Inc., a Senior Manager in the Financial Advisory group requested your support on a compilation engagement. Additional Information Henrietta’s was established in 1963 when it first...
Computer Science - Java Programming How do you read a text file and store three different...
Computer Science - Java Programming How do you read a text file and store three different pieces of information in the database when the given text file contains this info.: 12345 Computer Science Bob Stone 23456 Art James G. Ocean? These are written in the format as ID Class Name. I was going to take the three different pieces of information by separating them by spaces, but the number of spaces is random and I don't know how to adjust...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT