Question 8: Write a C++ program that accepts a string as its input. Your program should count the number of vowels appearing in the string and return that number i.e. total count of all vowels.
Question 8: Write a C++ program that accepts a string as its input. Your program should count the number of vowels appearing in the string and return that number i.e. total count of all vowels.
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
cout<<"This programme will count the number of vowels in the string without case sensitivity!!\n\n";
char str [50]; // To hold the string contents.
cout<<"Enter the string: ";
cin.getline(str,50); // Inputting the string with the spaces.
int count = 0; // To store the count of number of vowels.
for(int i = 0; str[i]!='\0';i++) // Loop for count the the vowels.
{
if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'||
str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u' ) // condition to check the vowels in the strung.
count ++; // counter for counting the number of vowels
}
cout<<"\nThe Number of Vowels are: "<<count<<endl;
return 0;
}
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
cout<<"This programme will count the number of vowels in the string without case sensitivity!!\n\n";
char str [50]; // To hold the string contents.
cout<<"Enter the string: ";
cin.getline(str,50); // Inputting the string with the spaces.
int count = 0; // To store the count of number of vowels.
for(int i = 0; str[i]!='\0';i++) // Loop for count the the vowels.
{
if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'||
str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u' ) // condition to check the vowels in the strung.
count ++; // counter for counting the number of vowels
}
cout<<"\nThe Number of Vowels are: "<<count<<endl;
return 0;
}
No comments: