Answer to Question #215975 in C++ for Hemambar

Question #215975
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-11T14:35:50-0400
#include <iostream>
#include <string>


using namespace std;


int main () {
	string inputString="";
	string outputString="";
	cout<<"Enter string: ";
	getline(cin,inputString);


	int firstIndex=-1;
	for (int i = 0;i< inputString.length(); ++i) {
		if (tolower(inputString[i]) == 'a' || 
			tolower(inputString[i]) == 'e' || 
			tolower(inputString[i]) == 'i' ||
			tolower(inputString[i]) == 'o' || 
			tolower(inputString[i]) == 'u') {
				firstIndex=i;
				break;
		}
	}


	if(firstIndex!=-1){
		for (int i = firstIndex;i< inputString.length(); ++i) {
			outputString+=inputString[i];
		}
		for (int i =0;i<firstIndex; ++i) {
			outputString+=inputString[i];
		}
	}
	cout<<"\nUpdated string: "<<outputString<<"\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