C++ Program To Find the Missing Values for a, e, i, o, u In the String.
Anonymous in /c/coding_help
761
report
Are you looking for a C++ program to find the missing values for a, e, i, o, u In the String?<br><br>Here is a sample C++ program to find the missing values for a, e, i, o, u In the String. This program will handle the Uppercase input also, We will convert the Upper case into Lowercase and find the missing values. Please refer to the below code for more details.<br><br>```cpp<br>#include <iostream><br>#include <string><br>#include <vector><br>#include <algorithm><br><br>void findMissingValuesInString(std::string s) {<br> char vowels[] = {'a', 'e', 'i', 'o', 'u'};<br> int sizes = sizeof(vowels) / sizeof(vowels[0]);<br><br> for (int i = 0; i < s.size(); i++) {<br> s[i] = tolower(s[i]);<br> }<br><br> std::sort(s.begin(), s.end());<br><br> for (int i = 0; i < s.size() - 1; i++) {<br> for (int j = 0; j < sizes; j++) {<br> if (s[i] == vowels[j] && s[i + 1] == vowels[j]) {<br> std::cout << "Matched: " << s[i] << std::endl;<br> }<br> if (s[i] == vowels[j] && s[i + 1] != vowels[j]) {<br> std::cout << "Missing: " << vowels[j] << std::endl;<br> }<br> }<br> }<br>}<br><br>// test the function<br>int main() {<br> std::string str = "IaieeOoeeuoua";<br> findMissingValuesInString(str);<br> return 0;<br>}<br><br>```<br><br>In the above code, we had used the C++ **for loop** to iterate the string and check the missing characters in the string. After we found the missing characters we will print it.<br><br>Please refer to the below for removing the duplicate vowels in the string.<br><br>```cpp<br>#include <iostream><br>#include <string><br>#include <vector><br>#include <algorithm><br><br>void findMissingValuesInString(std::string s) {<br> char vowels[] = {'a', 'e', 'i', 'o', 'u'};<br> int sizes = sizeof(vowels) / sizeof(vowels[0]);<br><br> for (int i = 0; i < s.size(); i++) {<br> s[i] = tolower(s[i]);<br> }<br><br> std::sort(s.begin(), s.end());<br><br> int count = 0;<br> std::string res = "";<br><br> for (int i = 0; i < s.size() - 1; i++) {<br> if (s[i] == s[i + 1]) {<br> count = count + 1;<br> } else {<br> res = res + s[i];<br> count = 0;<br> }<br> }<br><br> std::cout << "String after removing of vowels: " << res << std::endl;<br><br> for (int i = 0; i < res.size() - 1; i++) {<br> for (int j = 0; j < sizes; j++) {<br> if (res[i] == vowels[j] && res[i + 1] == vowels[j]) {<br> std::cout << "Matched: " << res[i] << std::endl;<br> }<br> if (res[i] == vowels[j] && res[i + 1] != vowels[j]) {<br> std::cout << "Missing: " << vowels[j] << std::endl;<br> }<br> }<br> }<br>}<br><br>// test the function<br>int main() {<br> std::string str = "IaieeOoeeuoua";<br> findMissingValuesInString(str);<br> return 0;<br>}<br><br>```<br><br>Refer to the above C++ program for removing the duplicate vowels in the string and finding the missing values in the string. Please let me know if you have any other questions.
Comments (15) 29640 👁️