Im am working on a program for class and I am a beginner C++ programmer. i am almost finished but keep getting errors about illegal use of local functions?
I am going to post the assignment and then post my output! 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.
char Func_menu(); //Menu Function prototype //
void swap_Chars (char, char, char);
int count_Char (int[], int);
int main()
{
char menu_choice; //user input from menu function
char oldchar; //entry for character to be scanned
char newchar; //user entry to replace old character
char string_array[80]; //array to hold string characters
cout << "\n\n\n\nWelcome Mr. Ed!"
"\n---------------------------"
"\nPlease Input A String:\n";
cin >> string_array;
Func_menu(); //calls menu function to display user menu
menu_choice = Func_menu(); //sets menuchoice to entry gathered from user
switch(menu_choice) // in menu function
{
case 'a':
case 'A':
cout << "\n\n\n\nSubstitute Character" //asks user for substitution entries
"\n---------------------------"
"\nPlease Enter The Character To Be Scanned:";
cin >> oldchar;
cout << "\nPlease Enter The Character To Be Substituted:";
cin >> newchar;
break;
case 'b':
case 'B':
cout << "\n\nCharacter Counter"<<endl; //asks user which character to count
cout << "\nString Editor"
"\n---------------------------"
"\nPlease Select from the Options Below:\n"
"\n---------------------------"
"\n(A)Substitute Character"
"\n(B)Count Character"
"\nPlease Make a Selection Using Letters in Parenthesis:\n\n";
cin >> selection;
switch(selection) //switch loop to check for valid entry, loop until valid entry recieved
{
case 'a':
case 'A':
return selection;
break;
case 'b':
case 'B':
return selection;
break;
default: //INVALID ENTRIES ON MAIN MENU
cout << "\nInvalid Entry, Please Try Again\n";
Func_menu();
break;
}
void swap_Chars(char* str, char u1, char u2)
{
for (int i=0;i<80;i++) if (str[i]==u1) str[i]=u2;
}
int count_Char(char* str, char u)
{
int count=0;
for (int i=0;i<80;i++)
if (str[i]==u) {
count++;
if (count<=9) str[i]=count+48;
}
return count;
}
to be honest im not sure? Ive have been fallowing my book and it has many different options. So I declared the fucntion incorrectly? I also think I need to call it in the main!. Any advice