#include <iostream.h>
#include <conio.h>
#include <string.h>#include<stdio.h>
void main()
{
clrscr();
char str[255] = " Hi \n Enter Strings \n Thanks ";
cout<< "\n Enter a String (~ to terminate ): ";
cin.getline(str, 255, '~');
/* Count no. of strings */
int no_f_strings = 0;
for(int i = 0; str[i] != '\0' ; i++)
if(str[i] == '\n')
no_f_strings ++;
/*Count total number of strings */
int tot_strings = 0;
for( i = 0 ; str[i] != '\0' ; i++)
{
/*space or new-line or fullstop means new word starts */
if( str[i] == ' ' || str [i] == '\n' || str[i] == '.')
{tot_strings++;
while(str[i] == ' ')
i++;}
if(str[i] == '\0')
i--;
}
tot_strings++; //for the last word in the string array
cout<< "\n The number of strings of each length : " << no_f_strings;
cout<<"\n The total number of strings (words) : " << tot_strings;
int len = strlen(str);
int ucas = 0, lcas = 0, fullst = 0;
for( i=0; str[i] != '\0' ; i++)
{
if(str[i]>='A' && str[i]<='Z')
ucas++;
if(str[i]>='a' && str[i]<='z')
lcas++;
if(str[i]=='.')
fullst++;
}
float avg_ucas = (float) (ucase / len);
float avg_lcas = (float) (lcas/len);
cout<< "\n The Mean of lowercase letters in strings of array = " << avg_lcas;
cout<< "\n The Mean of uppercase letters in strings of array = " << avg_ucas;
cout<< "\n The total number of terminating fullstop= " << fullst;
getch();
}
No comments:
Post a Comment