Question
A temperature file (e.g., temps.dat) A query file (e.g., queries.dat) This file contains a list of queries (i.e., requests for information) that your program should
A temperature file (e.g., temps.dat)
A query file (e.g., queries.dat) This file contains a list of queries (i.e., requests for information) that your program should calculate based on the data in file temps.dat. Each line in the file contains one query. There are two types of queries:
AVG: given a location (specified as a station id) and a range of years (specified as two integers, for example, 2000 2006), it computes the average temperature for the location and period. If no data is available for the location/period, the answer will be the string unknown.
MODE: given a location and a range of years, it identifies the most common rounded temperature value in the period.
If no data is available for the period, the expected result is the string unknown.
If more than one mode, you should return the one with the highest value.
Notice that the temperature values in file temps.dat are double numbers. You should round these values to the nearest integer before computing the mode. For example, 8.03, 8.1, and 8.5 are all rounded to 8; 8.51 and 8.8 are rounded to 9. So with this set of data, there are three eights and two nines. And the mode would be 8.
Your program should read these two files and generate a file result.dat with the queries and their results. Regardless,
temps.dat might look like this:
411048 2015 1 9.58 411048 2015 3 14.82 411048 2016 4 20.51 411048 2016 1 10.99 411000 1973 1 0.54 411048 2016 3 18.40 411048 2016 5 -99.99
queries.dat might look like this:
411048 AVG 2015 2016 411138 AVG 1995 1995 411048 MODE 2015 2016
Then your program is expected to produce a file named result.dat with the following content:
411048 2015 2016 AVG 14.86 411138 1995 1995 AVG unknown 411048 2015 2016 MODE 21
Requirements
Start with the code you completed for Part 1.
Your program should receive the names of the input files as command line arguments. The first argument will be the temperature file, the second the queries file.
If the input files contain a line with an invalid format, you should output on the console an error message and finish executing the program.
Do not throw an exception.
Output the message in the console beginning Error: followed by the description shown below followed by the invalid value. For example:
Data File
Error: Invalid temperature -1221.11
Error: Invalid year 2020
Error: Invalid month 0
Error: Unable to open input.dat
Error: Other invalid input
Query File
Error: Invalid range 1996-1995
Error: Unsupported query MAX
Error: Other invalid query
Note: You can have an invalid year in the query so that error can occur here too.
Invalid years will be part of an invalid range.
Error: Invalid range 1776-2025
Examples of lines with invalid format for queries.dat: AVG 2015 2016 411138 AVG 1996 1995 411048 MODE 1500 2016 411048 MAX 2015 2016
The output file created by your program should be named result.dat.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started