Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a C++ coding All code must be done using visual studio software!! Make a program that shows various c-string manipulation techniques. This lab

This is a C++ coding

All code must be done using visual studio software!!

Make a program that shows various c-string manipulation techniques. This lab must 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() - make a function to display the program title and program introduction. Then make a menu with 4 or 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.

Make a function called stringMath. This function calculates the profit or loss for a package delivery company. ? The function must ask the user to input a value that represents the number of miles driven in a week as a c-string. ? Then, ask the user to enter in the miles per gallon that their vehicle gets as a c-string. Next, enter in the cost of a gallon of diesel fuel as a c-string. Finally, enter in the number of packages delivered per week as a c-string. ? Convert the c-string to integers or doubles as appropriate. ? Calculate and display the total number of miles driven, the total gallons of fuel, the total cost of the fuel. ? Then calculate and display the average number of packages delivered per day, the average number of miles, average number of gallons and average cost per day to run the vehicle. Assume a 7-day week. ? Then calculate and display the total revenue made by delivering the packages. You need the total number of packages delivered in the week and multiple each package by $0.37 per package to get the revenue. ? Then calculate the total profit for the week. The profit is the amount of revenue minus the cost of the diesel fuel. Display the profit or the loss. ? The function must ask the user if they want 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). The code can reuse the function written in CE-Strings for this task. ? Extra credit: the program validates that the number of miles, the number of miles per gallon, the cost of a gallon of fuel and the number of packages per delivered per week are valid upon entry as a c-string. This means it is tested for numeric validity as well as if it is a number. If it not valid or not a number, the code displays an error and allows reentry.

