Question

In: Computer Science

USE C++ for the program and kindly keep it as simple as possible , use recursion...

USE C++ for the program and kindly keep it as simple as possible , use recursion and do not use loops please keep program simple and comment if possible

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.

Solutions

Expert Solution

ANSWER :-

GIVEN THAT :-

#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;
  
}


Related Solutions

USE C++ and please keep program as simple as possible and also comment so it is...
USE C++ and please keep program as simple as possible and also comment so it is easy to understad 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...
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...
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...
C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
(C++) keep things as simple as possible. I would love a good starting point with hints...
(C++) keep things as simple as possible. I would love a good starting point with hints to be able to finish it! Write a function called is valid phone number that takes a phone number as an array of characters and its size, and returns true if the input array is a valid phone number, false otherwise. A phone number is valid only if it is of the following format: (uuu) uuu-uuuu where u is from ‘0’, ‘1’, ‘2’, etc....
This C++ program will use arrays, recursion, and pass by reference to calculate 02, 12, 22,...
This C++ program will use arrays, recursion, and pass by reference to calculate 02, 12, 22, 32, 42 and then print a message. Write a driver program (main) that includes the following: An array class (not a built-in-array) of 5 integers initialized to 0,1,2,3,4 the bases An integer initialized to 2 to hold the exponent A string initialized to “Good Job!\n”; A for loop that calls the recursive pow function with all of the bases and the exponent. Call the...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data: Players Name (string) Players Jersey Number (integer) Points scored by Player (integer) The program will have an array of 12 players (use less for testing and development, use a constant...
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...
write a simple program to demonstrate the use of static type of variables in c++... use...
write a simple program to demonstrate the use of static type of variables in c++... use comments to explain plz
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT