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
Coordinates that measure how far a point is from the origin are _______________. A. Relative coordinates B. Absolute coordinates
S_A_V [24]
The correct answer is B
4 0
4 years ago
Read 2 more answers
In the game Singularity, broken objects can be restored to their original condition by reversing time. This is an example of whi
Zolol [24]

Solution:

In the game Singularity, broken objects can be restored to their original condition by reversing time. This is an example of which time element of player adjustment.

Thus the required answer is player adjusted.

6 0
3 years ago
Read 2 more answers
The query [windows], English (US) has two dominant interpretations: the operating system and the windows in a home
Nadusha1986 [10]

Answer:

True

Explanation:

When the word windows is google, there are two basic interpretations: operating system and the windows in a home. This is the two dominant interpretation can be given to the word windows when queried.

6 0
3 years ago
Need help with the last one or if I got the others wrong
Stells [14]
I think the answer would be c? if im wrong my apologies.
3 0
3 years ago
Design a Verilog module that takes a high frequency clock input and outputs a clock signal at 1/1000 of the input frequency. The
JulsSmile [24]

Answer:

// Code your design here

module clk_div

#(

parameter WIDTH = 7,// width of register

parameter N = 100// value of division here 100

)

(clk,reset, clk_out);

input clk;

input reset;

output clk_out;

reg [WIDTH-1:0] r_reg;// counting register

wire [WIDTH-1:0] r_nxt;

reg clk_track;// clock value

always at(posedge clk or posedge reset)

begin

if (reset)// reset

begin

r_reg <= 0;

  clk_track <= 1'b0;

end

else if (r_nxt == N)

   begin

  r_reg <= 0;

  clk_track <= ~clk_track;

  end

else

r_reg <= r_nxt;

end

assign r_nxt = r_reg+1;    

assign clk_out = clk_track;

endmodule

testbench:

// Code your testbench here

// or browse Examples

module clkdiv2n_tb;

reg clk,reset;

wire clk_out;

clk_div t1(clk,reset,clk_out);

initial

clk= 1'b0;

always

#5 clk=~clk;

initial

begin

#5 reset=1'b1;

#10 reset=1'b0;

#5000 $finish;

end

initial

$monitor("clk=%b,reset=%b,clk_out=%b",clk,reset,clk_out);

initial

begin

$dumpfile("dump.vcd");

$dumpvars(2);

end

endmodule

Explanation:

see waveform

8 0
3 years ago
Other questions:
  • The fast food restaurant Chipotle pulled its app from Apple's app store when customer demand caused the firm's servers to crash.
    14·1 answer
  • The ________ utility automatically creates duplicates of your libraries, desktops, contacts, and favorites to another storage lo
    7·1 answer
  • Analyst is investigating proxy logs and found out that one of the internal user visited website storing suspicious java scripts.
    8·1 answer
  • The__ key is used to group or identify a field or record within a table. (you don't need it).
    5·2 answers
  • Using symbols (%, $, #, etc.) can make it easier to take notes.
    8·2 answers
  • I make a budget of my 1st Gamer PC its good?
    9·1 answer
  • Which range of values would result in 10 elements stored in an array?
    13·1 answer
  • In which of the following stages of the development process is a team MOST likely to interview a potential user of an app?
    6·1 answer
  • How does the quantity of data affect the accuracy of an experiment?
    7·1 answer
  • Imagine an everyday scenario in which you are using the internet: downloading a file, uploading a photo, checking your email, et
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!