Sample run 1: Function Call int size = 5; string input_strings [size] = {"clefairy", "meowth", "snorlax"}; 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++) { } cout <

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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₁
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₁
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
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Array
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education