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
3 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]3 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
Which cloud technology characteristic ensures that a cloud customer can make changes to her cloud database from her smartphone w
Setler79 [48]

The cloud technology characteristic that ensures that a cloud customer can make changes to her cloud database from her smartphone is Broad network access.

<h3>What is the network about?</h3>

Broad network access is known to be a feature of cloud computing as it is seen as  the ability of network tools to be able to link with a large scope or variety of devices.

Note that The cloud technology characteristic that ensures that a cloud customer can make changes to her cloud database from her smartphone is Broad network access.

Learn more about cloud technology from

brainly.com/question/19057393

#SPJ1

5 0
2 years ago
Is technology science? I mean, I think it is... uh, why am I so paranoid about this project.
STALIN [3.7K]

Answer:

i ..d..k do something ez

Explanation:

5 0
3 years ago
Read 2 more answers
Qbasic program to accept 10 numbers and to find their sum. <br>​
sesenic [268]

Answer:

the answer is 5

Explanation:

6 0
3 years ago
Which of the following is an example of an application software?
pishuonlain [190]
Word processing software
6 0
2 years ago
Describe the steps involved in data mining or data analytics when viewed as a process of knowledge discovery.
Aleksandr [31]

Answer:

1. Data Cleaning

2. Data Integration

3. Data Selection

4. Data transformation

5. Data Mining

6. Pattern Evaluation

7. Knowledge presentation

Explanation:

The steps involved in data mining or data analytics when viewed as a process of knowledge discovery includes the following:

Step 1. Data cleaning: this involves the elimination of inconsistent data.

Step 2. Data integration: this involves the combination of data from multiple sources.

Step 3. Data selection: this is the step where significant data for task examination are gathered from the database.

Step 4. Data transformation: this the step in which the data are modified for mining by conducting the aggregate operation.

Step 5. Data mining: this step involves the extraction of data patterns through specific techniques.

Step 6. Pattern evaluation: this step involves the identification of patterns that depict knowledge based on measures.

Step 7. Knowledge presentation: this is the step in which visualization and knowledge representation methods are utilized to illustrate mined knowledge to users.

6 0
2 years ago
Other questions:
  • Plz answer and dont put a random thing for the points
    11·1 answer
  • What does using indirect quotations allow a writer to do?
    7·2 answers
  • A local area network works as a ____ network in that clusters of workstations are connected to a central point (hub or switch) t
    6·1 answer
  • Your school computer library has a network that connects computers and devices within a few small rooms. what type of network do
    7·1 answer
  • What is the purpose of the .NET Framework Class Library? a. it provides pre-written code that can be used by .NET applications b
    13·1 answer
  • Which of the following is not a key way that a LAN shares
    15·1 answer
  • Use the Windows ________ to check on a nonresponsive program. Select one: A. Backup utility B. Task Manager C. System Restore D.
    10·1 answer
  • Which of the following candidates would most likely be hired as a graphic artist?
    15·2 answers
  • Question #2: How would you demonstrate professionalism in a video call with a teacher? Edmentum Digital world Please Help!!
    8·1 answer
  • When adding a component to a container with the ____ layout, specify the NORTH, EAST, SOUTH, WEST, or CENTER position.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!