1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Oxana [17]
3 years ago
5

Write the following function without using the C++ string class or any functions in the standard library, including strlen(). Yo

u may use pointers, pointer arithmetic or array notation.Write the function lastOfAny().The function has two parameters (str1, str2), both pointers to the first character in a C-style string.You should be able to use literals for each argument.The function searches through str1, trying to find a match for any character inside str2.Return the index of the last character in str1 where this occurs.
Computers and Technology
1 answer:
dolphi86 [110]3 years ago
4 0

Answer:

The function in C++ is as follows

int chkInd(string str1, string str2){    

int lenstr1=0;

while(str1[lenstr1] != '\0'){  lenstr1++;  }

int index = 0; int retIndex=0;

for(int i=lenstr1-1;i>=0; i--){

   while (str2[index] != '\0'){

       if (str1[i] == str2[index]){

           retIndex=1;

           break;         }

       else{   retIndex=0;      }

  index++;    }

  if (retIndex == 0){   return i;   }else{return -1;}}

}

Explanation:

This defines the function

int chkInd(string str1, string str2){    

First, the length of str1 is initialized to 0

int lenstr1=0;

The following loop then calculates the length of str1

while(str1[lenstr1] != '\0'){  lenstr1++;  }

This initializes the current index and the returned index to 0

int index = 0; int retIndex=0;

This iterates through str1

for(int i=lenstr1-1;i>=0; i--){

This loop is repeated while there are characters in str2

   while (str2[index] != '\0'){

If current element of str2 and str1 are the same

       if (str1[i] == str2[index]){

Set the returned index to 1

           retIndex=1;

Then exit the loop

           break;         }

If otherwise, set the returned index to 0

       else{   retIndex=0;      }

Increase index by 1

  index++;    }

This returns the calculated returned index; if no matching is found, it returns -1

  if (retIndex == 0){   return i;   }else{return -1;}}

}

You might be interested in
Double clicking a word selects the entire word?
igor_vitrenko [27]
Yes. This is correct. :)
7 0
2 years ago
Read 2 more answers
What is the internet?
Inessa [10]
 this is the definition:<span>a global computer network providing a variety of information and communication facilities, consisting of interconnected networks using standardized communication protocols.</span>
3 0
3 years ago
Read 2 more answers
Which option should Gina click to edit the text contained in a text box on a slide in her presentation?
topjm [15]
Text box
hope this helped
3 0
2 years ago
Tom is not sure how to code contents such as title and meta elements. These are coded as ____ elements.
Naya [18.7K]

Answer:

Tom is not sure how to code contents such as title and meta elements. These are coded as <em>head</em> elements.

Hope that helps. x

8 0
2 years ago
Read 2 more answers
(70 points) This is a legit question that I have for a device FOR my homework.
guapka [62]

Answer:

it might be locked down so hold down the button for 20 sec and do a hard shut down, if it doesn't cut on try holding it down for down for 30 secs.  . IF that doesn't work there should be a port next to the power button. you can connect a micro-b cable to the kindle and then connect it to a computer or laptop if you have one.  There is a video where it shows you how to take it apart and repair if none of this helps

Explanation:  i hope this helps

7 0
3 years ago
Read 2 more answers
Other questions:
  • HELP ASAP!!!!!!!!! ITS A UNIT TEST: WILL MARK AS BRAINLIEST&gt;
    13·1 answer
  • Which device lets you hear audio on your computer?
    12·2 answers
  • Implement the function pairSum that takes as parameters a list of distinct integers and a target value n and prints the indices
    11·1 answer
  • Fortnite anyone? i just started tdy so dont be judgiee lol
    6·2 answers
  • In Windows Vista, which button is used to create a new folder?
    7·1 answer
  • Explain one way in which programmers may get hired.
    9·1 answer
  • The 'WIMP' environment is much more user friendly,why?​
    11·2 answers
  • Write a Java statement to create an object LG of class TvSets
    11·1 answer
  • - Which amongst the following is not a Characteristic of Cloud Computing?
    5·1 answer
  • Imagine that you just received a summer job working for a computer repair shop one of your first task is to take apart a compute
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!