Question: C++ Code Get Longest String Ask the user to input five strings and store them into an array. Then use the get_longest_string function to find

C++ Code

Get Longest String

Ask the user to input five strings and store them into an array. Then use the get_longest_string function to find the longest string in that array and return it.

get_longest_string should have two parameters.

  1. The array that contains all the strings.
  2. The size of the array.

Sample output

Please enter string #1: Hey Please enter string #2: hey Please enter string #3: whats Please enter string #4: up Please enter string #5: people The longest string is: people

In the case of two strings having the same length, then you should return the first of the two strings of the same length. For example:

Please enter string #1: Hello Please enter string #2: fee Please enter string #3: fi Please enter string #4: fo Please enter string #5: World The longest string is: Hello

Important note

Please make sure to create the get_longest_string function prototype in get_longest_string.hpp and its implementation in get_longest_string.cpp.

The main function in main.cpp already contains most of the implementation for retrieving input from the user. However, you need to properly create and store the inputs into an array and call the get_longest_string function appropriately.

Hint

std::string is a class which means it has data members and member functions. Try to see if you can find the right member function to help you out. This website provides the std::string class' member function list with their corresponding descriptions.

Step by Step Solution

3.33 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To accomplish this task you need to structure your C program as directed Lets break it down into steps implementing each part to fulfill the requireme... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!