Question

In: Computer Science

Solve this question in C++ language. DO NOT use loops. Use recursive function. Keep the program...

Solve this question in C++ language. DO NOT use loops. Use recursive function. Keep the program simple.

Q (5) Suppose you have been given the task to design a text editor which will take any multiline text from user and then display the statistics like total number of characters i.e., characters_count (excluding the white space and punctuations), words_count, and redundant_words_count. Create a structure named Text_Editor having four type members namely inserted_text (of type string), characters_count (of type unsigned int), words_count (of type unsigned int), and redundant_words_count (of type unsigned int). The structure should also have member functions namely Insert_Text( ) for obtaining the multiline text from user and assigning to input_text member-variable. End of text insertion should be specified by ‘#’ character. Moreover, there should be a separate member-function of the created structure named Count_Ch( ), Count_Words( ), and Count_Redundant_Words( ) that should process the input text in order to calculate and print the relevant statistics. All these different tasks are to be implemented using recursion technique.                                (30 Points)

Solutions

Expert Solution

#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
struct Text_Editor{
    string inserted_text;
    int characters_count;
    int words_count;
    int redundant_words_count;
    void Insert_Text(string s){
        inserted_text=s;
    }
    int i=0;
    void Count_Ch(){//used to count characters
        char char_array[inserted_text.length()+1];//Declaring a char array
        strcpy(char_array, inserted_text.c_str());//storing text in a char array
        char ch=char_array[i++];//Iterating through every single character
        int c=(int)ch;//Storing the ASCII value of character "ch" in variable "c".
        //How to get an ASCII value of a char
        //for eg: if we want an ASCII value of 'a' then type convert that char to int
        //ASCII value of a=(int)'a'
        /*In the below if statement we are getting the ASCII value of 'a','z','A','Z'
        and checking the ASCII value of a char from char_array so that its ASCII value
         lies in the range of ASCII value of ('a','z') or ('A','Z') . in that way we are
        counting the number of characters in a string which are pure alphabets
        (ignoring spaces and other punctuation marks*/
        if((c>=(int)'a'&&c<=(int)'z')||(c>=(int)'A'&&c<=(int)'Z')){
            characters_count+=1;
        }
        if(i<=strlen(char_array)){
                Count_Ch();
            }
    }
    void Count_Words( ){
        /*Here we are getting the total number of characters in a string
        irrespective of spaces and punctuation marks*/
        words_count=inserted_text.length();
    }
    void Count_Redundant_Words( ){
        /*This is simple we know the number of characters without spaces
        punctuation marks and also we know the total number of characters in a string
        irrespective of spaces and punctuation marks
        so to find the number of redundant words
        redundant words=total characters(including spaces and punctuation)-characters(excluding spaces and punctuation)*/
        redundant_words_count=words_count-characters_count;
    }
};
int main()
{
    Text_Editor t;
    cout<<"Enter your text:";
    string s;
    getline(cin,s);
    t.Insert_Text(s);
    cout<<"Text entered is:"<<t.inserted_text;
    t.Count_Ch();
    cout<<"\nCharacters count:"<<t.characters_count;
    t.Count_Words();
    cout<<"\nWords count:"<<t.words_count;
    t.Count_Redundant_Words();
    cout<<"\nRedundant words count:"<<t.redundant_words_count;
    return 0;
    
}

Thank you! if you have any queries post it below in the comment section I will try my best to resolve your queries and I will add it to my answer if required. Please give upvote if you like it.


Related Solutions

PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT PLEASE. Problem: Driving Function driving(): Write a function driving(), that updates the odometer and fuel gauge of a car. The function will take in a reference to the variables storing the odometer and fuel gauge readings, along with a double representing the miles per gallon (mpg) the car gets and the number of miles the driver intends to go. The function should update the...
In C program, Use "do...while" and "for" loops to write a program that finds all prime...
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
c++ using recursive no loops (for ,while ..ect)not allowed Write a recursive function ‘bool palindrome(string s)’...
c++ using recursive no loops (for ,while ..ect)not allowed Write a recursive function ‘bool palindrome(string s)’ that returns true if s is a palindrome and false if not. #5: Write a recursive function 'void reverse(string &word)' that reverses the given input string. string name = "damian"; reverse(name); cout << name << endl; //should display "naimad". #7: Write a function 'int numTwos(int n)' which returns the number of 2's in the base-4 expansion of n. cout << numTwos(2170) << endl; //...
Please use C language and use link list to do this program. This program should ask...
Please use C language and use link list to do this program. This program should ask user to enter two fraction polynomials. Then user chocie if he want add it or multiple it. I need you please to test it to see if it work with these two fraction polynomials 1-  Left Poly Pointer: 1/1x2 + 3/4x + 5/12 2-Right Poly Pointer: 1/1x4 – 3/7x2 + 4/9x + 2/11 AND AFTER ADDING 3- Resulting Poly Pointer: 1/1x4 + 4/7x2 + 43/36x...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem you will take a list of names from the user and sort them alphabetically using selection sort. The code for selection sort for integer is available in the "Lab and Weekly Coding Solution module" in webcourses. Ask the user how many names the user wants to input. Let's say the number be N. Then take N number of names and put them in an...
Write in Racket language. Write a non-recursive Racket function called "keep-short-norec" that takes an integer and...
Write in Racket language. Write a non-recursive Racket function called "keep-short-norec" that takes an integer and a list of strings as parameters and evaluates to a list of strings. The resulting list should be all strings on the original list, maintaining their relative order, whose string length is less than the integer parameter. For example, (keep-short-rec 3 '('abc' 'ab' 'a')) should evaluate to '('ab''a') because these are the only strings shorter than 3.
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q (4) Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the 1st token...
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is...
note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is allowed. The game of “Jump It” consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board where n is 6: 0 3 80 6 57 10 The object of the game is to move from the first column to...
(Please solve the question using C Language. Thanks). Write a function called is_perfect which takes an...
(Please solve the question using C Language. Thanks). Write a function called is_perfect which takes an integer n and returns 1 if n is a perfect number, otherwise it will return 0. If the sum of a number’s proper divisors are equal to the number, than the number is called a perfect number. For example, 6 is a perfect number: 6=1+2+3.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT