Write a c++ program with comments that prompts the user to input a string. The p
ID: 3680377 • Letter: W
Question
Write a c++ program with comments that prompts the user to input a string. The program then to remove all the vowels from the string. For example, if str = "There", then after removing all the vowels, str = "Thr". After removing all the vowels, output the string. Your program must contain a function that returns the a string with the vowels removed and a function to returns whether or not a single character is a vowel. Hint: The substr function might be useful, but you may find a simple solution that instead uses string concatenation and the array subscript operator.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char str[20];
int len, i, j;
cout<<"Enter a string : ";
gets(str);
len=strlen(str);
removevowel(str,len);//function to remove all vowels in //string
cout<<" String after deletion of vowels"<<str;
getch();
}
void removevowel(char str[],int len)
{
int i,j;
for(i=0; i<len; i++)
{
//to check whether character is vowel or not
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')
{
for(j=i; j<len;j++) //removal of character if it is vowel
{
str[j]=str[j+1];
} len--;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.