Question: Your implementation has to use a linked list to store the data you read from the temperature file. As you read the data from the

Your implementation has to use a linked list to store the data you read from the temperature file. As you read the data from the file, you need to insert it into your linked list such that the list is ordered by location first and then by date (i.e. by year and then by month). Your program should receive the names of the input files as command line arguments. The output file created by your program should be named results.dat.

If the input files contain a line with an invalid format, you should output on the console an error message and finish the execution. You do not need to specify which error occurred. Just make sure that the string Error appears in the console. You can be more specific about the error if you want (it may be useful for your own debugging, in case you are making a mistake when validating the input data.)

Examples of lines with invalid format for temps.dat: 4111000 1889 0 -4.3 4111000 1889 18 -4.3 4111000 2016 01 -1222.11 4111000 1889 8.3

You are required to use classes. By the end of the next homework (part 2), you must comply with the Rule of 3. For this part you need to implement the constructor and destructor. The constructor for your class representing temperature values should take all data items (station id, year, month, average temperature value) as parameters. Use initialization in the membername(value) format. Implement the overloaded output operator for the linked list and write its content to results.dat after reading in all values.

temperaturedb.h

#ifndef TEMP_DB #define TEMP_DB

#include #include "linkedlist.h"

class TemperatureDatabase { public: // Default constructor/destructor. Modify them if you need to. TemperatureDatabase() {} ~TemperatureDatabase() {}

// The two functions below are required

// Read the temperature records from the data file and populate the linked list void loadData(const std::string& data_file);

// Read the queries from the query file and perform a series of queries 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

temperaturedc.cpp

#include "temperaturedb.h"

#include using namespace std;

void TemperatureDatabase::loadData(const string& filename) { // Implement this function }

void TemperatureDatabase::performQuery(const string& filename) { // Implement this function }

node.h

#ifndef NODE #define NODE

// Include the header file for the data struct/class if you use one. // For example, if you have a data class in data.h, put // #include "data.h" // below.

struct Node { // Add your member variable for the data fields here. // You can use an extra struct/class for storing the data. In that case, put // your definition of the data class in a separate header file, for example: // data.h

// Pointer to the next node in the linked list Node* next;

// Default constructor Node() : next(nullptr) { // Initialize your data members properly inside the function body }

Node(int value) : next(nullptr) { // Initialize your data members properly inside the function body }

// The function below is written. Do not modify it virtual ~Node() {} };

#endif

main.cpp

include "temperaturedb.h"

#include using namespace std;

int main(int argc, char** argv) { if (argc < 3) { cout << "Usage: " << argv[0] << " data_file query_file" << endl; return 1; } else { TemperatureDatabase database; database.loadData(argv[1]); database.performQuery(argv[2]); } }

linkedlist.h

#ifndef LINKEDLIST #define LINKEDLIST

#include #include "node.h"

class LinkedList { private: Node* head; Node* tail;

public: // Default constructor LinkedList();

// Destructor ~LinkedList();

// Copy constructor LinkedList(const LinkedList& other);

// Assignment constructor LinkedList& operator=(const LinkedList& other);

// Insert a record to the linked list void insert(int location, int year, int month, double temperature);

// Clear the content of this linked list void clear();

friend std::ostream& operator<<(std::ostream&, const LinkedList&);

// The functions below are written already. Do not modify them. void print() const; void print(std::ostream&) const; };

std::ostream& operator<<(std::ostream& os, const LinkedList& ll); #endif

linkedlist.cpp

include #include #include "linkedlist.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(int location, int year, int month, double temperature) { // Implement this function }

void LinkedList::clear() { // Implement this function }

void LinkedList::print() const { /* Do not modify this function */ print(cout); }

void LinkedList::print(ostream& os) const { /* Do not modify this function */ os << *this; }

ostream& operator<<(ostream& os, const LinkedList& ll) { // Implement this function }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!