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 visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
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.
You should use Visual Studio to write and test the program from this problem.   Write a...
You should use Visual Studio to write and test the program from this problem.   Write a complete program with a for loop that (5 pts) uses proper variable types. (10 pts) uses a for loop to read in a real numbers exactly 8 times (10 pts) adds the number read in the loop to a running sum. (10 pts) Computes the average of the 8 numbers as a real number. (5 pts) Prints the correct result with 2 decimal places,...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
 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...
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one...
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one array of size 24 to another array of size 24 using string instructions. Write 3 versions of this code. One code must copy byte at a time. One code must copy word at a time and one code must copy double word at a time. Cut and paste the array in memory to show your code is working.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT