Question

In: Computer Science

String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...

String Manipulator Write a program to manipulate strings. (Visual Studio C++)

In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class:

a)   Declare class Paragraph_Analysis
b)   Member Function: SearchWord (to search for a particular word)
c)   Member Function: SearchLetter (to search for a particular letter)
d)   Member Function: WordCount (to count total words)
e)   Member Function: LetterCount (ONLY to count all letters e.g ‘A’,’a’)
f)   Member Function: FindReplaceWord (to find and replace a word)
g)   Member Function: FindReplaceLetter (to find and replace a letter)
h)   Member Function: Summary (to display summary of frequency of each letter within the paragraph)
i)   Of course, a menu is expected by user to know about available functionalities of your Paragraph_Analysis application.

Note: you can use access specifiers, return types and list of parameters of your own choice.

Solutions

Expert Solution

I have written the C++ Program for the Above problem requirements and have shown few output, The code for program is :

#include<bits/stdc++.h>
using namespace std;

class Pragraph_Analysis
{
    string paragraph; // Declaring the paragraph as a string variable
public:
    Pragraph_Analysis(string & para)
    {
        paragraph = para;
    }
    bool SearchWord(string word)
    {
        int i=0,c=0;
         while (paragraph[i]!='\0')
        {
                if (paragraph[i]==word[c] && word[c]!='\0' && paragraph[i]!=' ')
                c++;
                else
                c=0;
                i++;
        }

        if (c==word.length()) // if word found the return true else false
        return true;
        else
        return false;
    }
    bool SearchLetter(char letter)
    {
        for(int i=0;i<paragraph.length();++i)
        {
            if(paragraph[i]==letter)
                return true;
        }
        return false;
    }
    int WordCount(string word)
    {
    int count = 0;
        int strLen  = paragraph.length();
        int wordLen = word.length();
        int j;
        for(int i=0; i <= strLen; i++)
        {
                for(j=0; j< wordLen; j++)
                {
                        if(paragraph[i + j] != word[j])
                        {
                                break;
                        }
                }
                if(j == wordLen)
                {
            count++;
                }
        }
        return count;
    }
    int LetterCount(char letter)
    {
        int count=0;
        for(int i=0;i<paragraph.length();++i)
        {
            if(paragraph[i]==letter)
            {
                count++;
            }
        }
        return count;
    }
    void ReplaceWord(string word,string newword)
    {
        int wordl=word.length();
        for (int j = 0; j < paragraph.length(); j++)
            {
            string key = paragraph.substr(j, wordl), repl;
            if (key ==  word) {
                repl = newword;
                for (int k = 0; k < wordl; k++)
                 {
                    paragraph[j+k] = repl[k];
                }
            }
        }
    }
    void FindReplaceLetter(char letter,char newletter)
    {
        for(int i=0;i<paragraph.length();++i)
        {
            if(paragraph[i]==letter)
                paragraph[i]=newletter;
        }
    }
    void summary()
    {
        map<char,int> m;
        for(int i=0;i<paragraph.length();++i)
        {
                m[paragraph[i]]++;
        }
        cout<<" Showing the count of every character in Paragraph in ascending order"<<endl;
        for(auto c:m)
        {
                cout<<c.first<<" :"<<c.second<<endl;
        }
    }
};


int main ()
{
    string text;
    cout<<"Enter the Paragraph Text :\n";
    getline(cin,text);
    Pragraph_Analysis para(text); //created object of class
    int choice=-1;
    cout<<endl<<"Enter your choice from the Menu :\n";
    cout<<"1. Search a word"<<endl;
    cout<<"2. Search a letter"<<endl;
    cout<<"3. Count the frequency of a word"<<endl;
     cout<<"4. Count the frequency of a letter"<<endl;
     cout<<"5. Find and Replace a word"<<endl;
     cout<<"6. Find and Replace a letter"<<endl;
     cout<<"7. To see Summary of paragraph"<<endl;
     cin>>choice;
     switch(choice)
     {
         case 1:
             {
                 string word;
         cout<<"Enter the word to be searched"<<endl;
         cin>>word;
         if(para.SearchWord(word))
            cout<<"Found"<<endl;
         else
            cout<<"Not Found"<<endl;
             }
        break;
            case 2:
                {
                     char letter;
            cout<<"Enter the letter to be searched"<<endl;
         cin>>letter;
         if(para.SearchLetter(letter))
            cout<<"Found"<<endl;
         else
            cout<<"Not Found"<<endl;
                }

            break;
            case 3: {string word;
         cout<<"Enter the word to be count"<<endl;
         cin>>word;
         cout<<para.WordCount(word)<<endl;}
            break;
            case 4: {char letter;
            cout<<"Enter the letter to be count"<<endl;
         cin>>letter;
         cout<<para.LetterCount(letter)<<endl;}
         break;
            case 5:{string word,newword;
         cout<<"Enter the word to be replaced and new word"<<endl;
         cin>>word;
         cin>>newword;
         para.ReplaceWord(word,newword);}
         break;
         case 6:{char letter,newletter;
            cout<<"Enter the letter to be replaced and new letter"<<endl;
         cin>>letter;
         cin>>newletter;
         para.FindReplaceLetter(letter,newletter);}
         break;
         case 7: para.summary();
         break;
         default:
            cout<<"Wrong Choice"<<endl;
     }
}

OUTPUT SAMPLES:


Related Solutions

Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
Write a C program of car sale: The Visual Studio project itself must make its output...
Write a C program of car sale: The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 10%: Looping Menu with 2 main actions: Sell Car, View Sales Note: A Car is defined only by its price 10% Must contain at least one array containing sales figures (each entry represents the price of one vehicle) for a maximum of 10 Cars 5%:...
In c++, using stack structure, write a program that will take a sequence of characters (string)...
In c++, using stack structure, write a program that will take a sequence of characters (string) and determine whether it is a palindrome. Use the linked version of the stack.
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout,...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout, \n, \t, solving expressions )  Correcting errors Q1: Draw flow Chart of the following problems: a) Display “Hello World” on screen. b) Display Your Name, date of birth and mobile number on screen. c) Compute and display the perimeter and area of a rectangle with a height of 7 inches and width of 5 inches. d) Compute and display the perimeter and area...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
Write a C++ program to help the Administration of a football league to manipulate the list...
Write a C++ program to help the Administration of a football league to manipulate the list of players registered in different teams. There are 26 teams participating in the league, each is denoted by a letter in the range A to Z. Each team can have 11 players at most. The information of all teams' players are stored in a text file named 'players.dat'. Each line from the input file contains the details of one player; where the player's details...
PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find...
PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT