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

skeleton code : Temperature Queries (Part 1) In parts 1 and 2 you will use a lin

ID: 3774464 • Letter: S

Question

skeleton code :

Temperature Queries (Part 1) In parts 1 and 2 you will use a linked list to organize temperature sensor readings from a file. Another file will provide queries to report based on the data Program For part 1, you will build a program that receives as input two files: 1. A temperature file (e.g., temps.dat) This file contains historic average temperatures for several locations in Texas. The data has been obtained from the United States Historic Climate Network (USCHN). Each line of the file contains a location, a date. and the average temperature (in Celsius) for that location and date. A string, corresponding to a meteorological station id, represents a location. For example, "411048" corresponds to Brenham, Texas. A date is specified by two integers: a year and a month. A sample line in the temperature file would be 410120 1893 2 6.41 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.) l he 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.)

Explanation / Answer

#include "temperaturedb.h"
#iclude<fstream>
using namespace std;

void TemperatureDatabase::loadData(const string& filename){
   //creating linkedlist object
   LinkedList obj;
   std::ifstream infile(filename);
   while (std::getline(infile, line))
   {
       std::istringstream iss(line);
       int location,year,month;
       double temperature;
       if (!(iss >> location >> year >> month >> temperature)) { break; } // error
       obj.insert(location,year,month,temperature);
   }
}

void TemperatureDatabase::performQuery(const string& filename){
ofstream outputFile (filename);
Node *list = obj.head;
if (outputFile.is_open())
{
       while(list) {
           myfile << list->location << " " << list->year<< " " << list->month<< " " << list->temperature;
           list = list->next;
       }
       myfile.close();
}
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------

#ifndef TEMP_08
#define TEMP_08

#include<string>
#include "Linkedlist.h"

class TemperatureDatabase{
   public:
       TemperatureDatabase(){};
       ~TemperatureDatabase(){};
      
       void loadData(const std::string& data_file);
       void performQuery(const std::string& query_filename);
  
   private:
       Linkedlist records;  
};

-----------------------------------------------------------------------------------------------------------------------------------------

#include <string>
#include "linkedlist.h"
using namespace std;

LinkedList::LinkedList() {
   head = NULL;
}

LinkedList::~LinkedList() {
   head = NULL;
}

LinkedList::LinkedList(const LinkedList& source){
   head = source;
}

LinkedList& LinkedList::operator=(const LinkedList& source){
   Node *n = head;
   n = source;
}
void LinkedList::insert(int location, int year, int month, double temperature) {
   Node *newNode = new Node;
   newNode->location = location;
   newNode->year = year;
   newNode->month = month;
   newNode->temperature = temperature;
   newNode->next = NULL;

   Node *cur = head;
   while(cur) {
       if(cur->next == NULL) {
           cur->next = newNode;
           return;
       }
       cur = cur->next;
   }
}
void LinkedList::print() const {
   print(cout);
}
void LinkedList::print(ostream& os) const {
   os<<*this;
}

-----------------------------------------------------------------------------------------------------------------------------------------------

#ifndef LINKEDLIST
#define LINKEDLIST

#include <iostream>
#include "node.h"

class LinkedList{
   private:
       Node* head;
       Node* tail;
  
   public:
       LinkedList();
       ~LinkedList();
       LinkedList(const LinkedList& other);
       //assignment ocnstructor
       LinkedList& operator=(const LinkedList& other);
       //insert method
       void insert(int location, int year, int month, double temperature);
       void clear();
       void print() const;
       void print(std::ostream&) const;
}