Vector Program This file httpuahcsorgCS121dataSSTdatatxt con
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.
Solution
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;
 }

