C++ EXPERT REQUESTED. I just want take provided input and create output.txt files instead of hardcoding input.txt and output.txt by name in order to create an infinite amount of output.txt files as needed and take infinitely input.txt files as needed. I have implemented most of the code already just need help wrapping things up. I have attached the question and my already implemented code. As you can see I need help with just two things to wrap up the code. Instead of typing fileread.open("input.txt") and filewrite.open("output.txt"), (basically lines 11/12) I want it to instead be taking in its own infinitely as many times input, so instead of "input".txt it might say argv[1] and argv[2] respectively (assuming thats the proper solution for this string text file) as I will be given input files and the code is meant to create its own output.txt files instead infinitely. If any more information is needed please let me know. I was told be live chat to submit this here and a C++ expert can promptly resolve and fix this code for me. Thank you! This is just for practice and non-graded knowledge question. THE CODE IS WRITTEN BELOW #include #include #include #include using namespace std; int main(int argc, char *argv[]) { ifstream fileread; ofstream filewrite; int count1=0,count2=0,count3=0,count4=0,count5=0; fileread.open("input.txt"); filewrite.open("output.txt"); if(fileread.is_open()){ string sentence; while(fileread>> sentence){ for_each(sentence.begin(),sentence.end(),[](char &c) { c = ::tolower(c); }); if(sentence=="a") count1++; else if(sentence=="an") count2++; else if(sentence=="the") count3++; else if(sentence=="it") count4++; else if(sentence=="there") count5++; } filewrite<<"A: "<
C++ EXPERT REQUESTED. I just want take provided input and create output.txt files instead of hardcoding input.txt and output.txt by name in order to create an infinite amount of output.txt files as needed and take infinitely input.txt files as needed. I have implemented most of the code already just need help wrapping things up. I have attached the question and my already implemented code. As you can see I need help with just two things to wrap up the code. Instead of typing fileread.open("input.txt") and filewrite.open("output.txt"), (basically lines 11/12) I want it to instead be taking in its own infinitely as many times input, so instead of "input".txt it might say argv[1] and argv[2] respectively (assuming thats the proper solution for this string text file) as I will be given input files and the code is meant to create its own output.txt files instead infinitely.
If any more information is needed please let me know. I was told be live chat to submit this here and a C++ expert can promptly resolve and fix this code for me. Thank you! This is just for practice and non-graded knowledge question. THE CODE IS WRITTEN BELOW
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[]) {
ifstream fileread;
ofstream filewrite;
int count1=0,count2=0,count3=0,count4=0,count5=0;
fileread.open("input.txt");
filewrite.open("output.txt");
if(fileread.is_open()){
string sentence;
while(fileread>> sentence){
for_each(sentence.begin(),sentence.end(),[](char &c)
{
c = ::tolower(c);
});
if(sentence=="a")
count1++;
else if(sentence=="an")
count2++;
else if(sentence=="the")
count3++;
else if(sentence=="it")
count4++;
else if(sentence=="there")
count5++;
}
filewrite<<"A: "<<count1<<endl<<"An: "<<count2<<endl<<"The: "<<count3<<endl<<"It: "<<count4<<endl<<"There: "<<count5;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images