Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Filename: textline.cpp (Note that the filenames are all lowercase ) Functions Wr

ID: 645461 • Letter: F

Question

Filename: textline.cpp (Note that the filenames are all lowercase)

Functions

Write the following functions. Each of these functions should have a single parameter -- accepting a c-style string as an argument (To understand how to pass c-strings to functions, remember that c-strings are just character arrays!). The function should only do what is specified (note that none of these functions do any output to the screen). ** Your functions should pass the c-string as a const function parameter wherever it is appropriate**:

Write a function that counts and returns the number of vowels in the string. (For the purposes of this exercise, we are talking about the standard 5 vowels -- A, E, I, O, U).

Write a function that counts and returns the number of consonants in the string. This function should call another function you write for help. AVOID having tons of statements that check for all the consonants, as there are a LOT.

Write a function that converts the string to all lowercase, and returns no value.

Write a function that converts the string to all uppercase, and returns no value.

You can name the above functions however you'd like. It's up to you to figure out what parameters the functions should take in.

Menu program

Write a main program that performs the following steps:

Prompt the user to enter a string, and let them type it in. This could be an entire sentence, with the newline indicating the end of the string. You may assume the string will be no more than 100 characters, so declare your c-string array accordingly.

Display the following menu:

Enter a loop, allowing the user to type in a menu choice each time. Loop should continue until the user enters the command to exit. Upper and lowercase letters should be allowed for the menu choices.

When the A or B commands are entered (counting vowels or consonants), call the corresponding function, then print the result

When the C or D commands are chosen, just call the appropriate function to convert the string. Do not do any output from main on these commands.

When E is chosen, print the contents of the stored string.

When F is chosen, allow a new string to be typed -- this will replace the previous one.

The menu should only be displayed once at the start, and then again whenever the M option is selected

Explanation / Answer

//textline.cpp file

#include
#include
#include
#include
#include

int countVowels(char str[100]);
int countConso(char str[100]);
void toUpper(char *str);
void toLower(char str[100]);


int countVowels(char str[100])
{ int v=0;
for(int i=0;str[i]!='';i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e' || str[i]=='E' || str[i]=='i' || str[i]=='I' || str[i]=='o' || str[i]== 'O' || str[i]=='u' || str[i]=='U')
v++;
}
return v;
}

int countConso(char str[100])
{ int c=0;
for(int i=0;str[i]!='';i++)
{
if(str[i]!=' ' && str[i]!='a' && str[i]!='A' && str[i]!='e' && str[i]!='E' && str[i]!='i' && str[i]!='I' && str[i]!='o' && str[i]!= 'O' && str[i]!='u' && str[i]!='U')
c++;
}
return c;
}

void toUpper(char str[100])
{ char st[100];int j=0;
for(int i=0;str[i]!='';i++)
{if(str[i]>=97 && str[i]<=122)

st[j++]=str[i]-32;
else
st[j++]=str[i];
}
st[j]='';
//cout<

strcpy(str,st);
// cout< }

void toLower(char str[100])
{
char st[100];int j=0;
for(int i=0;str[i]!='';i++)
{if(str[i]>=65 && str[i]<=90)

st[j++]=str[i]+32;
else
st[j++]=str[i];
}
st[j]='';
//cout<

strcpy(str,st);
// cout< }

void main()
{
char x;
char str[100];
int v,c;
clrscr();
cout<<"Enter your string";
gets(str);
do{
L:
cout<<" A) Count the number of vowels in the String B) Count the number of consonants in the String C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current String F) Enter another String M) Display this menu X) Exit the Program Enter your choice: ";
cin>>x;
switch(x)
{
case 'A':
case 'a':
   v=countVowels(str);
   cout<<"Number of Vowels in the String is :"<    break;
case 'B':
case 'b':
       c=countConso(str);
       cout<<"Number of Consonants in the String is :"<        break;
case 'C':
case 'c':
       toUpper(str);
       break;
case 'D':
case 'd':
       toLower(str);
       break;
case 'E':
case 'e':
   cout<    break;
case 'F':
case 'f':
   cout<<"Enter the new String";
   gets(str);
   break;
case 'M':
case 'm':
   goto L;
   break;
case 'X':
case 'x':
   exit(0);
}
}while(x!='X' || x!='x');
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote