
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Write in C++
Now, what if Sam wants to insert Eevee after Pikachu but he doesn't know where Pikachu is located in his list. Let's help him search for a Pokemon by its name and insert another Pokemon directly after it. Write a function secondPlace() that takes six parameters and inserts a new Pokemon into a list right after another specified pokemon. Once you find the specified Pokemon, use the insertAfter() function from the previous sub-question to add the new Pokemon. The function should return the new number of strings in the array.
Note
- The same Pokemon may appear in the list multiple times (Sam has a bad memory). Assume that Sam wants every instance of the Pokemon he is searching for to be followed by the Pokemon he is attempting to insert.
- If the array is already full or if the number of strings that are going to be added to the array plus the current number of strings exceeds the total size of the array, the array should remain unchanged.
- Assume all inputs are lowercase alphabets.
Function specifications
- Name: secondPlace()
- Parameters (Your function should accept these parameters IN THIS ORDER):
- input_strings string: The array containing strings
- string_to_insert string: the string to insert
- string_to_find string: the string to find (target string)
- num_elements int: The number of elements that are currently stored in the array
- arr_size int: The number of elements that can be stored in the array
- count int: The number of the target strings present in the array
- Return Value: int:
- The number of elements in the array after the new strings are inserted into the array
- The original number of elements in the array if the new pokemon cannot be inserted into the array
![Sample run 1: Function Call
int size = 5;
string input_strings [size]
int num_elements = 3;
int count = 1;
string string_to_insert = "charizard";
string string_to_find = "meowth";
// updating num_elements with the updated value returned by secondPlace
num_elements = secondPlace (input_strings, string_to_insert, string_to_find, num_elements, size, count);
// print num_elements
cout << "Function returned value: " << num_elements << endl;
// print array contents
for(int i = 0; i < size; i++)
{
}
=
Output
{"clefairy", "meowth", "snorlax"};
cout <<input_strings[i] << endl;
Function returned value: 4
clefairy
meowth
charizard
snorlax
Q₁](https://content.bartleby.com/qna-images/question/b1d14486-aab8-45fa-9185-3d15b7af8b4b/152adfc0-62ba-4b18-bdd8-43861fcce8bc/jifm1en_thumbnail.png)
Transcribed Image Text:Sample run 1: Function Call
int size = 5;
string input_strings [size]
int num_elements = 3;
int count = 1;
string string_to_insert = "charizard";
string string_to_find = "meowth";
// updating num_elements with the updated value returned by secondPlace
num_elements = secondPlace (input_strings, string_to_insert, string_to_find, num_elements, size, count);
// print num_elements
cout << "Function returned value: " << num_elements << endl;
// print array contents
for(int i = 0; i < size; i++)
{
}
=
Output
{"clefairy", "meowth", "snorlax"};
cout <<input_strings[i] << endl;
Function returned value: 4
clefairy
meowth
charizard
snorlax
Q₁

Transcribed Image Text:Now, what if Sam wants to insert Eevee after Pikachu but he doesn't know where Pikachu is located in his list. Let's help him search for a
Pokemon by its name and insert another Pokemon directly after it. Write a function secondPlace() that takes six parameters and inserts a
new Pokemon into a list right after another specified pokemon. Once you find the specified Pokemon, use the insertAfter() function from
the previous sub-question to add the new Pokemon. The function should return the new number of strings in the array.
Note
• The same Pokemon may appear in the list multiple times (Sam has a bad memory). Assume that Sam wants every instance of the
Pokemon he is searching for to be followed by the Pokemon he is attempting to insert.
• If the array is already full or if the number of strings that are going to be added to the array plus the current number of strings exceeds
the total size of the array, the array should remain unchanged.
• Assume all inputs are lowercase alphabets.
Function specifications
• Name: secondPlace()
• Parameters (Your function should accept these parameters IN THIS ORDER):
input_strings string: The array containing strings
string_to_insert string the string to insert
string_to_find string the string to find (target string)
o num_elements int: The number of elements that are currently stored in the array
o arr_size int: The number of elements that can be stored in the array
o count int: The number of the target strings present in the array
O
O
O
• Return Value: int :
• The number of elements in the array after the new strings are inserted into the array
• The original number of elements in the array if the new pokemon cannot be inserted into the array
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Needs to be done in Assembly for Raspberry Pi 3B.arrow_forwardA for construct is used to build a loop that processes a list of elements in programming. To do this, it continues to operate forever as long as there are objects to process. Is this assertion truthful or false? Explain your response.arrow_forwardA for construct is used to build a loop that processes a list of elements in programming. To do this, it continues to operate forever as long as there are objects to process. Is this assertion truthful or false? Explain your response.arrow_forward
- please use your own code for better explanationarrow_forwardComplete the function that computes the length of a path that starts with the given Point. The Point structure = point on the plane that is a part of a path. The structure includes a pointer to the next point on the path, or nullptr if it's the last point. I'm not sure how to fill in the '?'; especially the while loop I'm not sure how to implement the condition for that.arrow_forwardPython please... Implement a function printIndex() that takes a list as a parameter, prompts the user to enter a whole number n, and prints the element in position Index[n]. If the list is empty ([]) or n is not a valid index into the list, the function will not print anything. Be careful to do the correct thing with negative indices. You should assume that the user will enter a whole number when prompted, and the function will crash if the user does not enter an integer. The function should not change the list passed as a parameter. Hint: Just because this involves a list does not mean that you need a loop to solve the problem. Think carefully about the right construct to use here. The following shows the function template, and several examples runs of the function (you must show all the examples with these values in your submission): Template def printIndex(lst): replace with your docstring newList = lst # ________________________ elementNum =…arrow_forward
- Consider there is a list i.e. listA = {20, 10, 5, 15, 3} Write python code that: a. Creates a function updateListA(), which takes listA as input parameter, adds 30 after 20, and adds 40 at the end of the listA. [Hint: create a parameterized function] b. Creates a function newList(), which takes listA as input parameter and creates a new list newList with same elements as listA but in reverse order. c. If there is a function defined as below: def example(par1, par2=30): print(‘valid’) From the following function calls: i. example(par1=1) ii. example(1, 2) iii. example(par2=1) iv. example(par1=5, par2=6) Which call is valid? Write the values of par1 and par2 if a call is valid? Suggest corrections if a call is invalid.arrow_forwardA for construct is used to build a loop that processes a list of elements in programming. To do this, it continues to operate forever as long as there are objects to process. Is this assertion truthful or false? Explain your response.arrow_forwardIn this task you will work with the linked list of digits we have created in the lessons up to this point. As before you are provided with some code that you should not modify: A structure definition for the storage of each digit's information. A main() function to test your code. The functions createDigit(), append(), printNumber(), freeNumber(), readNumber() and divisibleByThree() (although you may not need to use all of these). Your task is to write a new function changeThrees() which takes as input a pointer that holds the address of the start of a linked list of digits. Your function should change all of those digits in this linked list that equal 3 to the digit 9, and count how many replacements were made. The function should return this number of replacements. Provided codearrow_forward
- Written in python with docstrings if applicable. Thanksarrow_forwardC++ I'm interested in knowing if there are two adjacent strings in a list that are very similar to each other. For instance, "Zach" and "Zack" are only one character apart. Write a function, named "CloseEnough" that takes a const reference to a vector of strings and an int. The vector is a list of strings (each of the same length). The int represents how many characters can be different between any two strings next to each other. This function should return the index (an int) of the string that is within the second arguments distance to the next string in the vector. If no index fulfills this criteria, it should return -1. You should be using the STL algorithms to achieve this and no while or for loops.arrow_forwardIn C++, can I get a code example for a function that will return the intersection items for two sets. It will return/print out the shared (intersection) items for them. I am looking for an actual function preferably for a set class, comparing one instance of a set class with another, but definitely NOT a STL keyword. Thank you.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education