Question

C++ program. Design a class and function that does a basic word search and all the...

C++ program. Design a class and function that does a basic word search and all the possible functions. In a class, there can be lookup, replace, count word, count character function, and more.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<string>

#include<stdio.h>

#include <bits/stdc++.h>

#include <boost/algorithm/string/replace.hpp>

using namespace std;

class sentence{

public:

//Function will replace the value with the value you entered

void replace(string word){

string name;

cout<<"Enter a String"<<endl;

getline(cin,name);

string rep;

cout<<"Enter the Replacer "<<endl;

cin>>rep;

//built in function of string to replace

boost::replace_all(name, word, rep);

cout<<name<<endl;

}

//function to count the characters in a string

void character_Count(string se){

cout<<se.size();

}

//function will count words in a sentence

void wordcount(){

char arr[50]; // putting the string into character array

int count = 0, i;

cout << "Enter a string : ";

gets(arr); //gets function use to get the value from a character array

cin.get();

//loop will run till array index not equal to NULL space

for (i = 0; arr[i] != '\0';i++)

{

if (arr[i] == ' ')

count++;

}

cout << "Number of words " << count + 1;

}

//Function will find the word from the string you will enter

void lookup(){

int i=0,j=0;

string sentence ;

string key ;

cout<<"Enter a sentence "<<endl;

getline(cin,sentence);

cin.ignore();

cout<<"Enter the word to find "<<endl;

getline(cin,key);

while(sentence[i]!='\0')

{

if(sentence[i]==key[j] && key[j]!='\0'&& sentence[i]!=' ')

j++;

else

j=0;

i++;

}

if(sentence==strlen(key))

cout<<"Word found"<<endl;

else

cout<<"Word not found"<<endl;

}

};

int main (){

sentence obj;

int choice;

string nameee;

cout<<"Press 1 check string lookup function"<<endl;

cout<<"Press 2 for replace function"<<endl;

cout<<"Press 3 for count word"<<endl;

cout<<"Press 4 for count character"<<endl;

cin>>choice;

if(choice==1){

obj.lookup();

}

else if(choice==2){

string key;

cout<<"Enter the the word to be replaced "<<endl;

getline(cin,key);

obj.replace(key);

}

else if (choice==3){

obj.wordcount();

}else if(choice==4){

cout<<"Enter a sentence"<<endl;

getline(cin,nameee);

obj.character_Count(nameee);

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
C++ program. Design a class and function that does a basic word search and all the...
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
  • write a program which include a class containing an array of words (strings).The program will search...

    write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...

  • C++ PART B: (STRING) – 40% Program Description: Write a word search program that searches an...

    C++ PART B: (STRING) – 40% Program Description: Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears  in the input data file.   In addition, the program should read and display each word with the count of vowels in each word.  For example : The 1 Friend 2 Wrote 2 Write functions to process and display the results. No non-constant global variables should...

  • Program Description: (C++). Write a word search program that searches an input data file for a...

    Program Description: (C++). Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of characters in the input data file that are not vowels. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string &word, int &wordCount, int &nonVowelCount) ; void...

  • Design an algorithm which transforms a source word to a target word. for example: from head...

    Design an algorithm which transforms a source word to a target word. for example: from head to tail. In each step, you just can replace one character, and the resulting word must be valid. You'll be given a dictionary. Your function must not only return if there is a path but spell the specific path: bool isThereValidPath(map validWords, string startWord, string endWord) {} Program should be in java

  • C++ Program Help Prompt your user to enter a length of a word to search from...

    C++ Program Help Prompt your user to enter a length of a word to search from a string. Use forking to spawn a child process to perform the counting task. Allow the child process to finish and output the number of words found (if any), before prompting the user for the next length. Count all words in the string with this length and output the number of words that correspond to this length. Program keeps asking user for length till...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • The program needs to be written in C. Write a function void camelCase(char* word) where word...

    The program needs to be written in C. Write a function void camelCase(char* word) where word consists of more than two words separated by underscore such as “random_word” or "hello_world_my_name_is_sam". camelCase() should remove underscores from the sentence and rewrite in lower camel case” (https:// en.wikipedia.org/wiki/Camel_case). Watch out for the end of the string, which is denoted by ‘\0’. You have to ensure that legal strings are given to the camelCase() function. The program should only run when the input is...

  • C Programming Language on Linux - Word Frequency Program Please write a Program in C that...

    C Programming Language on Linux - Word Frequency Program Please write a Program in C that will accept a text file name as a command-line argument via a main program that will do the following: First, read the file (first pass) and create a linked list of words (in their order of occurrence), with the frequency of each word set to 0. Then, read the file (second pass) and for each word identified, search the linked list, and when found,...

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

  • How do I format this into C++? This the prompt: Design a class named Password that...

    How do I format this into C++? This the prompt: Design a class named Password that stores a password in a c-string and has member functions to test if the password complies with certain requirements as follows: The password should be between 6 and 20 characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. The password should have at least one punctuation character. Define a...

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