Question: Need help writing a program in C++ 1. OOP 3 file format. Classname should be myReader 2. Create a text file called data.txt with the
Need help writing a program in C++
1. OOP 3 file format. Classname should be myReader 2. Create a text file called data.txt with the following 3 numbers: 5 8 2 3. Write a method to read the numbers into an array. 4. Write a method to output the array to the terminal. 5. Now write a method to double the values of the array. 6. Now write a method to sort the array in ascending order using if statements. 7. Now write a method to calculate the total and the average. 8. Finally write a method to write the array, total and average to a file output.txt 9.
I have the 3 files format down, i just need help with the methods. *EDIT* All functions should be within the myReader class. I am struggling with the portion of doubling my array. this is what I have and it is only outputting the correct array before it is doubled.
void myReader::readData() { fstream inputFile; inputFile.open("data.txt"); // open data file
cout << "Output of array: "; for (int i = 0; i <= 2; i++) // i tracks row number { inputFile >> myNumbers[i]; cout << myNumbers[i] << " "; } cout << endl; inputFile.close(); }
void myReader::doubleArray() { cout << "Output of doubled array: " << endl; for (int j = 0; j <= i; j++) { myNumbersx[j] = 2 * myNumbers[j]; j++; cout << myNumbersx[j]; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
