0
hi, i have some doubt in following program i need to change the vowels into # symbol in first string and consonants into $ symbo
#include <iostream> #include <string> using namespace std; int main() { string a,b,c; getline(cin,a); getline(cin,b); getline(cin,c); for(int i=0;i<a.size();i++) { if(a[i]=='a'||'e'||'i'||'o'||'u') { cout<<"#"; } else { cout<<a[i]; } } for(int i=0;i<b.size();i++) { if(b[i]!='a'||'e'||'i'||'o'||'u') { cout<<"
quot;; } else { cout<<b[i]; } } for(int i = 0; i <c.size(); i++) { c[i] = toupper(c[i]); cout<<c[i]; } return 0; }2 ответов
+ 6
Here I have modified the Mohamed ELomari's code
#include <iostream>
#include <string>
using namespace std;
bool VowelOrConsonant(char alpha) {
if(alpha == 'a' || alpha == 'e' || alpha == 'i' || alpha == 'o' || alpha == 'u')
return true;
else
return false;
}
int main() {
string a,b,c;
getline(cin,a);
getline(cin,b);
getline(cin,c);
for(int i=0;i<a.size();i++) {
if(VowelOrConsonant(a[i]))
cout << "#";
else
cout << a[i];
}
cout << endl;
for(int i=0;i<b.size();i++) {
if(!VowelOrConsonant(b[i]))
cout << "quot;;
else
cout << b[i];
}
cout << endl;
for(int i = 0; i <c.size(); i++)
{
c[i] = toupper(c[i]);
cout<<c[i];
}
return 0;
}
+ 5
Change a[i]=='a'||'e'...
to (a[i]=='a')||(a[i]=='e')
Same for second if