| TMercier (7) | |||
|
Im am working on a program for class and I am a beginner C++ programmer. I am having trouble passing pointers and arrays. I am going to post the assignment and then post my code! Any help would be great!Thanks! Mr. Ed wants you to help him develop a program that has two string functions. The program that he has in mind will display a menu of two string functions: function one will scan for a specified character and substitute the specified character with another specified character; and function two will count the number of vowels ‘a’,’e’,’i',’o’,’u’ (upper and lower case) and non-vowels in the string and produce a short report. Declare an array of 80 characters in main(). Also, prompt the user for a string in main() and store the string into the array of characters that you have declared. Your main() program will display a menu by calling Function 1, based on the menu choice returned by Function 1, call the appropriate function based on user’s selection. For each function 2 and 3, prompt for user’s input in main() and pass those information as arguments into the function. Your program will allow Mr. Ed to perform as many string operations as he wishes. For the loop that controls the iteration, use the following condition: ‘U’ for continue and any other character to stop. For each user input, first check to see if the input is a lower case character (hint: use one of the standard string functions), if it is, call a standard string function to convert it to upper case before using it. This does not apply to character input for function 2 and 3 but it does apply to function 1. You are to write four functions: Function 1: (No argument, return a character value) This function will display the menu choice: A – Substitute Character, B – Count vowels. Call this function at the beginning of your program to display the menu. In the function, also, prompt for user’s choice, check for invalid input and loop until correct input is received. Return the choice back to main(). Function 2: (Accept three arguments: a pointer to an array, and two characters; return no value) This function will accept a pointer to an array containing the string, and two characters. It will use the pointer to traverse the string and scan for the first character and when it finds the character, it will substitute the first character with the second character. Prompt for the character to be scanned and the character to be substituted in main() and pass those into the function. Function 3: (Accept two arguments: an array and an integer; return an integer value) This function will accept an array containing the string and size of array. It will loop through the string and scan for the character: a,e,i,o, or u (upper and lower case). When it finds any of those characters, it will start keeping track of the number of times each character appeared in the string. It will also track non-vowels that are not a space or not a special character. In the function, output a report that lists the count for each vowel and all non-vowel alphabets. Also, sum up the count of all vowels and return the sum to main(). In main(), if the number is zero, output a message stating that “the string does not consist of any vowel”. Otherwise, display the total number of vowels found in the string. Bonus (2 points): Instead of passing in array and integer, pass in a pointer to the beginning of array and use that pointer to access the content of string. ** Do not use global variable, a minimum of 5 points will be taken off. ** Give your function meaningful name. Naming your function: Function 1, Func One, or Func A or anything similar will result in 3 points deduction for each function. Here is what I have so far.
| |||
|
|
|||
| Incubbus (675) | |
|
1. give your functions more meaningful names... such as show_menu e.g.... 2. toupper RETURNS the character as an uppercase letter 3. if the user enters a non-concatenated string such as something like this "hello world" your string will only contain "hello"... (use cin.getline instead)... 4.check for islower in the show_menu-function and return the character uppercase... 5. dont pass &array into your sub-function... read upon the array-chapters again... 6. done use endless if-else-control structures... use the switch-case... | |
|
|
|
| ubaidcybercrawler (4) | |||
try this code..
| |||
|
|
|||