Write a C++ program in Microsoft Visual Studio 2019 and using functions only with the following features. The program reads paragraph(s) from the file and stores it in a string. Then the program counts the occurrence of each word in the paragraph(s) and stores all words with their number of occurrences. If that word has appeared more than one time in the whole string, it should store the word only once along with its total number of occurrences. The output described above (in part 3) must be stored in a new file. The program must be written in user-defined functions. Use only these libraries (iostream, string.h, ctype, fstream, algorithm,conio.h, math.h)   Sample input: is the is and the is and the and is and only that is Sample output: is 5 the 3 and 4 only 1 that 1 ______________________________________________________________________________________________________________OR_____________________________________________                                           You can convert this code into user-defined functions (Code must be written in functions) #include #include #include #include #include using namespace std; int main() {     fstream f;     int i=0,b[50],j,x=0;     string word,a[50];     f.open("input.txt");     while(f)//reading data from the input file     {         f>>word;         transform(word.begin(),word.end(),word.begin(),::tolower);//to convert the word into lower case         if(word[word.size()-1]=='.' || word[word.size()-1]==',' || word[word.size()-1]=='?' || word[word.size()-1]=='!')             word[word.size()-1]='\0';//checking for punctuations and removing         int c=0;         for(j=0;j<50;j++)         {             transform(a[j].begin(),a[j].end(),a[j].begin(),::tolower);//conersion into lower case             if(word==a[j])//checking if the word already exists             {                 c=1;                 b[j]+=1;                 x=j;                 break;             }         }         if(c==0)//if the word is not present in the array we store the value         {             a[i]=word;//to store the word             b[i++]=1;//to store its frequency         }     }     b[x]-=1;//reducing the extra frequency count for the last occuring word     ofstream f1;     f1.open("output.txt");     for(int j=0;j

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 Write a C++ program in Microsoft Visual Studio 2019 and using functions only with the following features.

  1. The program reads paragraph(s) from the file and stores it in a string.
  2. Then the program counts the occurrence of each word in the paragraph(s) and stores all words with their number of occurrences.
  3. If that word has appeared more than one time in the whole string, it should store the word only once along with its total number of occurrences.
  4. The output described above (in part 3) must be stored in a new file.
  5. The program must be written in user-defined functions.
  6. Use only these libraries (iostream, string.h, ctype, fstream, algorithm,conio.h, math.h)

 

Sample input:

is the is and the is and the and is and only that is

Sample output:

is 5

the 3

and 4

only 1

that 1

______________________________________________________________________________________________________________OR_____________________________________________

                                         

You can convert this code into user-defined functions (Code must be written in functions)

#include <iostream>

#include<fstream>

#include<string.h>

#include<ctype.h>

#include<algorithm>

using namespace std;

int main()

{

    fstream f;

    int i=0,b[50],j,x=0;

    string word,a[50];

    f.open("input.txt");

    while(f)//reading data from the input file

    {

        f>>word;

        transform(word.begin(),word.end(),word.begin(),::tolower);//to convert the word into lower case

        if(word[word.size()-1]=='.' || word[word.size()-1]==',' || word[word.size()-1]=='?' || word[word.size()-1]=='!')

            word[word.size()-1]='\0';//checking for punctuations and removing

        int c=0;

        for(j=0;j<50;j++)

        {

            transform(a[j].begin(),a[j].end(),a[j].begin(),::tolower);//conersion into lower case

            if(word==a[j])//checking if the word already exists

            {

                c=1;

                b[j]+=1;

                x=j;

                break;

            }

        }

        if(c==0)//if the word is not present in the array we store the value

        {

            a[i]=word;//to store the word

            b[i++]=1;//to store its frequency

        }

    }

    b[x]-=1;//reducing the extra frequency count for the last occuring word

    ofstream f1;

    f1.open("output.txt");

    for(int j=0;j<i-1;j++)//writing the output into the output.txt file

    {

        f1<<a[j]<<" "<<b[j]<<"\n";

    }

    f.close();

    f1.close();

    return 0;

}

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education