Answer to Question #190780 in C++ for nikhil

Question #190780

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 with a lowercase vowel (i.e., with 'a', 'e', 'i', 'o', 'u'). 

For example, if the file FIRST.TXT contains Carry umbrella and overcoat when it rains Then the file SECOND.TXT shall contain umbrella and overcoat it


1
Expert's answer
2021-05-09T05:36:54-0400
#include <fstream>
#include <string>
#include <cctype>
using namespace std;

void vowelwords()
{
    ifstream ifs("FIRST.TXT");
    ofstream ofs("SECOND.TXT");
    string word;

    while (ifs) {
        ifs >> word;
        int ch = tolower(word[0]);
        if (ch == 'a' || ch == 'e' || ch == 'i' ||
            ch == 'o' || ch == 'u') {
            ofs << word << ' ';
        }
    }
}

int main() {
    vowelwords();
}

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