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

Vector Program This file http://uahcs.org/CS121/data/SSTdata.txt contains data f

ID: 3777572 • Letter: V

Question

Vector Program This file http://uahcs.org/CS121/data/SSTdata.txt contains data from an instrument that measures sea surface temperature remotely. On occasion data points are corrupted falling outside an accepted range of values (Less than 0 degrees C or greater than 40 degrees C). Write a program that reads in the data from the file and stores it in a vector. Once all the data is read in find and replace all out of range values with the flag value -9999.

Then create a new file with the revised data.

Explanation / Answer

Here is the code for you:

#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main()
{
//This file (data.txt) contains data from an instrument that measures sea surface temperature remotely.
ifstream fin;
fin.open("data.txt");
//Write a program that reads in the data from the file and stores it in a vector.
vector <double>temperatures;
double temp;
while(!fin.eof())
{
fin>>temp;
temperatures.push_back(temp);
}
//Once all the data is read in find and replace all out of range values with the flag value -9999.
for(int i = 0; i < temperatures.size(); i++)
if(temperatures[i] < 0 || temperatures[i] > 40)
temperatures[i] = -9999;
for(int i = 0; i < temperatures.size(); i++)
cout<<temperatures[i]<<" ";
cout<<endl;
}