Write a c++ program that reads numbers from a file, stores the numbers in a dyna
ID: 3647621 • Letter: W
Question
Write a c++ program that reads numbers from a file, stores the numbers in a dynamically allocated array, and prints the numbers to the console. The program will not know how many numbers are in the file until the program runs; your software should count the number of numbers in the file and then dynamically allocate an array to store all the numbers. Print the numbers after you have read all of them from the file. Be sure to de-allocate the memory allocated to store the numbers.
This is what the program should display:
File opened OK.
There are 9 numbers in the file.
Memory allocated OK to store numbers.
The numbers in the array are: 1, 2, 3, 4, 5, 6, 77, 88, 99
Press any key to continue . . .
Explanation / Answer
#include #include #include//reading/writing to file #include// using namespace std; //uses input.Dat, //create() IS ONLY FOR TESTING PURPOSES void create(){ int test[9]={91,82,73,64,55,46,37,28}; ofstream dat; dat.open("Input.dat"); if(dat.is_open()){ coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.