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
The study and practice of information storage and retrieval is called
puteri [66]
Information Science
4 0
3 years ago
The proof that the Clique problem is NP-complete depends on a construction given in Theorem 34.11 (p. 1087), which reduces 3SAT
ki77a [65]

Answer:

Check the explanation

Explanation:

Kindly check the attached image below to see the step by step explanation to the question above.

5 0
3 years ago
_____ involves identifying and controlling the functional and physical design characteristics of products and their support docu
slamgirl [31]

Answer:

The correct answer to the following question will be Option C (Configuration management).

Explanation:

  • A method of device engineering to create and maintain continuity of the functionality, operational and physical characteristics of software with its specifications, configuration and operating details across its existence.
  • You will gain profit from:

Decreased risk of interruptions and data leaks through accessibility and keeping track of adjustments to your devices by implementing configuration management.

The remaining three solutions will not be capable of performing these functions. Therefore, the correct answer is alternative C Configuration management.

5 0
3 years ago
What are some of the challenges that could arise from setting up a file management system on a computer?
Arisa [49]
It could fail, it would take a long time setting it up and aslo it could be easily hacked.
3 0
3 years ago
What are software applications?
navik [9.2K]

Answer:

files that are stored on the computer

Explanation:

there is an actual definition, but it isnt listed here. Application software is commonly defined as any program or number of programs designed for end-users. That's it, in a nutshell.

4 0
3 years ago
Read 2 more answers
Other questions:
  • What is the correct order of network types when categorized by their size or the physical area they cover, from largest to small
    5·1 answer
  • A display that is thin, flexible, light, and easy to read in all types of light is a(n) _____. touch screen computer. electronic
    13·2 answers
  • A large flowing network of streams and rivers moving across a land area is a ______________________.
    15·1 answer
  • A word root is used to link a suffix that begins with a vowel. Which of the following words is an example of this rule? Group of
    6·1 answer
  • The parallax perspective says that objects that are close up appear to move __________ than far away objects.
    10·1 answer
  • What method of heat transfer is used when the sun heats the earth?
    14·1 answer
  • Hi<br>is it right?<br>"I think there is a small mistake in the quotation(second not first)"​
    5·1 answer
  • Paula needs to ensure that an animation she has created is repeated. Which option should she use to achieve this?
    8·1 answer
  • If, in a recursive solution, function A calls function B which calls function C, this is called ________ recursion. indirect thr
    6·1 answer
  • You use lpstat and determine that a user named User1 has placed two large print jobs in the queue for Printer1 that have yet to
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!