Answer to Question #215982 in C++ for Hemambar

Question #215982
given a string "programming" and find the first occurrence of the vowel and move the sequence of consonants preceding the first vowel to the end of the string
Sample input:
Str[]=programming
Sample output:
Updated string=ogrammingpr
1
Expert's answer
2021-07-12T17:18:40-0400
#include <iostream>
#include <string>




using namespace std;


int getIndex(string message){
	for (int i = 0;i< message.length(); ++i) {
		if (tolower(message[i]) == 'a' || 
			tolower(message[i]) == 'e' || 
			tolower(message[i]) == 'i' ||
			tolower(message[i]) == 'o' || 
			tolower(message[i]) == 'u') {
				return i;
		}
	}
	return -1;
}


int main () {
	string message="";
	string newMessage="";
	cout<<"Enter string: ";
	getline(cin,message);
	int index=getIndex(message);
	if(index!=-1){
		for (int i = index;i< message.length(); ++i) {
			newMessage+=message[i];
		}
		for (int i =0;i<index; ++i) {
			newMessage+=message[i];
		}
	}
	cout<<"\nUpdated string: "<<newMessage<<"\n\n";


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS