can anyone give me a program in c++ to accept a scentance and print words without vowels.
C++ program to print words without vowels?
The STL is your friend.
#include %26lt;iostream%26gt;
#include %26lt;algorithm%26gt;
using namespace std;
bool isVowel(char c)
{
c = ::toupper(c);
if ((c == 'A')
|| (c == 'E')
|| (c == 'I')
|| (c == 'O')
|| (c == 'U'))
{
return(true);
}
else
{
return(false);
}
}
int main ()
{
string str;
cout %26lt;%26lt; " Enter sentence: ";
getline(cin, str);
string::iterator e = remove_if(str.begin(), str.end(), isVowel);
str.erase(e, str.end());
cout %26lt;%26lt; "Changed sentence: " %26lt;%26lt; str %26lt;%26lt; endl;
return 0;
}
Reply:here's some psuedo-code:
void main {
char[] text
input text
text = remove('a',text)
text = remove('e',text)
text = remove('i',text)
text = remove('o',text)
remove('u',text)
remove('y',text)
output text
}
char [] remove(char x, char[] text) {
int result = find(x, text)
do {
//copy all characters before result text
//copy all characters after result one position to the left
//so you overwrite the offending character
result = find(x, text)
}
while result != -1
return text
}
find(char x, char[] text)
{
// this may already be implemented in C++, not sure
//look for x in text
//return -1 if not found
//if found, return index of char[] where it is found
}
Reply:here is the program that reads the word,
count its lenght(b),
compare the every letter(a[i]) with every letter of array of vowels[bi],
if vowel is found then over write the whole array from the vowel position by the help of for loop(k),
and decrements the size of array by 1(b=b-1),
and prints the word again without vowels;
Reply:string UserInput = ""
get UserInput .
UserInput = UserInput .replace("a","")
UserInput = UserInput .replace("e","")
UserInput = UserInput .replace("i","")
UserInput = UserInput .replace("u","")
UserInput = UserInput .replace("o","")
UserInput = UserInput .replace("A","")
UserInput = UserInput .replace("E","")
UserInput = UserInput .replace("I","")
UserInput = UserInput .replace("U","")
UserInput = UserInput .replace("O","")
print UserInput
flowers gifts
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment