Question
C++ Create a program that shows various c-string manipulation techniques. This lab should be implemented as a menu driven program that calls various functions that
C++
Create a program that shows various c-string manipulation techniques. This lab should be implemented as a menu driven program that calls various functions that demonstrate your understanding of character arrays, c-strings and the string class.
In main() create a menu with 5 options:
Doing Math with Strings
Counting Elements
C-String Manipulation
String Class Manipulation
Exit Program
Loop though the menu until the user selects to exit the program. You may use numbers or letters to indicate the menu options. Test that the user enters in a valid option. If they do not enter a valid option, tell the user their selection is invalid and allow them to reenter the option. The menu will continue to loop until a valid option is entered.
Write a function called cStringManip that demonstrates the following functions by writing code that performs that function (NOTE: cString variables should be declared as character arrays, not strings):
Enter in a string called testString. Display the string and its length by using strlen.
Enter in a first name and a last name into two separate strings. Copy the first name into a string called fullName using strcpy. Display that string and its length.
Add the last name to fullName using strcat. Display the fullName and the length. Note: make sure that there is a space between the first and last names.
Enter in a string called city.
Copy the contents of city into a string called fullAddress using strncpy. Copy only the actual number of elements in the string up to a max of 10 characters. The max value should be a constant.
NOTE: Remember, strncpy and strncat does NOT add a null terminator if the number of characters added is less the size of the string. So, make sure to add a null terminator if necessary!!
Compare the string city with the fullAddress string using strcmp. Display an output that states that the strings match or do not match based on the outcome.
Enter in two more strings (state and zip). Add them to fullAddress using strncat. Again, only concatenate the max number of characters. Display the output of the full address (should be in the format: Columbia, Maryland 21044)
Search for the state in the fullAddress string using strstr. Display the resulting string when the state is found.
NOTE: Remember, strstr returns a pointer. So there needs to be a pointer variable created to hold this pointer.
I Just need the function. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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