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

C++ code In oceanography, ships collect all kinds of data – at any one latitude

ID: 3665457 • Letter: C

Question

C++ code In oceanography, ships collect all kinds of data – at any one latitude and longitude position, there might be temperature, conductivity, salinity, and depth. The SOIREE project collected temperature and depth data as it transited to the research site from New Zealand. There are 3 files here: 30XBT.flat1.txt, 31XBT.flat1.txt, and 32XBT.flat1.txt The data in each file looks something like this: Xseq date time lon lat depth_xbt temp_xbt 30 19990206 0355 142.732 -59.087 0.6 3.59 30 19990206 0355 142.732 -59.087 1.2 2.85 30 19990206 0355 142.732 -59.087 1.9 2.66 The first line is a header that describes the data: the Sequence number, the date (February 6, 1999), the time the data was collected, the longitude and latitude of the data, the depth in meters, and the temperature in degrees C. The rest of the file contains the data. The data is fixed record size of 60 characters per record. Each field is left-justified and contains data like this: Columns Value 1-6 Sequence Number 7-14 Date 17-20 Time 23-29 Longitude 32-38 Latitude 41-45 Depth 52-60 Temperature Read all three datasets. The datasets have a problem in that when the data collection ends, a temperature higher than 30 degrees is recorded. For each dataset, determine the depth at which the last valid data point exists, and output the Sequence number, the date, longitude, latitude, depth and temperature for the deepest point for each record, as well as the number of valid points in each dataset. Assume a maximum of 1500 data points per data set. Create functions to determine the minimum temperature and the maximum temperature for each dataset. Output the depth at which those temperatures occur. Use the function openFileIn() from page 667 in the text. Your output should look similar to the output below (the actual values have been removed in the example).

30XBT.flat1.txt,

31XBT.flat1.txt, and 32XBT.flat1.txt are in next part of this question

Explanation / Answer

Program Logic :
1). Create a class to store all the variables
2). Create a vector to store above class into it.
3). findMin() function traverses the complete vector passed to it as input. And compares the temperature of Record(s) with a function scoped temporary variable; and update the result(output Record to be returned) and temporary minimum variable.
4). findMax() works exactly the same, just the checking condition is changed.

class Record{
public:
int seq;
long int date;
int time;
float lon;
float lat;
float depth_xbt;
float temp_xbt;
};

Record findMin(vector<Record> v)
{
Record temp_rec = new Record();
min_temp = 10000000;
for(auto &i : v)
{
if(i.temp_xbt < min_temp)
{
min_temp = i.temp_xbt;
temp_rec = i; // use of copy constructor
}
}
return temp_rec;
}

Record findMax(vector<Record> v)
{
Record temp_rec = new Record();
max_temp = -10000000;
for(auto &i : v)
{
if(i.temp_xbt > max_temp)
{
min_temp = i.temp_xbt;
temp_rec = i; // use of copy constructor
}
}
return temp_rec;
}

int main()
{
vector<Record> v1;
vector<Record> v2;
vector<Record> v3;
FILE *f0 = freopen("30XBT.flat1.txt", "r", stdin);
do
{
Record r1 = new Record();
cin >> r1.seq >> r1.date >> r1.time >> r1.lon >> r1.lat >> r1.depth_xbt >> r1.temp_xbt;
v1.push_back(r1);
}while(f0 != EOF);
fclose(f0);

FILE *f1 = freopen("31XBT.flat1.txt", "r", stdin);
do
{
Record r1 = new Record();
cin >> r1.seq >> r1.date >> r1.time >> r1.lon >> r1.lat >> r1.depth_xbt >> r1.temp_xbt;
v2.push_back(r1);
}while(f0 != EOF);
fclose(f1);
  
FILE *f2 = freopen("32XBT.flat1.txt", "r", stdin);
do
{
Record r1 = new Record();
cin >> r1.seq >> r1.date >> r1.time >> r1.lon >> r1.lat >> r1.depth_xbt >> r1.temp_xbt;
v3.push_back(r1);
}while(f0 != EOF);
fclose(f2);
  
/* Function calls to get the Minimum maximum */
Record result = new Record();
result = findMin(v1);
//Print(result);
result = findMin(v2);
//Print(result);
result = findMax(v1);
//Print(result);

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote