Question

Document2 Tell me Layout References Mailings Review View 1. Write a program named Lab17B that will read 2 strings and compare

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


using namespace std;
#include <iostream>
bool compareLetters(string s1, string s2);
bool inside(string s1, string s2);
int main()
{
string letter1;
cout << "Enter first letter ";
   cin >> letter1;
string letter2;
cout<<"Enter second letter ";
cin>> letter2;

   if (compareLetters(letter1,letter2) == true)
cout<<"compareLetters() function result--True ";
else
cout<<"compareLetters() function result--False ";
   if( inside(letter1,letter2)==true)
   cout<< "inside() function result--True ";
   else
   cout<<"inside() function result--False ";
}

bool compareLetters(string s1, string s2)
{

   int n1=s1.length();
   int n2= s2.length();
   if(s1[0]==s2[0] && s1[n1-1]==s2[n2-1])
return true;
else
return false;
}


bool inside(std::string s1,std::string s2){
if(s2.size() > s1.size())
return false;

for (int i = 0; i < s1.size(); i++){
int j = 0;
// If the first characters match
if(s1[i] == s2[j]){
int k = i;
while (s1[i] == s2[j] && j < s2.size()){
j++;
i++;
}
if (j == s2.size())
return true;
else // Re-initialize i to its original value
i = k;
}
}
return false;
}

Please up vote if you get any help from the content. Your likes motivate us to solve more and help others too. Moreover, your likes improve our ratings so please help us as we help you. Thank You.

Add a comment
Know the answer?
Add Answer to:
Document2 Tell me Layout References Mailings Review View 1. Write a program named Lab17B that will...
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
  • Document2 Tell me ign Layout References Mailings Review View 1. Write a program called Lab18C that...

    Document2 Tell me ign Layout References Mailings Review View 1. Write a program called Lab18C that searches for a number in an array. T a. Write a bool function named search that receives 3 parameters: an int array, an int containing the length of the array, and an int number to search for. Return true if the number is in the array and false otherwise. b. Write a void function called fillArray with the array as a parameter that uses...

  • Grades for Katie Snyder: DHM.3213.30638 Document2 aver Draw Design Layout References Mailings Review View SH alibri...

    Grades for Katie Snyder: DHM.3213.30638 Document2 aver Draw Design Layout References Mailings Review View SH alibri (Bo... 12 A A Aa A EEEE I Ueb X, X APA CE AL Styles Sherri's Tan-O-Rama is a local tanning salon. The following information reflects its number of appointments and total costs for the first half of the year: Month Number of Appointments Total Cost January 475 $ 6,600 February 150 5,300 March 375 6,800 April 300 6,050 May 350 5,950 June 250...

  • AutoSave OF S U : Document2 sert Draw Design Layout References Mailings Review View Share Times...

    AutoSave OF S U : Document2 sert Draw Design Layout References Mailings Review View Share Times New... 12 AA Aa A BIVX, X ADA Styles Styles Dictate Sens 21 Required information [The following information applies to the questions displayed below.) Odessa, Inc., manufactures one model of computer desk. The following data are a regarding units shipped and total shipping costs: ble Month Number of Units Shipped Total Shipping Cost January $3,100 February 3,700 March 2.550 April 3.900 1,850 1450 July...

  • 1.) Write a recursive function named isPalindrome that will take a single string as an argument...

    1.) Write a recursive function named isPalindrome that will take a single string as an argument and determine if the argument is a palindrome. The function must return True if the argument is a palindrome, False otherwise. Recall that any string is a palindrome if its first and last characters are the same and the rest of it is also a palindrome (therefore, a single character is a palindrome): 2.) Consider a text file named samplestrings.txt that contains a collection...

  • C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask,...

    C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask, and get a character from the user. The function will return true if the character the user enters is NOT in either of the words, otherwise it will return false. Keep in mind that uppercase and lowercase letters are not the same. You will need to change both words and the character input by the user to the same case (upper or lower) -...

  • Statistics Exam 2 (1) Compatibility Mode gn Layout References Mailings Review View Help Tell me what...

    Statistics Exam 2 (1) Compatibility Mode gn Layout References Mailings Review View Help Tell me what you want to do AA Aa- Title x2x' A. e. || --를 :-, 2-B- 1Normal 1NoSpac Heading 1 Heading 2 Paragraph Styles Font a. rejecting a false null hypothesis rejecting a true null hypothesis C. failing to reject a false descriptive hypothesis d. failing to reject a true descriptive hypothesis 8. AType li error means that a researcher has falsely concluded that a treatment...

  • Help. In language c View Layout References Mailings Program 1 Write a simple invoice generating program...

    Help. In language c View Layout References Mailings Program 1 Write a simple invoice generating program for a pet store as follows: 1- Ask the user for tee tax rate and store it in a float variable. 2- Ask the user for the number of cats being purchased and store the value in an integer variable. 3- Ask the user for the price of one cat and store it in a float variable. 4- Ask the user for the number...

  • Assignment 1. - Word File Insert Design Layout References Mailings Review View Tell me what you...

    Assignment 1. - Word File Insert Design Layout References Mailings Review View Tell me what you want to do Sign in Share Home Cut Find Aria E Copy Paste Select Editing Format Painter Clipboard Paragraph Font 9 leads to cell division when the target gene is transcribed. When the signal is present, will the target gene be Styles (5) The following is a diagram of the RTK signalling pathway. Assume that when the signal is present the pathway Ligand Receptor...

  • Spreadsheet basics hwk Saved to this PC References Mailings Review View Help Design Layout Tell me...

    Spreadsheet basics hwk Saved to this PC References Mailings Review View Help Design Layout Tell me what you want to do A Aa- A,ッ. A. 닐를: 仨. a- E L Normal ITNo Spac Heading 1 Heading 2 T Paragraph Styles Z. Determne the numencal results that you would expect to be returned by the formulas in the tollowin spreadsheet. Type your answers in the column to the right of the formulas. 2 Simon Pie Co. Weekly Profit Model 4 Input...

  • C++ 1) Write a function named WordCount, which determines the number of words in a “C...

    C++ 1) Write a function named WordCount, which determines the number of words in a “C type” string. The function will have one parameter (the address of the string) and will return the number of words (words are separated by one or more spaces). (15 points) 2) Write a function named VowelConsonant which will have three parameters - all “C type” strings. The function will place all vowels (the characters a, e, i, o, u) from the first string into...

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