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.
- The array that contains all the strings.
- 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: peopleIn 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: HelloImportant 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
Step: 1
Code include include Solutionh ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started