Arrays and reading from a file USE C to write a program that
Arrays and reading from a file
USE C++ to write a program that will read a file containing floating point numbers, store the numbers into an array, count how many numbers were in the file, then output the numbers in reverse order.
The program should only use one array and that array should not be changed after the numbers have been read.
You should assume that the file does not contain more than 100 floating point numbers. The file name is 4-7Array.txt.
the number example like
108.2444
 67.8807
 108.5296
 107.8583
 84.2688
 100.0140
 67.0943
.........
Solution
#include <iostream>
 #include <fstream>
 using namespace std;
int main()
 {
   
     //open file for reading
    fstream myfile(\"4-7Array.txt\");
    //declare variables
     float tmp;
     int size=-1;
     //array to hold nos
     float nos[100];
     //read through EOF
     while (myfile >> tmp)
     {
         //increment the count and assign value to array
         size++;
         nos[size]=tmp;
     }
     //close file
    myfile.close();
 
    //loop through array and display
    for(int i=size;i>=0;i--)
    {
        cout<<nos[i]<<endl;
    }
    return 0;
 }

