Question

USING C++ LANGUAGE

Q (5) Suppose you have been given the task to design a text editor which will take any multiline text from user and then disp

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#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.

Add a comment
Know the answer?
Add Answer to:
USING C++ LANGUAGE Q (5) Suppose you have been given the task to design a text...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C programming Description: You have been tasked to design an application for an engineering...

    Using C programming Description: You have been tasked to design an application for an engineering firm to measure the performance of their vehicle designs. The user, an engineer will enter data into your program when prompted and will perform the required calculation and output the answer. The formula used for this project calculates the distance an object will cover in meters given an initial velocity, a rate of acceleration and a time of acceleration or travel. 1. Your program must...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • so i have my c++ code and ive been working on this for hours but i...

    so i have my c++ code and ive been working on this for hours but i cant get it to run im not allowed to use arrays. im not sure how to fix it thank you for the help our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT