Answer to Question #54108 in C++ for Guruwinder

Question #54108
Write a programming as per the following instruction:
(1) write a c++ code which reads the contents of a text file "first_file.txt"
(2) write a function named vowel_words () which will segregate the words starting with vowels from the "first_file.txt"
(3) 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-Iam an umbrella
1
Expert's answer
2015-08-14T02:52:14-0400
Answer

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

vector<string> vowel_words(vector<string>vs)
{
vector<string>res;
for (auto s:vs)
if (s[0]=='a'||s[0]=='A'||s[0]=='e'||s[0]=='E'||s[0]=='i'||s[0]=='I'||s[0]=='o'||s[0]=='O'||s[0]=='u'||s[0]=='U')
res.push_back(s);
return res;
}

int main()
{
string s1="first_file.txt",s2="second_file.txt";
ifstream in;
ofstream of;
vector<string>vs;
in.open(s1);
for (string s;in>>s;)
vs.push_back(s);
in.close();
of.open(s2);
for (auto s:vowel_words(vs))
of<<s<<" ";
of.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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS