Answer to Question #217271 in C++ for Hemambar

Question #217271
Write a c++ program to implement the following . Assuming that a text file named first.text contains some text written into it .write a function named vowelwords (), that reads the file.txt and creates a new file named second.txt ,to contain those words from the file first.txt which start the lowercase vowel (a,e,i,o,u).
1
Expert's answer
2021-07-15T00:11:22-0400
#include <iostream>


using namespace std;


int main()
{
    freopen("first.txt", "r", stdin);
    freopen("second.txt", "w", stdout);
    string s;
    getline(cin, 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';
        }
    }


    return 0;
}

Example:

first.txt:
hakuna azimjon matata euler

Output at second.txt:
azimjon
euler
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