Question
Specifications Part 1: You will implement a linked list to organize temperature sensor readings from a file. Part 2: Process a file with queries to
Specifications
Part 1: You will implement a linked list to organize temperature sensor readings from a file.
Part 2: Process a file with queries to report based on the data.
A temperature file (e.g., temps.dat) The temperature value -99.99 is used by the UCHN agency to represent missing information, for example: 410120 1893 1 -99.99 Valid temperatures are assumed to be in the interval -50.0 to 50.0 (remember that they use Celsius, so this is a good range). The first valid year is 1800. The latest valid year should be our current year. You can declare a constant in your program to specify the current year. (If we were programming this to be used for real, we would instead obtain the current year from the system, so that no code changes are required for future years.)
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
LinkedList.cpp
#include
#include
#include "LinkedList.h"
#include "Node.h"
using namespace std;
LinkedList::LinkedList() {
// Implement this function
}
LinkedList::~LinkedList() {
// Implement this function
}
LinkedList::LinkedList(const LinkedList& source) {
// Implement this function
}
LinkedList& LinkedList::operator=(const LinkedList& source) {
// Implement this function
}
void LinkedList::insert(string location, int year, int month, double temperature) {
// Implement this function
}
void LinkedList::clear() {
// Implement this function
}
Node* LinkedList::getHead() const {
// Implement this function it will be used to help grade other functions
}
string LinkedList::print() const {
string outputString;
// Implement this function
return outputString;
}
ostream& operator
/* Do not modify this function */
os
return os;
}
LinkedList.h
#ifndef LINKEDLIST
#define LINKEDLIST
#include
#include
#include "Node.h"
class LinkedList {
private:
Node* head;
Node* tail;
public:
// Default constructor
LinkedList();
// Destructor
~LinkedList();
// Copy constructor
LinkedList(const LinkedList& other);
// Copy assignment
LinkedList& operator=(const LinkedList& other);
// Insert a record to the linked list
void insert(std::string location, int year, int month, double temperature);
// Clear the content of this linked list
void clear();
// The functions below are written already. Do not modify them.
std::string print() const;
Node* getHead() const;
};
Main.cpp
#include "TemperatureDatabase.h"
#include
using namespace std;
int main(int argc, char** argv) {
if (argc
cout
return 1;
} else {
TemperatureDatabase database;
database.loadData(argv[1]);
database.performQuery(argv[2]); // Will be done in Part 2
}
}
Node.cpp
#include
#include "Node.h"
using namespace std;
// Default constructor
Node::Node() {} // remember to initialize next to nullptr
// Parameterized constructor
Node::Node(string id, int year, int month, double temperature) {}
// remember to initialize next to nullptr
bool Node::operator
return this->data
}
Node.h
#ifndef NODE
#define NODE
#include "TemperatureData.h"
struct Node {
TemperatureData data;
Node* next;
// Default constructor
Node(); // remember to initialize next to nullptr
Node(std::string id, int year, int month, double temperature); // remember to initialize next to nullptr
// This operator will allow you to just ask if a node is smaller than another
// rather than looking at all of the location, temperature and date information
bool operator
// The function below is written. Do not modify it
virtual ~Node() {}
};
#endif
std::ostream& operator
#endif
TemperatureData.cpp
#include "TemperatureData.h"
using namespace std;
TemperatureData::TemperatureData() {} //initialize everything
TemperatureData::TemperatureData(std::string id, int year, int month, double temperature) {} //initialize everything
TemperatureData::~TemperatureData() {} // You should not need to implement this
bool TemperatureData::operator
// Implement this
}
TemperatureData.h
#ifndef TEMPERATUREDATA
#define TEMPERATUREDATA
struct TemperatureData {
// Put data members here
TemperatureData();
TemperatureData(std::string id, int year, int month, double temperature);
virtual ~TemperatureData();
bool operator
};
#endif /* TEMPERATUREDATA */
TemperatureDatabase.cpp
#include "TemperatureDatabase.h"
#include
using namespace std;
// Default constructor/destructor. Modify them if you need to.
TemperatureDatabase::TemperatureDatabase() {}
TemperatureDatabase::~TemperatureDatabase() {}
void TemperatureDatabase::loadData(const string& filename) {
// Implement this function for part 1
}
void TemperatureDatabase::performQuery(const string& filename) {
// Implement this function for part 2
// Leave it blank for part 1
}
TemperatureDatabase.h
#ifndef TEMP_DB
#define TEMP_DB
#include
#include "LinkedList.h"
class TemperatureDatabase {
public:
TemperatureDatabase();
~TemperatureDatabase();
// The two functions below are required
// Read the temperature records from the data file and populate the linked list
// Implement for Part 1
void loadData(const std::string& data_file);
// Read the queries from the query file and perform a series of queries
// Implement for Part 2
void performQuery(const std::string& query_filename);
private:
// Linked list to store the temperature records. You need to properly populate
// this link list.
LinkedList records;
// You can add any private member variables/functions you feel useful in this class.
};
#endif // TEMP_DB
Your implementation has to use a linked list to store the data you read from the temperature file.
You must implement a function named getHead() in the class LinkedList. This function is supposed to return the pointer to the start Node of the list.
You must implement an overloaded operator
First ordered by location
Then by date (i.e. by year and then by month)
For example, for the sample temps.dat above, after reading 3 lines of the file your linked list looks like:After reading all 7 lines from the file, it looks like:
Notice that we ignored the entry with value -99.99.
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. Well use the queries file next week.
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:
Error: Invalid temperature -1221.11
Error: Invalid year 2020
Error: Invalid month 0
Error: Unable to open input.dat
Error: Other invalid input
You are required to use classes and comply with the Rule of 3 (see zyBook and slides). More specifically, you need to implement the constructor, destructor, copy assignment, and copy constructor for the LinkedList class and any other class that uses the freestore, but I dont think any other class should use the heap.
The constructor for your Node and TemperatureData classes should take all data items (station id, year, month, average temperature value) as parameters. Use initialization in the membername(value) format (see zyBook and slides)
Well test these directly.
Implement the print() function for the linked list. Use this function and/or the overloaded output operator to test your results. Well test the linked list functions directly for part 1. The expectation is that the list will be printed out in the correct order based on the comparison rules listed earlier.
The output format is the same as the format in the input file. Id, year, month, and temperature separated by a space.
When you output, it will look like the input file, with each item on one line. However, the order should be sorted according to the requirements above.
Sample Input/Output Files
temp-3lines.dat: 411048 2015 3 14.82
temp-7lines.dat: 411048 2015 1 9.58
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