Answer to Question #52975 in C++ for Blackhippie

Question #52975
Write a program that reads in a string provided the user. Return the following statistics about the string:
• Length
• Number of vowels
• Number of lower case characters
• Number of upper case characters
• Number of numerals
• Number of other symbols

Thanks in advance
1
Expert's answer
2015-06-05T04:33:44-0400
/* Answer on Question#52975 - Subject - Programming, C++ */
#include <stdio.h>
#include <iostream>
int main()
{
    char str[256]; /* string bufer*/
    int len = 0; int vow = 0; int upp = 0; int low = 0; int digit = 0;
    int other = 0;
    printf("Enter string: ");
    scanf("%s", str); /*read string*/
    int i = 0; /*index*/
     while ( str[i] != '\0' ) /*go through string while char is not 0*/
     {
       if ( (tolower(str[i]) == 'a') || (tolower(str[i]) == 'e') || (tolower(str[i]) == 'i') || (tolower(str[i]) == 'o') || (tolower(str[i]) == 'u'))
          vow++;  /* vowels*/
       if ( isupper(str[i]) != 0 )
          upp++; /*uppercase*/
       else low++; /*lowercase*/
       if ( isdigit(str[i]) != 0 )
          digit++; /*digits*/
       if ( ((tolower(str[i]) < 'a') || (tolower(str[i]) > 'z')) && (isdigit(str[i]) == 0)  )
          other++; /*other symbols*/
       i++; 
       len++; /*length of the string*/
     } 
     /*statistic output*/
    printf("length: %d\n", len);   
    printf("number of vowels: %d\n", vow);
    printf("number of uppers: %d\n", upp);
    printf("number of lowers: %d\n", low);
    printf("number of digits: %d\n", digit);
    printf("number of other: %d\n", other);
    
    system("PAUSE"); /*sys delay*/
    return 0;
    
}
     
     
     

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS