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
Oxana [17]
3 years ago
5

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 lastOfAny().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 any character inside str2.Return the index of the last character in str1 where this occurs.
Computers and Technology
1 answer:
dolphi86 [110]3 years ago
4 0

Answer:

The function in C++ is as follows

int chkInd(string str1, string str2){    

int lenstr1=0;

while(str1[lenstr1] != '\0'){  lenstr1++;  }

int index = 0; int retIndex=0;

for(int i=lenstr1-1;i>=0; i--){

   while (str2[index] != '\0'){

       if (str1[i] == str2[index]){

           retIndex=1;

           break;         }

       else{   retIndex=0;      }

  index++;    }

  if (retIndex == 0){   return i;   }else{return -1;}}

}

Explanation:

This defines the function

int chkInd(string str1, string str2){    

First, the length of str1 is initialized to 0

int lenstr1=0;

The following loop then calculates the length of str1

while(str1[lenstr1] != '\0'){  lenstr1++;  }

This initializes the current index and the returned index to 0

int index = 0; int retIndex=0;

This iterates through str1

for(int i=lenstr1-1;i>=0; i--){

This loop is repeated while there are characters in str2

   while (str2[index] != '\0'){

If current element of str2 and str1 are the same

       if (str1[i] == str2[index]){

Set the returned index to 1

           retIndex=1;

Then exit the loop

           break;         }

If otherwise, set the returned index to 0

       else{   retIndex=0;      }

Increase index by 1

  index++;    }

This returns the calculated returned index; if no matching is found, it returns -1

  if (retIndex == 0){   return i;   }else{return -1;}}

}

You might be interested in
FREE POINTS JUST ANSWER MY LATEST TWO QUESTIONS PLEASE
Mekhanik [1.2K]

Answer:

Look down below for answer!

Explanation:

1. The internet has backup files and a greater authoritative figure can easily see the history on the photo, etc. Some apps have save files no matter what and can track the post, photo, and when and why it was deleted. The impression the photo left on people may not be left either.

2. The zoo can be breaking the law because even though they store the information safely, they do not have the visitors consent to having their information.

7 0
3 years ago
Read 2 more answers
2. To ________
Feliz [49]

Answer:2.render 3.resolution 4.visual communication 5.rasterizing 6.nondestructive 7.stroke&fill 8.lines&path 9.pixels

Explanation:

7 0
2 years ago
A(n) ____ is an attack that takes advantage of a system vulnerability.
jarptica [38.1K]
<span>Exploit -</span> An attack that takes advantage of a system vulnerability, often<span> due to a combination of one or more improperly configured services.</span>
8 0
3 years ago
In java write a program:A contact list is a place where you can store a specific contact with other associated information such
BigorU [14]

Answer:

import java.util.Scanner;

public class ContactInformation

{

public static String GetPhoneNumber(String[] nameVec, String[] phoneNumberVec, String contactName, int arraySize)  

{  

for(int i=0;i<arraySize;i++)

{

if(nameVec[i].equals(contactName))  

return phoneNumberVec[i];

}  

return "Contact doesn't exists!";

}

public static void main(String[] args)

{

int records;

Scanner sc = new Scanner(System.in);

System.out.print("Enter the size of contact List :");

records=sc.nextInt();

String[] contactNameList=new String[records];

String[] phoneNumberList=new String[records];

String contactName;

System.out.println("Enter the contact name and phone number :");

for(int i=0;i<contactNameList.length;i++)

{  

contactNameList[i]=sc.next();  

phoneNumberList[i]=sc.next();  

}  

System.out.println("Enter the name of the contact to be searched :");  

contactName=sc.next();

System.out.println(GetPhoneNumber(contactNameList,phoneNumberList,contactName,records));  

}  

}

Explanation:

In the following the function defined above for getting the contact

number on the basis of contact number provided we are checking the contact name list if we are able to find the contact name and if we did we return the contact number on the same index from the contact number list

which we found in the contact name list.

4 0
3 years ago
A retail store stocks two types of shirts A and B. These are packed in attractive cardboard boxes. During a week the store can s
antiseptic1488 [7]
300 of A and 300 of b
7 0
2 years ago
Other questions:
  • In the C-SCAN disk scheduling algorithm, the disk arm is required to move in one direction only until it reaches the last track
    7·1 answer
  • The purpose of the ____________ element is to provide a method for a browser to display different images depending on specific c
    14·1 answer
  • Differences between Quality of Services and a Service of Quality approach
    9·1 answer
  • How can a user preview the playback of an audio clip in PowerPoint? Use the drop-down menus to complete the statements.
    14·1 answer
  • In addition to paying $100 per month for health insurance, sam is responsible for paying her first $500 of medical bills every y
    10·1 answer
  • A computer essentially takes input, processes it, and produces output. Which person developed a machine in the mid-1880s that ac
    6·1 answer
  • In an MLA style citation for an image, what information should be listed first? A. The name of the creator B. The title of the i
    8·2 answers
  • In order to preview an attachment in an e-mail, click the attachment in the ______
    8·1 answer
  • The small flash memory used in<br>protable device like Laptop<br><br>​
    10·1 answer
  • The equals method of the Object class returns true only if the two objects being compared:_________
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!