//what i needed to do was to read the file number.txt, and check for frequencies by using arrays.
Code:
#include<iostream>
#include<fstream>
#include<ctime>
#include<cstdlib>
using namespace std;
int MAX=20;//Global variable
void createDataFile();//Function prototype
int main(){
//Call function;
createDataFile();
//Declare Variables
int a(0);
int read;
ifstream dataFile("numbers.txt");//open stream
if(dataFile.fail()) //check if stream failed to open
cout<<"In fail state"<<endl;
//Create array
int freq_array[20]={0};
for(int i=MAX-1; i>=0; i--)
cout << i << ": " << freq_array[i] << endl;
dataFile.get(read);
}
/*
This function generates a file called numbers.txt with random
numbers from 0-MAX
*/
void createDataFile(){
//dataFile is the file handle for “numbers.txt”
ofstream dataFile("numbers.txt");
//Seed random number generator rand() function
srand(time(0));
//Write 150 random number to the file numbers.txt
for (int i = 0; i<150; i++)
dataFile << (rand() % MAX) <<'\n';
}
Comment