Write a C++ program that inputs a string of maximum length 50 named test. The program then count and print the following with appropriate format.
i) Count number of characters in test string.
ii) Count number of words in test string.
iii) Count number of sentences in test string.
iv) Count number of vowels in test string.
v) Count all the occurrence of letter ‘a’ in test string.
#include<stdio.h>
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
int main()
{
char test[50];
cout << "Enter a String: ";
gets(test);
cout << test;
int y=strlen(test);
int count1=0, count2=0, count3=0, count4=0;
for(int j=0; j<50; j++)
{
if(test[j]==' ')
count1++;
if(test[j]=='.')
count2++;
if(test[j]=='a')
count3++;
if((test[j]=='a')||(test[j]=='A')||(test[j]=='e')||(test[j]=='E')||(test[j]=='i')||(test[j]=='I')||(test[j]=='o')||(test[j]=='O')||(test[j]=='u')||(test[j]=='U'))
count4++;
}
cout << "\n\nNumber of Characters in Test String are : " << y;
cout << "\n\nNumber of Words in Test String are : " << ++count1;
cout <<"\n\nNumber of Sentences in Test String are : " << count2;
cout << "\n\nNumber of Vowels in Test String are : " << count4;
cout << "\n\nNumber of Occurrence of Letter 'a' in Test String are : " << count3;
getche();
return 0;
}
No comments:
Post a Comment