67 257
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #72077 in C++ for Dhvani

Question #72077
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
/*
* main.cpp
*
*/

#include <iostream>
#include <fstream>
#include <string>

bool check_word(const std::string& word);

int main()
{
std::ifstream in("first_file.txt");
std::ofstream out("second_file.txt");
std::string word;

if (!in) {
std::cout << "File not found!\n";
return 0;
}

while (in >> word) {

if (check_word(word)) {
out << word << " ";
}
}

return 0;
}

bool check_word(const std::string& word)
{
const char c = std::tolower(word[0]);

return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}

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