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
A clock is reading 10:27:54.0 (hr:min:sec) when it is discovered to be 4 seconds fast. Explain why it is undesirable to set it b
lara31 [8.8K]

Answer:

(a)Applications Time Stamp Events

(b)S=0.5(W-T_{skew})+T_{skew}, where T_{skew}≤W≤T_{skew}+8.

Explanation:

Some applications assume that clocks always advance, so they could timestamp events under this assumption.

In our case we have the wrong timed clock, say W and the hardware clock H which is supposed to advance at a perfect rate.

We proceed to construct a software clock such that after 8 seconds we can replace the wrong timed clock with the software clock in good conditions.

Let us denote the software clock with S.

Then, S=c(W-T_{skew})+T_{skew} where:

T_{skew}=The current Time(10:27:54) and;

c is to be found.

We already know that S=T_{skew}+4 when W= T_{skew}+8,

So:

S=c(W-T_{skew})+T_{skew}

T_{skew}+4=c(T_{skew}+8-T_{skew})+T_{skew}

4=8c

c=0.5

We obtain the formula

S=0.5(W-T_{skew})+T_{skew}, where T_{skew}≤W≤T_{skew}+8.

4 0
3 years ago
The goal for me is that I need to identify the objects needed for the UNO card game and the actions that those objects perform,
Alik [6]

Answer:

Explanation:

//Java program

class UnoCard{

  private String color;

  private int value;

 

  public UnoCard(String color , int val) {

      this.color = color;

      value = val;

  }

  public String getColor() {

      return color;

  }

  //set the color of the card

  public void setColor(String color ) {

      this.color = color;

  }

  //get the value of the card

  public int getValue() {

      return value;

  }

  //set the value of the card

  public void setValue(int val) {

      value = val;

  }

  //return true if card has same value or

  //same color as the card

  //return false otherwise

  public boolean isMatch(UnoCard card) {

      return (this.value==card.value)||(this.color==card.color);

  }

}

public class Card {

  public static void main(String args[]) {

      UnoCard card1 = new UnoCard("Red",10);

      UnoCard card2 = new UnoCard("Green",10);

      UnoCard card3 = new UnoCard("Blue",15);

     

      if(card1.isMatch(card2))System.out.println("Match");

      else System.out.println("No Match");

     

      if(card2.isMatch(card3))System.out.println("Match");

      else System.out.println("No Match");

  }

}

6 0
4 years ago
Hello! I hope you have a great day! Good things will come your way.
Ad libitum [116K]

Answer:

<h2>thanks </h2><h2>may god bless you </h2>
5 0
3 years ago
Para que sirve un software
dedylja [7]
No habla muy espaniol?
6 0
3 years ago
No time-weighting of contingently issuable shares is required when computing basic EPS. True or False
sveticcg [70]

Answer:

True

Explanation:

Earning Per Share (EPS)

Earnings per share (EPS) is calculated as a company's profit divided by the outstanding shares of its common stock. The resulting number serves as an indicator of a company's profitability.

Basic EPS

Basic EPS is calculated by dividing profit or loss attributable to ordinary equity holders of the parent entity (the numerator) by the weighted average number of ordinary shares outstanding (the denominator) during the period.

The earnings numerators (profit or loss from continuing operations and net profit or loss) used for the calculation should be after deducting all expenses including taxes, minority interests, and preference dividends.

The denominator (number of shares) is calculated by adjusting the shares in issue at the beginning of the period by the number of shares bought back or issued during the period, multiplied by a time-weighting factor.

Contingently issuable shares are included in the basic EPS denominator when the contingency has been met.

4 0
3 years ago
Other questions:
  • ________ is a method for addressing, creating, updating, or querying relational databases.
    9·1 answer
  • What is life all about?
    15·2 answers
  • Parameter variables should not be changed within the body of a method because _______________. Select one: a. it mixes the conce
    5·1 answer
  • write a program, using python, to determine the mean, median, and standard deviation of a list of numbers. In addition, count th
    7·1 answer
  • For window 7 explain the steps you will use to find the available program you will list.
    13·1 answer
  • Write a CPP Program to read an integer number. Use a pointer to display this numbe
    5·1 answer
  • Thsi is for gacha girl5467
    14·2 answers
  • Which file formats have relatively small file size and are therefore the most widely used formats for sharing and
    12·2 answers
  • Giusp minfg gấp vs ạ đáp án thôi nhé
    15·1 answer
  • Whats the best way to make a video game?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!