64 757
Assignments Done
99,3%
Successfully Done
In September 2018

Answer to Question #53797 in C++ for Ankush

Question #53797
Write a C++ program as per the following instructions:
(i) Write a C++ code which reads the contents of a text file “first_file.txt”
(ii) Write a function named vowel_words() which will segregate the words starting with vowels
from the “first_file.txt”
(iii) Write a C++ code which writes the resultant words to the output file, “second_file.txt”.
Example: Content of first_file – “I am going to buy an umbrella”
Output in second_file.txt – I am an umbrella
Expert's answer

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void segregateWords(string str);

void main()
{
ifstream inFile;
string words;

inFile.open("first_file.txt");

while (inFile >> words)
{
segregateWords(words);
}//end while loop

inFile.close();

return;
}


void segregateWords(string str)
{

char vowels[10] = { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
ofstream outFile;
outFile.open("second_file.txt", ios::app);

for (int j = 0; j < 10; j++)
{
if (str.at(0) == vowels[j])
{
outFile << str + " ";
break;
}
}

outFile.close();

}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions