PLz the code should be C++ Language I would rate 5 starts for every one who coul
ID: 3681596 • Letter: P
Question
PLz the code should be C++ Language I would rate 5 starts for every one who could help Thanks in advance !
You are required to read double values from a file named "values.txt". You don't know how many values will be there. Therefore, you will use a dynamically allocated array of doubles to store the values you are reading from the file. The initial size of the dynamically allocated array should be 10. Whenever you find that you need more space, increases the size of the array by 10. After reading all the values in the file print the count of the numbers, the sum of the numbers, and the average of the numbers on the prompt and in an output file called "output.txt". Hint: To increase the size of the array you will need to created a new dynamically allocated array with the new size, copy the old array in the new array, and delete the old array.Explanation / Answer
#include #include int main() { std::ifstream infile ("total.txt"); float num; float total = 0.0f; unsigned int count = 0; // While infile successfully extracted numbers from the stream while(infile >> num) { total += num; ++count; } // don't need the file anymore, close it infile.close(); // test to see if anything was read (prevent divide by 0) if (!count) { std::cerrRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.