Write a function chat accepts a pointer to a C-string as its argument. The function should count the number of vowels appearing in the sering and rerurn that number. Write another function that accepts a pointer to a C-string as its argument. This function should count the number of consonants appearing in the string and return that number. Demonstrate these two functions in a program rhar performs the following steps: I. The user is asked to enter a string. 2. The program displays the following menu: A) Count the number of vowels in rhe string 8) Count the number of consonants in the string C) Count both the vowels and consonants in the string D) Enter another string E) Exit the program 3. The program performs the operation selected by the user and repeats until the user selects E to exit the program.

Respuesta :

Answer:

Function contains into the code asked for:

  • Receives a string as an argument.  
  • count the number of vowels in the string and return that number.
  • receives a string as an argument.
  • count the number of consonants in the string and return that number.  

Explanation:

//Let's call libraries

#include <stdio.h>  

#include <conio.h>

//Start main

int main()

{

//*Declare functions for counting number of vowels and consonants

int vowels=0;      

int consonants=0;    

int all=0;    

//Output need information

//Ask user to input a string

printf("what do you want to count?\n");    

printf("1-the vowels.\n");      

printf("2-the consonants.\n");    

printf("3-all of the letters on a phrase.\n");      

printf("\n");      

printf("-> ");      

int a;    

a = getchar();

   switch (a)

   {          

//Ask user what function they want to run

case '1':

//Call the function needed to count the vowels  

            printf("Introduce a phrase: ");                  

char textoa[1001];                

scanf("%s", &textoa);

char *p;                  

p = textoa;                

while (*p != '\0')

               {

                     if (*p == 'a' || *p == 'e' || *p == 'i' || *p == 'o' || *p == 'u' || *p == 'A' || *p == 'E' || *p == 'I' || *p == 'O' || *p == 'U') vocales ++;

                     p++;

               }

               printf("there are %d vowels.", vowels);                  

break;            

case '2':

//Call the function needed to count the consonants

printf("Introduce a phrase: ");                

char textob[1001];                

scanf("%s", &textob);

p = textob;                

while (*p != '\0')

               {

                     if (*p == 'b' || *p == 'B' || *p == 'c' || *p == 'C' || *p == 'd' || *p == 'D' || *p == 'f' || *p == 'F' || *p == 'g' || *p == 'G' || *p == 'h' || *p == 'H' || *p == 'j' || *p == 'J' || *p == 'k' || *p == 'K' || *p == 'l' || *p == 'L' || *p == 'm' || *p == 'M' || *p == 'n' || *p == 'N' || *p == 'p' || *p == 'P' || *p == 'q' || *p == 'Q' || *p == 'r' || *p == 'R' || *p == 's' || *p == 'S' || *p == 't' || *p == 'T' || *p == 'v' || *p == 'V' || *p == 'w' || *p == 'W' || *p == 'x' || *p == 'X' || *p == 'y' || *p == 'Y' || *p == 'z' ||  

*p == 'Z') consonants ++;

                     p++;

               }

               printf("there are %d consonants.", consonants);                  

break;            

case '3':

printf("Introduce a phrase: ");                

char textoc[1001];                

scanf("%s",&textoc);

p = textoc;                

while (*p != '\0')

               {

                     if (*p == 'a' || *p == 'e' || *p == 'i' || *p == 'o' || *p == 'u' || *p == 'A' || *p == 'E' || *p == 'I' || *p == 'O' || *p == 'U' || *p == 'b' || *p == 'B' || *p == 'c' || *p == 'C' || *p == 'd' || *p == 'D' || *p == 'f' || *p == 'F' || *p == 'g' || *p == 'G' || *p == 'h' || *p == 'H' || *p == 'j' || *p == 'J' || *p == 'k' || *p == 'K' || *p == 'l' || *p == 'L' || *p == 'm' || *p == 'M' || *p == 'n' || *p == 'N' || *p == 'p' || *p == 'P' || *p == 'q' || *p == 'Q' || *p == 'r' || *p == 'R' || *p == 's' || *p == 'S' || *p == 't' || *p == 'T' || *p == 'v' || *p == 'V' || *p == 'w' || *p == 'W' || *p == 'x' || *p == 'X' || *p == 'y' || *p == 'Y' || *p == 'z' || *p == 'Z') all ++;

                     p++;

               }

               printf("there are %d letters on the phrase.", all);                 break;

   }     getch();

}