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
Task 04
aleksley [76]

Answer:

are u sure this is the right question?

Explanation:

7 0
1 year ago
Task 2
USPshnik [31]
4.
3.
1.
5.
2.
I rearranged them so the program would make sense by arranging the interaction in a logical order then placing input statements in between
6 0
2 years ago
Read 2 more answers
Not everything is a success all of the time! So do you know which version of Windows was the least popular?
mario62 [17]

Answer:

windows xp

Explanation:

I think because it is not fast and don't play the games and programs which have higher requirements

7 0
3 years ago
You are the leader of your school's Go Green Club, which supports environmentally friendly choices and lifestyles. Your club wil
miskamm [114]

Answer:

(Answers may vary.)

My Considerations

The Go Green Club has a total of 100 members. I plan to photograph each of them in front of our club's "Go Green" sign. I have a deadline of 30 days to deliver the ID cards. Therefore, I have to ensure that all the cards are printed and ready for delivery in 20 days, with 10 days of buffer time (in case the cards require any edits or changes). Additionally, after I have submitted the draft for review, I will need the coordinator's final approval on the design and layout of the ID card.

Hardware Requirements

  • a desktop computer or laptop with adequate memory to run the software to create the ID cards
  • some external storage devices, such as pen drives and DVD disks, to share the design and layout for the coordinator to review; I will also need these devices to store the final digital file for print
  • a color scanner to scan hand-drawn artwork and signatures, which I will place on the ID card
  • a digital camera to capture photos of members, and to transfer them to the computer/laptop
  • a printer to make hard copies of the cards.
  • Software Requirements

I intend to use Scribus to create the ID cards because it is a free DTP application, and has most of the common features I'd need to create an ID card.

Formatting Techniques

  • I plan to use the following techniques to design the club ID cards.
  • I'll use the landscape or horizontal orientation. This will enable proper spacing for the ID card elements.
  • I'm planning to use a card measuring 3.370 inches × 2.125 inches. A card this size will ensure that all the elements of the card are visible.
  • I am planning to place the club logo on the top left corner, because the eye normally follows the path of the letter Z. This'll help the viewer to see the logo and identify/recognize the club.
  • Next I'll place the club name; I'll use the top-center alignment and also vertically align it to the logo. I'll use the sans serif font for the club name.
  • Following the Z-path rule, I'll place the member's photo to the right and the member's name under the photo. In this position, the photo and the name will be visible, and will not get mixed up with other elements. I'll print the member name with a serif font.
  • Finally, again in line with the Z-path rule, I'll position the club seal and the club director's signature at the right lower bottom. Although these elements are essential on an ID card, they do not require as much viewer attention as the club logo, name, and member photo.

Explanation:

I used Canva for this card.

8 0
3 years ago
Marco travels often and does not have consistent wireless Internet service. He frequently uses his mobile phone service to provi
bulgar [2K]

Answer:

PAN

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Using refracted laser light to store data on a photoreceptive substrate is essentially how ___ storage works. Theoretically this
    5·1 answer
  • What folder holds 32-bit programs installed in a 64-bit installation of windows?
    12·1 answer
  • Which of the following refers to special eyeglasses from Google that provide the user with visual information directly in front
    5·1 answer
  • Given an integer variable count, write a statement that displays the value of count on the screen. Do not display anything else
    11·1 answer
  • How to connect an Apple Watch series 3 to your iPhone (ASAP)
    6·2 answers
  • Assume that strikeCounter has already been declared to be a "pointer to int". Assume further that strikeCounter has been initial
    5·1 answer
  • 1. Which of the following cables are used in networking? Check all that apply.
    8·2 answers
  • How is binary used in pixels and in sound?
    5·2 answers
  • How to transfer bookmarks to new computer
    15·1 answer
  • WRITE A PROGRAM TO CALCULATE SIMPLE INTEREST
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!