Question: Given a string, does occ appear in the middle of the string? To define middle, we'll say that the number of characters to the left

Given a string, does "occ" appear in the middle of the string? To define middle, we'll say that the number of characters to the left and right of the "occ" must differ by at most one.

Complete the following file:

main.cpp

Given a string, does "occ" appear in the middle of the string?

To define middle, we'll say that the number of characters to the

It's raining frogs and fleas. Write a function that tells you if the number of frogs in a sentence is the same as the number of fleas.

Complete the following file:

main.cpp

left and right of the "occ" must differ by at most one.Complete the following file: main.cpp It's raining frogs and fleas. Write a

#include #include // abs for integers using namespace std; 1 2 3 4 5 6 7 8 9 10 11 12 13 bool occMiddle(const string& s) { bool result{false}; int length = s.length(); int start = s.find("occ"); if(start==-1) return 0; int end =length-(start+3); int diff = start-end; return diff==0 || diff==1 || diff==-1; 14 15 16 } return result; pass occMiddle "1x3450cc12x4" true true fail occMiddle "occAOCCBBB" false true fail occMiddle "OCCAOCCBOCC" false true fail occMiddle "occoccAOCCBoccocc" false true fail occMiddle "occoccoccBoccocc" false true fail occMiddle "occoccAOCCOCCOCC" false true nass CcMiddle "accoccccccy" false false 12 Cus 2 #include 3 using namespace std; 4 5 bool fleasNFrogs (const string& s) 6 { 7 bool result{false}; 8 string word = ""; 9 //variables to store the count of fleas & frogs in the sentence 10 int fleas = 0, frogs = 0; 11 //loop through each character in the sentence 13 for (const auto c: 5 14 { 15 //if the character encountered is not a space and a dot 16 if (c != '' && c != '.') 17 //append the character to the word 18 word += c; 19 20 //else the word formed is checked 21 else 22 { 23 //if the word is fleas 24 if (word "fleas") 25 { 26 //increment the count of fleas 27 fleas++; 28 29 1/else if the word is frogs 30 else if (word == "frogs") 31 { 32 //increment the count of frogs 33 frogs++; 34 } 35 //clear the word to store the next word 36 word 37 } 38 } 39 40 //if the count of fleas & frogs are same then result is true else false 41 if (frogs == fleas) 42 result = true; 43 44 return result; ame Arguments Actual Expected pass fleasNFrogs "frogflea" true true fail fleasNFrogs "frogfrog" true false pass fleasNFrogs "ifrogicadoflea" true true fail fleasNFrogs "frogxxfleaxoxflea" true false pass fleasNFrogs "frogxfleaxfleaxfrog" true true fail fleasNFrogs "frogxfleaxfleaxca" true false fail fleasNFrogs "fleafleafrog" true false pass fleasNFrogs "fleaogfrog" true true fail fleasNFrogs "flea" true false fail fleasNFrogs "Frog" true false pass fleasNFrogs "ca" true true

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!