1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
xxTIMURxx [149]
3 years ago
14

Write a program that takes paragraph from the user and prints all unique words in that paragraph in c++

Computers and Technology
1 answer:
Greeley [361]3 years ago
4 0

Answer:

We strongly recommend you to minimize your browser and try this yourself first

The idea is to use map in STL to keep track of words already occurred.

// C++ program to print unique words in a string

#include <bits/stdc++.h>

using namespace std;

  

// Prints unique words in a file

void printUniquedWords(char filename[])

{

    // Open a file stream

    fstream fs(filename);

  

    // Create a map to store count of all words

    map<string, int> mp;

  

    // Keep reading words while there are words to read

    string word;

    while (fs >> word)

    {

        // If this is first occurrence of word

        if (!mp.count(word))

            mp.insert(make_pair(word, 1));

        else

            mp[word]++;

    }

  

    fs.close();

  

    // Traverse map and print all words whose count

    //is 1

    for (map<string, int> :: iterator p = mp.begin();

         p != mp.end(); p++)

    {

        if (p->second == 1)

            cout << p->first << endl;

    }

}

  

// Driver program

int main()

{

    // Create a file for testing and write something in it

    char filename[] = "test.txt";

    ofstream fs(filename, ios::trunc);

    fs << "geeks for geeks quiz code geeks practice for qa";

    fs.close();

  

    printUniquedWords(filename);

    return 0;

}

Output:

code practice qa quiz

Thanks to Utkarsh for suggesting above code.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.

Explanation:

please mark me as brainliest thank you merry Christmas

You might be interested in
An asymmetric encryption system utilizes how many keys?
ivanzaharov [21]
Two. One for encryption, and one for decryption. RSA is an example of an asymmetric encryption algorithm.
7 0
3 years ago
A must decode this code. I guess is not a Cesar. The last line is a email adress.
Pie
It is a text in Polish language.
Powiedz nam w czym jesteś dobry

Magento
Drupal
DjangoSymfony
Python
PHP
Zaznaczone?
Teraz wyślij formularz z konsoli przeglądarki:

require('jquery')[WON'T TRANSLATE THIS LINE BECAUSE IT IS IMMORAL-> YES, I AM A PROGRAMMER :)) ]



3 0
3 years ago
I need help with cisco please
Dmitry [639]

A cisco develops, manufactures and sells networking hardware, software, telecommunications equipment and other high-technology services and products. ... They pioneered the concept of a local area network (LAN) being used to connect geographically disparate computers over a multiprotocol router system.

Hope that helps.

4 0
3 years ago
Consider the following code snippet:public static void main(String[] args) throws FileNotFoundExceptionWhich of the following st
iVinArrow [24]

Answer:

The main method should simply terminate if the FileNotFoundException occurs.

Explanation:

Considering the full code snippet

snippet:public static void main(String[] args) throws FileNotFoundException

public static void main(String[])

represent the entry point method to a java main method

The addition of

throws FileNotFoundException

widens the scope of the main method to explicitly specifies that an exception named the FileNotFoundException may be thrown.

So, if any part of the code explicitly throws the FileNotFoundException the compiler makes use of this to throw an exception.

By throwing an exception, the main method is not catching any exceptions, instead it handles the FileNotFoundException by throwing it to the source which invoked the main method

This is required by the compiler to terminate the program if the FileNotFoundException occurs.

8 0
3 years ago
Anyone here codes? <br> C++, C#, Lua? Anything?
Travka [436]

Answer:

IxxyzjgzkgzjgKfzkg v

jvljcljxkhxkgg/gjhkggzkykzkgjzjgggggzjgcufxu

Explanation:

nk yxthzefhGghghrhgzxhhsdgchiixxu

7 0
3 years ago
Read 2 more answers
Other questions:
  • There are many modes of remote visual communication. Which is the most common mode?
    10·2 answers
  • Explain Cascading Style Sheets and what they do. Describe their primary function, two effects that this function has on programm
    11·1 answer
  • What should a password policy contain to reduce a hackers ability to crack the passwords?
    10·1 answer
  • Use fuel with the _____________ rating recommended by your vehicle manufacturer. A ) Converter B) Emission C) Exhaust D) Octane
    9·2 answers
  • Alex’s family members live in different parts of the world. They would like to discuss the wedding plans of one of their distant
    7·2 answers
  • What are the four stages a customer goes through when buying a product?
    7·2 answers
  • Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shi
    9·1 answer
  • Which file extension indicates a text document? .ppt .tst .pdf .txt
    14·2 answers
  • 1. Which of the following is not true about high-level programming language s? (a) Easy to read and write (b) Popular among prog
    12·1 answer
  • What are the common camera hazards? When might you encounter these hazards in your life, and what do you plan to
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!