Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Attached is a data file called Data_RemoveBad that contains integer values 1 thr

ID: 3690972 • Letter: A

Question

Attached is a data file called Data_RemoveBad that contains integer values 1 thru 7. There are additional entries of value -9999 in the data table: these are invalid entries that need to be removed from the file. You will write a program that

(a) calls function called cleandata that reads each value into a one-dimensional array called NELM and writes it to a new file if it is not a -9999 value. This function should also count the number of bad values removed, and return the number of removed data points to the screen.

and

(b) calls function named frequency that counts the number of occurrences of the values 1, 2, 3, 4, 5, 6, 7 and returns to a data file the relative frequency of occurrence of each numerical value. Relative frequency is just the percent of times a value occurs compared to the total number of data points collected.

i would post the data fil;e but it is extremely long. from my undertstanding it needs to read the txt file and then remove the any number not between 1-7. then it needs to give a cout statement of how many numbers were removed and then how many between 1-7 truely were in the data file.

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string>

#include <cstdlib>

#include <vector>

using namespace std;

void cleandata ()

{

int bad_values = 0;

vector<int> NELM;

ifstream file_

("e;//removebadtext.txt");  

ofstream file("e;//result.txt");

int number;

while(file_ >> number)

{

if(number == -9999) bad_values++;

else

{

NELM.push_back(number);

file << number;

}

}

cout << "Number of removed data points: " << bad_values << endl;

file_.close();  

file.close();  

}

void frequency()

{

ifstream file_("e;//removebadtext.txt");  

ofstream file("e;//frequency.txt");

int number;

int frequency1 = 0;

int frequency2 = 0;

int frequency3 = 0;

int frequency4 = 0;

int frequency5 = 0;

int frequency6 = 0;

int frequency7 = 0;

while(file_ >> number)

{

if(number == 1) frequency1++;

else if(number == 2) frequency2++;

else if(number == 3) frequency3++;

else if(number == 4) frequency4++;

else if(number == 5) frequency5++;

else if(number == 6) frequency6++;

else if(number == 7) frequency7++;

}

file << "Frequency of 1: " << frequency1 << endl;

file << "Frequency of 2: " << frequency2 << endl;

file << "Frequency of 3: " << frequency3 << endl;

file << "Frequency of 4: " << frequency4 << endl;

file << "Frequency of 5: " << frequency5 << endl;

file << "Frequency of 6: " << frequency6 << endl;

file << "Frequency of 7: " << frequency7 << endl;

file_.close();

file.close();

}

int main()

{

cleandata();

frequency();

system("pause");

return 0;

}

this is what i have so far but it wont read the file from my flashdrive

Explanation / Answer

Hi, I have coded remining part. Please test it.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <vector>
using namespace std;

void cleandata ()
{
   int bad_values = 0;
   vector<int> NELM;
   ifstream file_("e;//removebadtext.txt");
   ofstream file("e;//result.txt");
   int number;
     
   while(file_ >> number)
   {
       if(number == -9999) bad_values++;
       else
       {
           NELM.push_back(number);
           file << number<<" "; // writinf numbers to file and and putting a space
       }
   }
     
   cout << "Number of removed data points: " << bad_values << endl;
   file_.close();
   file.close();
}

void frequency()
{
   ifstream file_("e;//removebadtext.txt");
   ofstream file("e;//frequency.txt");
   int number;
   int frequency1 = 0;
   int frequency2 = 0;
   int frequency3 = 0;
   int frequency4 = 0;
   int frequency5 = 0;
   int frequency6 = 0;
   int frequency7 = 0;
     

   while(file_ >> number)
   {
       if(number == 1) frequency1++;
       else if(number == 2) frequency2++;
       else if(number == 3) frequency3++;
       else if(number == 4) frequency4++;
       else if(number == 5) frequency5++;
       else if(number == 6) frequency6++;
       else if(number == 7) frequency7++;
         
   }
  
   double total = frequency1+frequency2+frequency3+frequency4+frequency5+frequency6+frequency7;
     
   file << "Relative Frequency of 1: " << (frequency1/total)*100 << endl;
   file << "Frequency of 2: " << (frequency2/total)*100 << endl;
   file << "Frequency of 3: " << (frequency3/total)*100<< endl;
   file << "Frequency of 4: " << (frequency4/total)*100 << endl;
   file << "Frequency of 5: " << (frequency5/total)*100<< endl;
   file << "Frequency of 6: " << (frequency6/total)*100 << endl;
   file << "Frequency of 7: " << (frequency7/total)*100 << endl;

   file_.close();
   file.close();
}

int main()
{
   cleandata();
   frequency();
   system("pause");
   return 0;

}