Question

In: Computer Science

THE NOT REPLACE PROBLEM Must use loops. Please do not use sequence of if statements. I...

THE NOT REPLACE PROBLEM

Must use loops. Please do not use sequence of if statements.

I need it in C++.

Given an input string, set result to a string where every appearance of the lowercase word "is" has been replaced with "is not". The word "is" should not be immediately preceded or followed by a letter -- so for example the "is" in "this" does not count.  

• for input of "is test" → "is not test"

• for input of "is-is" → "is not-is not"

• for input of "This is right" → "This is not right"

Solutions

Expert Solution

PROGRAM :

#include <iostream>
#include <string>
// importing regex module for regular expression
#include <regex>

using namespace std;

int main() {
string text;
cout << "Please enter the input string : ";
// getline() to input a string ot a sentence
getline(cin,text);
// \b acts as word boundary
// regex variable 'e' is initialized based on the question which matches for 'is' inside any statement
std::regex e("\\b(is)\\b");
// replace 'is' with 'is not'
cout<<"The replaced string is : " + std::regex_replace(text,e,"is not");
}

OUTPUT :


Related Solutions

THE STRING MATCH PROBLEM C++ only. Must use loops. Please do not use sequence of if...
THE STRING MATCH PROBLEM C++ only. Must use loops. Please do not use sequence of if statements. . Given 2 strings, a and b, set result to the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings. • for input of "xxcaazz", "xxbaaz" → 3 • for input of "abc", "abc" → 2 • for input...
How do I change my if statements into while and for loops, so that I can...
How do I change my if statements into while and for loops, so that I can make my bot go straight and turn exactly 12 times. /*********************************************************************** * Exp7_1_RotaryEncoder -- RedBot Experiment 7_1 * * Knowing where your robot is can be very important. The RedBot supports * the use of an encoder to track the number of revolutions each wheels has * made, so you can tell not only how far each wheel has traveled but how * fast...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
YOU MUST USE SWITCH STATEMENTS TO SOLVE THE NEXT TWO PROBLEMS. NO LOOPS ALLOWED we have...
YOU MUST USE SWITCH STATEMENTS TO SOLVE THE NEXT TWO PROBLEMS. NO LOOPS ALLOWED we have not covered them yet therefore we can't use them Write a program that displays the following menu: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display...
C++ Please Do not use loops!! Assignment : Dice Roll Redux In "Dungeons & Dragons" and...
C++ Please Do not use loops!! Assignment : Dice Roll Redux In "Dungeons & Dragons" and similar role-playing games, dice with different numbers of sides are used to determine the outcomes of events throughout the game. There are different dice for different occasions: 4-sided, 6-, 8-, 10-, 12-, and 20-sided dice are common. A required roll is typically designated <n>d<s> where <n> is the number of dice to throw and <s> is the number of sides on those dice. For...
Re-do Problem 1, but now implement the following method: i must use this code :- public...
Re-do Problem 1, but now implement the following method: i must use this code :- public static BagInterface intersection (BagInterface bagA, BagInterface bagB) and here how my java program must work This method must return a new bag which is the intersection of the two bags: bagA and bagB. An element appears in the intersection of two bags the minimum of the number of times it appears in either. For example, {1,1,2} ∩{1,1,2,2,3}= {1,1,2}. Do not forget to state the...
What are pre-test loops. Which C++ statements use pre-test loops? Why pre-test loops are called 0...
What are pre-test loops. Which C++ statements use pre-test loops? Why pre-test loops are called 0 to N loops? When do you use the pre-test loops? Give at least one example.
Objectives To reinforce the use of If-Else statements To learn how to use while loops Introduction:...
Objectives To reinforce the use of If-Else statements To learn how to use while loops Introduction: Mission to Mars Your friend has been playing a new Mars Colony simulator nonstop! They are always talking about how cool it would be if they could be a on the first real-life mission to Mars! To amuse your friend, you have decided to create a series of programs about the possible first colony on Mars. Problem: Where Can We Get the Best Deal?...
please do this in C++! I want to understand it, it must be done before the...
please do this in C++! I want to understand it, it must be done before the evening or nightime. Follow instructions exactly as it says. Please send a screenshot also with your code so I can see how it is supposed to be formatted. Since typing it a chegg answer, makes it look a bit messy. Your program will read in a file of commands. There are three types of commands: Warrior creates a new warrior with the specified name...
MUST USE LOOPS. Write a perl program that replicates the actions of a pez dispenser. The...
MUST USE LOOPS. Write a perl program that replicates the actions of a pez dispenser. The program should print out the contents of the dispenser showing that it is empty, prompt a user for 10 pez candy flavors/colors, print out the contents of the dispenser showing that it is full, dispense the candies one at a time, and then print out the contents of the dispenser showing that it is empty. The dispenser should only take in 10 candies and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT