Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

rEAD THE FOLLOWING CAREFULLY TO GET FULL VALUE FROM THE PRACTICE. 1. Download the program reWriteThis.cpp. You will use the code in reWriteThis.cpp to rewrite

rEAD THE FOLLOWING CAREFULLY TO GET FULL VALUE FROM THE PRACTICE. 1. Download the program reWriteThis.cpp. You will use the code in reWriteThis.cpp to rewrite the processes into functions by performing the following: 2. Create int function(s) for opening the input and output files. These opens may be in the same function. This function MUST RETURN an int value to indicate the success or failure of the open(s). Test this value and take appropriate action after the function call. This function MUST have the following parameters, in any order: a. input file stream b. output file stream 3. Create a void function to read the data file. This function MUST have the following parameters, in any order: a. input file stream b. OUT parameter to return the total of all values c. OUT parameter to return the number of values read 4. Create a value returning function (I'm leaving it up to YOU to choose the correct type) to return the avg of the numbers read. This function MUST have the following parameters, in any order: a. IN parameter to pass in the total of the numbers read b. IN parameter to pass in the number of values read 5. Create void function(s) for closing the input and output files. These closes may be in the same function. This function MUST have the following parameters, in any order. a. input file stream b. output file stream 6. Move the global variables (defined before main in reWriteThis.cpp) and place them within the appropriate functions. Some will be needed with the related function, some will still be needed in main. 7. FOR PRACTICE, do NOT use the same variable names as ARGUMENTS in the function call and PARAMETERS in the function heading definition. 8. You MUST use function prototypes (before main) and you MUST define your functions AFTER main. 9. The console (cout) and file writes remain in main. 10. Either create a file named inFile.txt that contains: a. The number of values to add b. A number of integer values matching the number read in a. OR c. Download and use attached inFile.txt If you like to include the following line of code: system("pause"); You MAY need to: #include 

Here is the rewritecpp:

#include  #include  #include  #include // for system("pause") using namespace std; // global variables; are used anywhere within the program without re-definition string ifileName, ofileName; ifstream inData; ofstream outData; int numValues, total, i, num; float avg; int main () { ifileName = "inFile.txt"; inData.open(ifileName.c_str()); if (!inData) { cout << "Error opening file: " << ifileName << ". Exiting program..." << endl; return 0; } inData >> numValues; for (i = 0; i < numValues; i++) { inData >> num; total += num; } avg = float(total) / float(numValues); ofileName = "outFile.txt"; outData.open(ofileName.c_str()); if (!outData) { cout << "Error opening file: " << ofileName << ". Exiting program..." << endl; return 0; } cout << "You entered " << numValues << " numbers totaling " << total << " with a average of " << avg << endl; outData << "You entered " << numValues << " numbers totaling " << total << " with a average of " << avg << endl; inData.close(); outData.close(); system("pause"); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

Find: a. (8x 3 6x 2 + 5)dx b. (5x + 2) x 1/2 dx

Answered: 1 week ago