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
azamat
4 years ago
12

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 lastNotIn(). 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 the last character NOT found in str2. Return the index of the last character in str1 that does NOT appear inside str2. Note that if all of the characters in str1 appear in str2, then return -1. Call the function like this: cout << lastNotIn("eieioh", "aeiou"); // prints 5 (the index of h) cout << lastNotIn("aaaiii", "aeiou"); // prints -1 (all inside s2)
Computers and Technology
1 answer:
Law Incorporation [45]4 years ago
5 0

Answer:

Following are the program to this question:

#include <iostream> //defining header file

using namespace std;

int lastNotIn(string str1, string str2) //defining method lastNotIn

{    

int s1_len=0, i, loc=0, j=0; //defining integer variable

while(str1[s1_len] != '\0') //defining loop that checks str 1 length  

{

s1_len++; // increment length by 1  

}

for(i=s1_len-1;i>=0; i--) //reverse loop for str2

{

   while (str2[j] != '\0') //finding last index value

   {

   if (str1[i] == str2[j]) //comparing all character value

   {  

   loc=1; //assign value 1 in loc variable  

   break; //using break key  

   }

   else //else block

   {

   loc=0; //assign value 0 to loc variable

   }

   j++; //increment loop variable value by 1

   }

   if (loc == 0) //check condition value it is not found then

   {

   return i; //returns value of i

   }

}

  return -1; //return value -1

}

int main() //defining main method

{

  cout<<lastNotIn("eieioh", "aeiou")<<endl; //call method and print its value

  cout<<lastNotIn("aaaiii", "aeiou")<<endl;  //call method and print its value

  return 0;

}

Output:

5

2

Explanation:

In the above program, a method lastNotIn is defined, that accepts two string value "str1 and str2" in its parameter, inside the method four integer variable "s1_len, i, loc, and j" is declared, in which all the variable assign a value that is equal to 0.

  • In the next line, a while loop is declared, that counts str1 value length, and another for loop is used, that reverse value of str2, inside the loop a conditional statement is used, in if the block it will match str1 and str2 value if value match it will assign 0 in loc variable. otherwise, it will go to else block.
  • In this block it will assign 0 in loc variable and increment the j value by 1, outside the loop another if block is used, that check value of loc is equal to 0, if it is true, it will return i value.
  • In the main method, we call the method two times, the first time, it will give value 5, and the second time, it will give 2.  
You might be interested in
Global IT has designed its corporate structure with divisions based on their location. For example, there are the Southern and N
nirvana33 [79]

Answer: Geographical divisions

Explanation:

 The global IT is one of the example of the geographical division structure in an organization. It is basically divided on the basis of the operational location according to the services, product and the requirement.

The main benefits of this geographical division is that it bring all the employees together to perform specific functions and task in an organization. The geographical organization is one of the organisation where hierarchy of an organization are basically divided into geographical location.

6 0
3 years ago
Read 2 more answers
Programming In C:
levacccp [35]

Our function will simply be the inverse of the given one: celsius and kelvin degrees differ by 273.15. You add this number is you compute kelvin from celsius, and you subtract this number if you're going the other way around (which is what we're doing):

#include

double KelvinToCelsius(double valueKelvin ) {

double valueCelsius = 0.0;

valueCelsius = valueKelvin - 273.15;

return valueCelsius ;

}

3 0
3 years ago
Americans overwhelmingly support organ and tissue donation.
Simora [160]

This statement would be TRUE


7 0
4 years ago
Two independent customers are scheduled to arrive in the afternoon. Their arrival times are uniformly distributed between 2 pm a
seraphim [82]

Answer:

1/3

Explanation:

T₁ , T₂ , be the arrival times of two customers.

See expected time for the earliest and latest below.

The formulas used will guide you.

4 0
3 years ago
In the Gradient Descent algorithm, we are more likely to reach the global minimum, if the learning rate is selected to be a larg
Lady_Fox [76]
False iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
5 0
3 years ago
Other questions:
  • Design a kernel module that iterates through all task in the system using the for_each_process() macro. In particular, output th
    7·1 answer
  • The system should enable the staff of each academic department to examine the courses offered by their department, add and remov
    14·1 answer
  • What are the two components that make up the chipset?
    15·1 answer
  • Which of the following provides astronomical evidence for the age of the earth?
    11·1 answer
  • A cell reference with only one dollar sign before either the column or the row is called an absolute reference.
    10·1 answer
  • Which is an example of Raw Input?
    11·1 answer
  • Select the pieces of information that are added on to data to get it where it is going.
    5·1 answer
  • Sergio needs to tell his team about some negative feedback from a client. The team has been
    5·1 answer
  • Which is an example of an operating system? (5 points)
    5·1 answer
  • A _______ is a group of elements that you want to style in a particular way.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!