Answer to Question #218002 in C++ for Hemambar

Question #218002

Write a c++ program to implement the following . Assuming that a text file named first.txt contains some text written into it .write a function named vowelwords(), that reads the file first.txt and creates a new file named second.txt ,to contain only those words from the file first.txt which start the lowercase vowel (a,e,i,o,u).



1
Expert's answer
2021-07-17T01:30:16-0400
#include <iostream>


using namespace std;


void vowelwords(string s) {
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == ' ' &&
            (s[i + 1] == 'a' || s[i + 1] == 'e' || s[i + 1] == 'i' || s[i + 1] == 'o' || s[i + 1] == 'u')) {
            int j = i + 1;
            bool test = true;
            while (test) {
                cout << s[j];
                j++;
                if (j == s.size() || s[j] == ' ') test = false;
            }
            cout << '\n';
        }
    }
}


int main() {
    freopen("first.txt", "r", stdin);
    freopen("second.txt", "w", stdout);
    string s;
    getline(cin, s);
    
    vowelwords(s);


    return 0;
}

Example:

first.txt
hakuna matata azimjon archimedes

second.txt
azimjon
archimedes

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