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
After separating from Mexico, Texas passed laws that made it harder for slave owners to _____________ slaves.
baherus [9]

Answer: b.

Explanation:

8 0
3 years ago
Read 2 more answers
Which command provides the source refrence at the bottom of the current page of a document?
DENIUS [597]

Answer:

Footnote

Explanation:

The notes related to citation or reference or comment that is assigned to a text on that page is called footnote.

3 0
3 years ago
Given the following method static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } } Wh
Zolol [24]

Answer: aaaa

Explanation:

Since the condition of n > 0 is satisfied, the number will decreement and the print out will look like the above answer.

3 0
3 years ago
Identify the key that would allow you to move to previous column in a row.
swat32
The answer is c tab
3 0
3 years ago
A power user needs you to install a second type of operating system on his computer to increase efficiency while running some sp
Troyanec [42]

Answer:

Hi,

Correct answer option is (D) Multiple boot

Explanation:

In multiple boot installation, more than one operating system can be installed on a single computer and a user can freely select the operating system to boot when starting up. Multiple boot allows us to retain the previous operating system and also the applications/software that cannot run in the first installed operating system.

Best wishes!

4 0
3 years ago
Other questions:
  • ________ are found on the motherboard and are used to attach your hard disk.
    6·1 answer
  • The person who can give a short defination of subroutine will get the brainliest.
    9·1 answer
  • Who invented the ENIAC? More than one answer may apply.
    14·1 answer
  • When you open as many links as you want, and still stay in the same browser window instead of cluttering your screen with multip
    5·1 answer
  • _________ is the start up sequence a computer conducts.
    9·1 answer
  • Spencer wants to choose a career path that wouldn’t hold him to an office or laboratory. Which of the following career paths wou
    13·2 answers
  • ​Client/server computing is​ a: A. network that connects sensors to desktop computers. B. distributed computing model where clie
    12·1 answer
  • Anyone down to play gta later i play on ps4?
    15·2 answers
  • X = 10<br> y = 20<br> x &gt; y<br> print("if statement")<br> print("else statement")
    6·1 answer
  • C++
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!