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
Unwanted or unneeded software included by manufacturers on new computers is called
Travka [436]
The answer is called bloatware. This is unneeded files that are actually on the computers which are already there even if it's new. It doesn't have any essential function and sometimes is a trial version. The application also adds up space which limits your free space storage. In other words, because it has no significant tasks to handle it is unnecessary, but it only serves as an additional profit to the company once it is purchased by the buyer.

Bloatware may also come especially in adware where a lot of extension applications are sometimes automatically installed after it is allowed to operate in just a click. The only solution for a bloatware is to uninstall it.  .
5 0
3 years ago
Your isp connects to the core routers of the internet via a _____. cable mode spine backbone satellite
melisa1 [442]

fairly certain its backbone

5 0
3 years ago
onsider a file system on a disk that has both logical and physical block sizes of 512 bytes. assume that the information about e
anygoal [31]

For three disk allocation strategies (contiguous, linked, and indexed),

in this case, the  physical blocks must be read from the disk are 1,4 and 2 respectively.

In the disk, every block has a sequential number. The majority of disks today do logical I/O in hardware. Physical I/O is seldom ever required of operating systems today.

File access uses virtual I/O. Similar to disk logical I/O is disk virtual I/O. The distinction is that with virtual I/O, as opposed to physical I/O, the blocks that make up a file are

You could want to transfer from virtual block 10 to virtual block 4 in a contiguous allocation. Since the file is contiguous and you are at logical block 10 + Z, block four can be accessed by reading logical block 4 + Z. Without any intermediaries, that can be done directly.

Each block in the linked structure has 511 bytes of data and one byte that serves as an offset to the following block.

Read the first block, determine the offset to the second block, read the second block, determine the offset to the fourth block, and then read the fourth block in order to gain access to the fourth block.

If blocks are numbered from 1 to 10, then then is the "4" correct. The remainder of the solutions, however, make the assumption that block numbering begins at 0, using division to obtain offsets.

Assume there is a contiguous index for the indexed way of allocating files. Once more, it is assumed that each offset in the index is one byte in size.

Let's say that Z serves as the index's origin. Then, the byte at block Z + 3 DIV 512 and the offset at 3 MOD 512 (3 = 4 - 1) make up the entry for block 4 (numbered 1 to 4).

You must read the index and the data block in order to locate the block (2 reads).

To learn more about disk allocation strategies click here:

brainly.com/question/15083707

#SPJ4

4 0
1 year ago
Traffic shaping reduces traffic by ________. preventing certain undesirable traffic from entering the network limiting the amoun
Lera25 [3.4K]

Answer:

Explanation:

Traffic Shaping is a technique for managing congestion on a network by delaying the flow of less important/desired packets on the network so more valuable/desirables ones are able to pass. Traffic shaping reduces traffic by preventing certain undesirable traffic from entering the network as well as limiting the amount of certain undesirable traffic entering the network.

5 0
3 years ago
What makes creating business cards difficult?
Gre4nikov [31]
Lots of information must fit in a small space is the correct answer
7 0
3 years ago
Other questions:
  • When you include a word cover page in a multi page document, the cover page is not considered the first page. True or false?
    13·1 answer
  • You have found statistics on the Internet that you would like to use in your speech.
    6·1 answer
  • Create a dictionary named letter_counts that contains each letter and the number of times it occurs in string1. Challenge: Lette
    14·1 answer
  • Match the number in the picture to the correct Excel interface part. Each number is only used one time.
    11·1 answer
  • Information flows:
    11·1 answer
  • How can an Excel table be added to a Word document? Check all that apply.
    15·1 answer
  • How can you tell the value of a purchase?
    7·1 answer
  • Directory services store information in a heirarchical structure. Which statements about Organizational Units (OUs) of a directo
    13·1 answer
  • 1. Encrypt this binary string into cipher text: 110000. Include in your answer the formula the
    10·1 answer
  • Jason is the motion picture projectionist at the local IMAX theater. This means that he runs the huge movie projector so that cu
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!