Make a function called CountElements that does the following: ? In main(), declare a char array called sentence of 65 elements (remember, use a constant, do not hard code the number) and assign the following: (I have noted the spacing) How(sp)R(sp)cStrings(sp)4(sp)U?(sp)They(sp)can(sp)B(sp)tricky(sp)4(sp)brand(sp)new( sp)C++(sp)students! ? Send this c-string to the CountElements function as a parameter. ? Declare counters that will count the number of elements that are: alphabetic, digits, upper case, lower case, punctuation, and spaces ? 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 as defined in the screen shot. Write a function called cStringManip that demonstrates the following functions by writing code that performs that function (NOTE: cString variables must 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 completeName using strcpy. Display that string and its length. ? Add the last name to completeName using strcat. Display the completeName and the length. Note: make sure that there is a space between the first and last names. ? Enter in a single character and a single integer number. ? Replace the character indicated by the number with the new character entered. Remember to count correctly based on array counting. ? Enter in a string that will hold the city name. ? Copy the contents of city into a string called completeAddress using strncpy. Copy only the actual number of elements in the string up to a max of 10 characters. The max value must be a constant. ? Compare the city string with the completeAddress 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 (one for state and one for zip). Add them to completeAddress using strncat. Again, only concatenate the max number of characters. Display the output of the complete address (must be in the format: Columbia, Maryland 21044) ? Search for the state in the completeAddress string using strstr. Display the resulting string when the state is found. o NOTE: Remember, strstr returns a pointer. So there needs to be a pointer variable created to hold this pointer. ? Enter in the data exactly as it is shown on the test data screen below.

EXTRA CREDIT: Make a function named scStringManip that demonstrates the following concepts (NOTE: scString variables must be declared as strings not character arrays): ? Enter in two strings representing part numbers for a laptop. 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 representing a laptop make and model. Append the second string to the first string using += (appending). Display the final string. ? Enter in two strings representing a laptop dealer and a city. Concatenate the second string to the first string using + (concatenating). Display the final string. Do not forget to add any appropriate spaces. Exit the program when the user selects the appropriate menu option. 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. You can reuse the function that was written in CE-Strings for this purpose.

The Output must match the Screenshot below!!

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Page 4 of 9 ZOOM + K Welcome to the CMSY-141 C-String Manipulation Program String Lab Menu 1 Doing Math with Strings 2 Counting Elements 3 C-String Manipulation 4 String Class Manipulation 5 Exit Program Please enter menu choice: 7 ERROR: You must enter in a valid menu item. Please try again String Lab Menu 1 Doing Math with Strings 2 Counting Elements 3 C-String Manipulation 4 String Class Manipulation 15 Exit Program Please enter menu choice: All rights reservePage 5 of 9 ZOOM Menu Option 1: String Lab Menu 1 - Doing Math with Strings Counting Elements 3 - C-String Manipulation 4 String Class Manipulation 5 - Exit Program Please enter menu choice: 1 Please enter in the number of miles driven in a week: 450.7 Please enter the miles per gallon your vehicle gets: 11.2 ation prohibited. Please enter the cost of a gallon of diesel: 4.69 Please enter the number of packages delivered per week: 1218 The number of miles driven in a week was: 450.70 The amount of fuel used in a week was: 40.24 The cost of fuel for the week was: $188.73 The average packages delivered per day was : 174.00 The average miles driven per day was: 64.39 The average amount of fuel used per day was: 5.75 The average cost per day was: $26.96 The total revenue for the week was: $450.66 The company made $261.93 in deliveries this week. Do you wish to enter another value? (Y or N) g Please enter Y or N: n String Lab Menu 1 Doing Math with Strings 2 Counting Elements 3 C-String Manipulation 4 - String Class Manipulation 5 Exit Program Please enter menu choice:Page 6 > of 9 - ZOOM + Menu Option 2: Please enter menu choice: 2 The test string is: How R cStrings 4 U? They can B tricky 4 brand new C++ students! The number of alphas = 44 The number of digits = 2 The number of uppers = 7 The number of lowers = 37 The number of spaces = 13 The number of puncts = 4 String Lab Menu 1 - Doing Math with Strings 2 - Counting Elements 3 - C-String Manipulation 4 - String Class Manipulation 5 - Exit Program Please enter menu choice: served; UnaPage of 9 - ZOOM + Menu Option 3: String Lab Menu - Doing Math with Strings Counting Elements 3 C-String Manipulation 4 String Class Manipulation 5 Exit Program Please enter menu choice: 3 Enter in a string for test string: This is a test string. The length of This is a test string. is: 22 Enter in a first name: Megan Enter in a last name: Rapinoe After stropy, string completeName is Megan and the length is: 5 After strcat, string completeName is Megan Rapinoe and the length is: 13 Enter in a single character: @ Enter in the character number in the string holding the full name to replace: 4 After replacement, string completeName is Meg@n Rapinoe Enter in a city: Ellicott City Enter in a state: Maryland Enter in a zip: 21043 When doing a strncpy of city into completeAddress, max 10, you get: Ellicott C when first copied, city and completeAddress do not equal each other. The complete address is: Ellicott C, Maryland 21043 The lengeth of the address is: 26 characters. When looking for the string "Maryland" in name using strstr you get: Maryland 21043 String Lab Menu 1 - Doing Math with Strings Counting Elements C-String Manipulation String Class Manipulation Exit Program Please enter menu choice:Page of 9 - ZOOM Menu Option 4 (extra credit): String Lab Menu 1 Doing Math with Strings Counting Elements 3 C-String Manipulation 4 String Class Manipulation 5 Exit Program Please enter menu choice: 4 Please enter part number 1: abc 125 Please enter part number 2: abc 123 duplication prohibited. Enter in the laptop make: Hewlett Packard Enter in the laptop model: Envy 17.5 Enter in the store where the laptop was purchased: Best Buy Enter in the city: Columbia The part numbers are: abc 123 and abc 125 The laptop make and model is: Hewlett Packard Envy 17.5 The laptop was purchased at: Best Buy Columbia String Lab Menu 1 - Doing Math with Strings N Counting Elements 3 C-String Manipulation 4 String Class Manipulation 5 Exit Program Please enter menu choice:Menu Option 5: String Lab Menu 1 Doing Math with Strings Counting Elements C-String Manipulation String Class Manipulation Exit Program enter menu choice: 5 no you wish [(1 0in lho program (Y or N) {3 Please enter Y or N: n String Lab Menu , Doing Math with Strings , Counting Elements CeString Manipulation String Class Manipulation - Exit Program Please enter menu choice: 5 Do you wish to exit the program (Y or N) y Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions