1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
.
.
.
cout << int FREQ(int NELM[]); /*tried to call on function immediatley
below to no avail, tried with "int" without "int", technically this function
should return an array. */
.
.
int FREQ(int array[]) /* Not sure how to call on this function either,
because technically it does need input but it prompts the user for it*/
return 0;
.
.
int FREQ(int array[])
/*Not sure if this is the proper way to initialize this
function, it will need an array, the actual array name is NELM[], it is a
2D array created in the main function by pulling data from a file the user
inputs. therefore the exact number of elements isn't known.*/
{
int freq1=0,freq2=0,freq3=0,freq4=0,freq5=0,freq6=0,freq7=0;
int freq[7]={freq1, freq2, freq3, freq4, freq5, freq6, freq7};
for(int i = 0; array[i] != '\0'; i++)
if (array[i]=1)
freq1+=1;
else if (array[i]=2)
freq2+=1;
else if (array[i]=3)
freq3+=1;
else if (array[i]=4)
freq4+=1;
else if (array[i]=5)
freq5+=1;
else if (array[i]=6)
freq6+=1;
else
freq7+=1;
return freq[7]; /* I would like to return a array called freq[] with
7 elements from this function. However I'm not sure if I should return
the array like this or the array location. and i'm not even sure how to
go about it at this point. */
}
void RemoveBad() /*Used Void because don't need to return file.
File is written and saved outside of c++
(Not sure how to put that we need an input file for the function,
or if I even need that since it is prompted for???) */
{
string testtxt;
int array_size = 15360; // define the size of character array
char * NELM = new char[array_size]; // allocating an array of 15kb
int position = 0; //this will be used incremently to fill characters in the array
cout << "What is the name of the data file you would like to use, please be sure it is a .txt file, and include that in the name." << endl;
getline(cin, testtxt);
ifstream fin(testtxt.c_str()); //opening an input stream for file test.txt
if(fin.is_open())
{
//file opened successfully so we are here
cout << "File Opened successfully. Now reading data from file into array" << endl;
while(!fin.eof() && position < array_size)
{
fin.get(NELM[position]);
position++;
}
NELM[position-1] = '\0';
}
else //file could not be opened
{
cout << "File could not be opened." << endl;
}
//Inputting the retrieved data
ofstream fout("OnlyGood.txt");
if(fout.is_open())
{
cout << "File Opened successfully. Now writing data from array to file" << endl;
int NumBad = 0;
for(int i = 0; NELM[i] != '\0'; i++)
{
if (NELM[i] >= 0)
{
fout << NELM[i]; //writing ith character of array in the file
}
else
{
NumBad += 1;
}
}
cout << "Array data successfully saved into the file OnlyGood.txt" << endl;
cout << "However you had " << NumBad << "counts of data that did not fall between 0-7 NELM Value." << endl;
}
else //file could not be opened
{
cout << "File could not be opened." << endl;
}
return ???; // Not sure how to return a file, or if it should just be a file location, and then convert it back with the other function.
}
|