Answer to Question #316006 in C++ for Azad

Question #316006

Write a program in C++ that reads some text entered through the keyboard till the end of 

file (eof) character is entered. The words in the text are written to different text files as per 

the following conditions:

• The words beginning with any of the lowercase vowels (a, e, i, o, u) are written to 

a file fileV.txt.

• The words beginning with a digit (0 – 9) are written to a file fileD.txt.

• All other words are written to a file fileRest.txt.


1
Expert's answer
2022-03-22T19:08:08-0400
#include <iostream>
#include <fstream>
#include <string>
using namespace std;


int main() {
    string word;
    ofstream fvowels("fileV.txt");
    ofstream fdigit("fileD.txt");
    ofstream frest("fileRest.txt");


    while (cin >> word) {
        if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' ||
            word[0] == 'o' || word[0] == 'u') {
                fvowels << word << endl;
        }
        else if (word[0] >= '0' && word[0] <= '9') {
            fdigit << word << endl;
        }
        else {
            frest << word << endl;
        }
    }
    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