Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i wrote a code can you change this code so i can set the input and output file n

ID: 3659869 • Letter: I

Question

i wrote a code can you change this code so i can set the input and output file name i need to set the name of input file and output file but i dont know how to.. please help me ---------------------------------------------------------------------------------------------------------- example cout << "Please enter the name of the input file a:"; //Enter name of input file cin.getline(filename, SIZE); //Read input file inFile.open(filename); //Open input file cout << "Please enter the name of the output file a:"; //Enter name of output file cin.getline(filename,SIZE); //Read output file outFile.open(filename); //Open output file ---------------------------------------------------------------------------------------------------------- code that i wrote ------------------------------------------------------------------------------------------------------------------- #include #include #include #include #include using namespace std; enum Month {January,February,March,April,May,June,July,August,September,October,November,December}; void correctRainFall(double rainFall_before[],double rainFall_after[]); void printMonth(ofstream& outf,Month month); void printData(ofstream& outf,double rainFall_after,Month month); void sortToDescendingOrder(double rainFall_after[],Month month[]); int getNumOfLessThanOrEqual(double rainFall_after[],int criteria); int main() { double rainFall_before[12],rainFall_after[12]; double total_rainFall=0,avg_rainFall,highest_rainFall,lowest_rainFall; double criteria; Month month[12]; Month highest_month,lowest_month; int i; ifstream inFile; //input file stream ofstream outFile; //output file stam ifstream inf("in8.txt"); cout <<" "<< "SALES CALCULATIONS"<<endl; cout << ""<<endl; if (inf.good() == false) { cout << "File open failed!" << endl; return 1; } ofstream outf("outf8.txt"); if (outf.good() == false) { cout << "File open failed!" << endl; inf.close(); return 1; } cout << "Enter a value to count rainfalls" << endl; cout << "less than or equal to amount "; cin >> criteria; cout << endl; for (i=0; i<12; i++) { inf >> rainFall_before[i]; month[i] = (Month) i; } correctRainFall(rainFall_before,rainFall_after); outf << " YEARLY RAINFALL CALCULATIONS" << endl << endl; outf << " Month Rainfall(in inches)" << endl << endl; for (i=0; i<12; i++) { if (i == 0) { highest_rainFall = rainFall_after[i]; lowest_rainFall = rainFall_after[i]; highest_month = month[i]; lowest_month = month[i]; } else { if (highest_rainFall < rainFall_after[i]) { highest_rainFall = rainFall_after[i]; highest_month = month[i]; } if (lowest_rainFall > rainFall_after[i]) { lowest_rainFall = rainFall_after[i]; lowest_month = month[i]; } } total_rainFall += rainFall_after[i]; printData(outf,rainFall_after[i],month[i]); } avg_rainFall = total_rainFall / 12; sortToDescendingOrder(rainFall_after,month); outf << endl << "The yearly rainfall sorted from highest to lowest:" << endl << endl; outf << " Month Rainfall(in inches)" << endl << endl; for (i=0; i<12; i++) printData(outf,rainFall_after[i],month[i]); outf << endl << "The total rainfall for the year is " << total_rainFall << " inches." << endl; outf << "The average monthly rainfall is " << avg_rainFall << " inches." << endl; outf << "The highest rainfall of " << highest_rainFall << " occured in "; printMonth(outf,highest_month); outf << endl << "The lowest rainfall of " << lowest_rainFall << " occured in "; printMonth(outf,lowest_month); cout << "The number of months this year with rainfalls" << endl; cout << "less than or equal to " << fixed << setprecision(2) << criteria << " is "; cout << getNumOfLessThanOrEqual(rainFall_after,criteria); cout << "." << endl << endl; cout << "Processing complete" << endl; inf.close(); outf.close(); return 0; } void correctRainFall(double rainFall_before[],double rainFall_after[]) { int i; for (i=0; i<12; i++) { if (rainFall_before[i] < 0) { cout << "Rainfall can't be checked less than 0!" << endl; cout << "Correct value..." << endl << endl; rainFall_after[i] = 0; } else rainFall_after[i] = rainFall_before[i]; } } void printMonth(ofstream& outf,Month month) { switch (month) { case January : outf << "January"; break; case February : outf << "February"; break; case March : outf << "March"; break; case April : outf << "April"; break; case May : outf << "May"; break; case June : outf << "June"; break; case July : outf << "July"; break; case August : outf << "August"; break; case September : outf << "September"; break; case October : outf << "October"; break; case November : outf << "November"; break; case December : outf << "December"; } } void printData(ofstream& outf,double rainFall_after,Month month) { outf.width(16); outf << left; printMonth(outf,month); outf.width(13); outf << right << fixed << setprecision(2) << " " << rainFall_after << endl; } void sortToDescendingOrder(double rainFall_after[],Month month[]) { double temp1; int temp2; int i,j; for (i=0; i<11; i++) { for (j=i+1; j<12; j++) { if (rainFall_after[i] < rainFall_after[j]) { temp1 = rainFall_after[i]; rainFall_after[i] = rainFall_after[j]; rainFall_after[j] = temp1; temp2 = month[i]; month[i] = month[j]; month[j] = (Month) temp2; } } } } int getNumOfLessThanOrEqual(double rainFall_after[],int criteria) { int cnt=0; int i; for (i=0; i<12; i++) { if (rainFall_after[i] <= criteria) cnt++; } return cnt; }

Explanation / Answer

you want to set the input and output file name but your code not even near to that.... well your code is not properly intended so it was very reading it but then also i tried, all that i understood from your code is that its for the calculation of rainfall and sales of each month and to sort that..but not to set the input and output file name. here i am giving you a detailed example to set the input and output file name..try to follow it and enjoy :) Text file streams are those where we do not include the ios::binary flag in their opening mode. These files are designed to store text and thus all values that we input or output from/to them can suffer some formatting transformations, which do not necessarily correspond to their literal binary value. Data output operations on text files are performed in the same way we operated with cout: // writing on a text file #include #include using namespace std; int main () { ofstream myfile ("example.txt"); if (myfile.is_open()) { myfile