Question: Lab 6 (60 points) Chapter 10: Characters, C-Strings, and More About the string Class Independent Study This assignment will be graded on the basis of
Lab 6 (60 points) Chapter 10: Characters, C-Strings, and More About the string Class Independent Study This assignment will be graded on the basis of completion and effort. Turn in the .cpp file and appropriate screenshots in Canvas. 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:
1. Doing Math with Strings
2. Counting Elements
3. C-String Manipulation
4. String Class Manipulation
5. 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 stringMath.
The function should ask the user to input a value that represents the number of weeks as a string.
Then, ask the user to enter in the number of hours per day that they work and their hourly pay rate (again, enter as strings).
Convert the string to integers or doubles as appropriate.
Calculate and display the total number of working days in those weeks (there are a constant 5 working days per week).
Then calculate the weekly pay (number of hours per day * 5 days per week * hourly rate). Then calculate the total amount earned for the entered number of weeks. Display the pay per week and the total amount earned.
Finally, the function should ask the user if he/she wants to perform another calculation. Validate the input (the only valid values are Y and N; convert the input to upper case in the trap) and write the code that will allow for another set of calculations (again converting the input to upper case).
Extra credit will be awarded if the program validates that the number of weeks, the number of hours per day and the hourly pay rate are tested for validity upon entry. ? Write a function called CountElements that does the following:
Declare a char array called sentence of 40 elements (remember, use a constant, do not hard code the number) and assign the following: (I have noted the spacing) How(sp)is(sp)Course(sp)1,(sp)C++,(sp)going(sp)4(sp)u?
Declare counters that will count the number of elements that are: alphabetic, digits, upper case, lower case, punctuation and spaces (ex: numalph=0, numdig=0, etc)
Loop through each character in the array and increase the proper counter. Note: some of these will be counted twice. For example: C is both an alpha and an upper case.
Display the counts of each element. Output: Number of alphabetic characters: Number of digits: etc. Write a function called cStringManip that demonstrates the following functions by writing code that performs that function:
Enter in a string called testString. Display 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.
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 result when the state is found. Write a function named scStringManip that demonstrates the following concepts: Enter in two strings. Compare and sort the strings (ask for 2 words; if they are equal, state that they are the same; if not equal then alphabetize and display the two words in alphabetical order).
Enter in two strings. Append the second string to the first string using += (appending). Display the final string.
Enter in two strings. Concatenate the second string to the first string using + (concatenating). Display the final string. Write a function called ExitProgram that returns a Boolean value. The function confirms if the user wishes to exit the program. The only acceptable answers are Y and N (use toupper() to allow y and n). Exit the program if the user selects to do so.? Make sure you enter in everything EXACTLY is entered in these screen shots! Main Menu: Menu Option 1: ? Menu Option 2: Menu Option 3: ? Menu Option 4: Menu Option 5:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
