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

For this assignment you will write a program that reads in climate data (imagine

ID: 3880285 • Letter: F

Question

For this assignment you will write a program that reads in climate data
(imagine it is coming from a weather station) and stores that data in a linked
list. After reading and storing all of the data your program will generate a
report from the data.

The objective of this assignment is to learn how to implement a linked list
and to gain familiarity with using a linked list in solving a problem. Since
one of the objectives is to learn how to implement a linked list you cannot
use the STL linked list.

Your program should use good design methodologies so you should have separate
classes for each of the following:

- datalogger -- This class represents the "business logic" of adding data to
the storage. This class also handles filtering out duplicate data items (see
the requirements listed below). This is the only class that weatherlog.cpp
knows about and it expects two methods: addData() and printReport().
- linkedlist -- This class should implement a linked list. This class should
be distinct from the datalogger class (although I would expect datalogger to
have a data member that is a linkedlist object).
- weatherdata -- This class encapsulates the weather data (time, temperature,
windspeed).

You are welcome to create any additional classes that you need.

Below are the specific external and internal requirements for this
assignment. Your program will be evaluated based on these requirements.

== External Requirements ==

- The main driver (weatherlog.cpp) will provide a sequence of data
readings. The program needs to store these readings. After all of the data
is read in, the program must create a report identical to the one in the
expected.txt output file.
- Data with a duplicate timestamp indicates contradictory or inaccurate data
and should not be stored (all records with the same timestamp).
- The report includes:
- a line that states the timestamp range
- a line that states the number of data entries
- a temperature section that contains a detailed report (see below)
- a windspeed section that contains a detailed report (see below)
- detailed report data:
- the minumum value measured
- the maximum value measured
- a list of all of the readings >= the 99% reading (in order)
- a list of all of the readings <= the 1% reading (in order)
- see the provided "expected.txt" to see the report format

== Internal Requirements ==

- The program must use the supplied weatherlog.cpp file, unmodified, as the
main driver.
- All of the weather data must be stored in a linked list.
- The linked list must have three separate "chains". One that keeps the data
ordered by timestamp, one that keeps the data ordered by temperature, and
one that keeps the data ordered by windspeed.
- Strings must be stored using char* variables, not std::string.
- No memory leaks.

Weatherlog.cpp file:

#include <iostream>
#include <fstream>
#include "datalogger.h"

using namespace std;

int main(int argc, char** argv) {

datalogger dl;

if (argc != 2) {
cout << "Usage: " << argv[0] << " <datafile>" << endl;
exit(0);
}

// Read the data

char* datafile = argv[1];
ifstream infile(datafile);
int timestamp;
double temperature;
double windspeed;

while (!infile.eof()) {
infile >> timestamp;
infile >> temperature;
infile >> windspeed;

if (!infile.eof()) {
dl.addData(timestamp, temperature, windspeed);
}
}

// Output the report
dl.printReport();

return(0);
}

Example Climate data values in climatedata.txt:

1480906168 -226 361
1480906168 -224 270
1480906175 -222 326
1480906179 -218 236
1480906187 -218 145
1480906189 -216 109
1480906189 -212 145
1480906190 -208 153
1480906197 -204 90
1480906197 -201 48
1480906198 -197 38
1480906203 -193 60
1480906209 -190 117
1480906213 -188 108
1480906219 -186 104
1480906225 -185 94
1480906225 -181 186
1480906233 -181 234
1480906240 -179 221
1480906246 -175 283
1480906253 -175 224
1480906260 -177 146
1480906261 -180 126
1480906261 -184 51
1480906262 -185 38
1480906271 -187 52
1480906273 -191 25
1480906277 -193 110
1480906279 -194 42
1480906280 -197 0
1480906284 -199 0
1480906291 -203 0
1480906293 -205 0
1480906295 -208 0
1480906302 -209 0
1480906309 -210 0
1480906312 -213 0
1480906320 -209 0
1480906323 -206 41
1480906330 -202 102
1480906331 -202 130
1480906339 -202 114
1480906341 -200 165
1480906344 -196 256
1480906348 -192 299
1480906349 -191 205
1480906349 -190 176
1480906354 -186 206
1480906359 -184 189
1480906367 -183 258
1480906376 -180 310
1480906383 -177 282
1480906386 -175 286
1480906392 -175 266
1480906400 -175 240
1480906403 -174 217
1480906404 -170 12

This question has been asked before, http://www.chegg.com/homework-help/questions-and-answers/programming-assignment-assignment-write-program-reads-climate-data-imagine-coming-weather--q22881915. But was done incorrectly. There needs to be atleast 7 total files, weatherlog.cpp, datalogger.cpp, datalogger.h, linkedlist.cpp, linkedlist.h, weatherdata.cpp and weatherdata.h. Please take as long as you need to fully complete everything, as the previous post did not.

Explanation / Answer

weatherlog.cpp
---------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include "datalogger.h"

using namespace std;

int main(int argc, char** argv) {

    datalogger dl;
    LinkedList ll;

    if (argc != 2) {
        cout << "Usage: " << argv[0] << " <datafile>" << endl;
        exit(0);
    }
    const char* fileName = "climatedata.txt";

    // Read the data

    char* datafile = argv[1];
    ifstream infile(fileName);
    int timestamp;
    double temperature;
    double windspeed;

    while (!infile.eof()) {
        infile >> timestamp;
        infile >> temperature;
        infile >> windspeed;

        if (!infile.eof()) {
            dl.addData(timestamp, temperature, windspeed);
        }
    }

    // Output the report
    dl.printReport();

    return(0);
}
----------------------------------------------------------------------------------------------------
datalogger.cpp
-----------------------------------------------------------
#include <iostream>
#include "datalogger.h"

using namespace std;

void datalogger::printReport() {
    weatherList.printSmallReport();
//    weatherList.generateReport();
//    weatherList.prettyPrint();
};

void datalogger::addData(int time, double temp, double wind) {
    WeatherData * wd = new WeatherData(time, temp, wind);
    Node * new_node = new Node(wd);
    if(!weatherList.addSorted(new_node)) {
        delete new_node;
        new_node = nullptr;
    }
}
-------------------------------------------------------------------------------------------------------
datalogger.h
-------------------------------
#ifndef DATALOGGER_H
#define DATALOGGER_H

#include <ostream>
#include "linkedlist.h"

class datalogger {
public:
//    datalogger();

//    ~datalogger();

    void addData(int, double, double);

    void printReport(void);

private:
    static const bool DEBUG = false;
    LinkedList weatherList;
};

#endif
--------------------------------------------------------------------------------------------------
linkedlist.cpp
---------------------------------------
#include <iostream>
#include "linkedlist.h"

using namespace std;

// Helper functions
double fToC(double);
double mphToMps(double);

Node::Node() : wd(nullptr), nextTime(nullptr), nextTemp(nullptr), nextWind(nullptr), remove(false) {}

Node::Node(WeatherData *wd) : wd(wd), nextTime(nullptr), nextTemp(nullptr), nextWind(nullptr), remove(false) {}

Node::~Node() {
    if(wd) {
        delete wd;
    }
}

Node::Node(const Node & copy_me) : nextTime(nullptr), nextTemp(nullptr), nextWind(nullptr), wd(copy_me.wd), remove(copy_me.remove){}

void Node::print() {
    cout << "Time: " << wd->getTime() << " Temp: " << wd->getTemp() << " Wind: " << wd->getWind() << endl;
}

LinkedList::LinkedList() : size(0), head(new Node()), tail(new Node()) {};

LinkedList::~LinkedList() {
    if(head) {
        destroy(head);
    }
}

LinkedList::LinkedList(const LinkedList & copy_me) : size(copy_me.size), head(nullptr), tail(nullptr) {
    copy(head, copy_me.head);
}


void LinkedList::generateReport() const {
  
    cout << " -- Data Report -- " << endl << endl;
    cout << "Time Range: " << head->nextTime->wd->getTime() << " - " << tail->nextTime->wd->getTime() << endl;
    cout << "Number of entries: " << size << endl;
    cout << "----------------------------------------------------------------------" << endl;
    cout << "TEMPERATURE" << endl;
    cout << "Min temperature: " << head->nextTemp->wd->getTemp() << " C" << endl;
    cout << "Max Temperature: " << fToC(tail->nextTemp->wd->getTemp()) << " C" << endl << endl;
//    cout << "Top 1% of temperatures (>= " << determineTop(1) << "):" << endl; // index 1 corresponds to temperatures
//    printTop(determineTop(1));
//    cout << "Bottom 1% of temperatures (<= " << determineBottom(1) << "):" << endl;
//    printBottom(determineBottom(1));
    cout << "----------------------------------------------------------------------" << endl;
    cout << "WINDSPEED" << endl;
    cout << "Min windspeed: " << mphToMps(head->nextWind->wd->getWind()) << " m/s" <<endl;
    cout << "Max windspeed: " << mphToMps(tail->wd->getWind()) << "m/s" << endl;
//    cout << "Top 1% of windspeeds (>= " << determineTop(2) << "):" << endl;
//    printTop(determineTop(2));
//    cout << "Bottom 1% of windspeeds (<= " << determineBottom(2) << "):" << endl;
//    printBottom(determineBottom(2));
}

void LinkedList::printSmallReport() {
    int time_min = head->nextTime->wd->getTime(), time_max = tail->nextTime->wd->getTime();
    double temp_min = head->nextTemp->wd->getTemp(), temp_max = tail->nextTemp->wd->getTemp(),
    wind_min = head->nextWind->wd->getWind(), wind_max = tail->nextWind->wd->getWind();

    cout << endl << " ------ Data Report ------ " << endl;
    cout << "Total data points: " << size << endl << endl;
    cout << "Time Range: (" << head->nextTime->wd->getTime() << "-" << tail->nextTime->wd->getTime() << ")" << endl;
    cout << "Time Min: " << time_min << " Time Max: " << time_max << " 1% of temps: " << ((time_max - time_min) * 0.01) << endl << endl;

    cout << "Temp Range: (" << head->nextTemp->wd->getTemp() << "-" << tail->nextTemp->wd->getTemp() << ")" << endl;
    cout << "Temp Min: " << temp_min << " Temp Max: " << temp_max << " 1% of times: " << ((temp_max - temp_min) * 0.01) << endl << endl;

    cout << "Wind Range: (" << head->nextWind->wd->getWind() << "-" << tail->nextWind->wd->getWind() << ")" << endl;
    cout << "Wind Min: " << wind_min << " Wind Max: " << wind_max << " 1% of winds: " << ((wind_max - wind_min) * 0.01) << endl << endl;
}
void LinkedList::prettyPrint() const {
    Node *curr = head->nextTime;
    cout << "List size: " << size << endl;//" [";
    if (size > 10) {
        int i = 0;
        while (curr) {
            if ((i < 5 || (i > size - 6))) {
                cout << curr->wd->getTime() << ", " << curr->wd->getTemp() << ", " << curr->wd->getWind() << endl;
                if (curr->nextTime) {
                    cout << (i == 4 ? " ... " : "");
                }
            }
            curr = curr->nextTime;
            i++;
        }
    }
}

// Used for debugging
void LinkedList::uglyPrint(bool slightlyLessUgly) const {
    Node *curr = head->nextTime;
    cout << endl << "List size: " << size << (slightlyLessUgly ? " [" : " ");
    while (curr) {
        cout << curr->wd->getTime() << ", " << curr->wd->getTemp() << ", " << curr->wd->getWind() << "";
        cout << (curr->nextTime ? ", " : "");
        curr = curr->nextTime;
    }
    cout << (slightlyLessUgly ? "]" : "");
}

bool LinkedList::addSorted(Node *&new_node) {
    if(linkSortedTime(head->nextTime, new_node)) {
        bool ret = linkSortedTemp(head->nextTemp, new_node);
        ret |= !linkSortedWind(head->nextWind, new_node);
        ++size;
        return ret;
    }
    return false;
}

bool LinkedList::linkSortedTime(Node *& curr, Node *& new_node) {
    if(!curr) {
        curr = new_node;
        tail->nextTime = new_node;
        return true;
    }
    if(curr->wd->getTime() == new_node->wd->getTime()) {
        return false;
    } else if(curr->nextTime && curr->nextTime->wd->getTime() > new_node->wd->getTime()) {
        new_node->nextTime = curr->nextTime;
        curr->nextTime = new_node;
        return true;
    }
    return linkSortedTime(curr->nextTime, new_node);
}

bool LinkedList::linkSortedTemp(Node *& curr, Node *& new_node) {
    if(!curr) {
        curr = new_node;
        tail->nextTemp = new_node;
        return true;
    }
    if(curr->nextTemp && curr->nextTemp->wd->getTemp() > new_node->wd->getTemp()) {
        new_node->nextTemp = curr->nextTemp;
        curr->nextTemp = new_node;
        return true;
    }
    return linkSortedTemp(curr->nextTemp, new_node);
}

bool LinkedList::linkSortedWind(Node *& curr, Node *& new_node) {
    if(!curr) {
        curr = new_node;
        tail->nextWind = new_node;
        return true;
    }
    if(curr->nextWind && curr->nextWind->wd->getWind() > new_node->wd->getWind()) {
        new_node->nextWind = curr->nextWind;
        curr->nextWind = new_node;
        return true;
    }
    return linkSortedWind(curr->nextWind, new_node);
}

// Deprecated AF
void LinkedList::removeDupes() {
    Node *curr = head->nextTime, *trailCurr = head, *temp = nullptr;
    if (curr->remove) {
        temp = curr;
        curr = curr->nextTime;
        delete temp;
        trailCurr->nextTime = curr;
        size--;
    }

    while (curr->nextTime) {
        if (curr->remove) {
            temp = curr;
            curr = curr->nextTime;
            delete temp;
            trailCurr->nextTime = curr;
            size--;
        } else {
            trailCurr = curr;
            curr = curr->nextTime;
        }
    }

    if (curr->remove) {
        delete curr;
        tail = trailCurr;
        size--;
    }
};

void LinkedList::destroy(Node *curr) {
    if(!curr) {
        return;
    }
    destroy(curr->nextTime);
    delete curr;
    curr = nullptr;
    return;
}

bool LinkedList::copy(Node *&result, Node *source) {
    if(!source) {
        result = nullptr;
        return true;
    }
    result = new Node(*source);
    copy(result->nextTime, source->nextTime);
    return true;
}


// ---------------- Helper Functions -----------------
double fToC(double f) {
    return (f - 32.0) * (5.0/9.0);
}

double mphToMps(double mph) {
    return mph * 0.44704;
}

double LinkedList::determineBottom(int top, int bottom, int size) const {
    // Pass for now.
}

double LinkedList::determineTop(int top, int bottom, int size) const {
    // Pass for now
}

void LinkedList::printTop(double top) const {
    Node *curr = head->nextTime;
    while (curr) {
        if (curr->wd->getTemp() >= top) {
            cout << "Timestamp: " << curr->wd->getTime() << " Temperature: " << fToC(curr->wd->getTemp())
                 << " C Windspeed: " << mphToMps(curr->wd->getWind()) << " m/s" << endl << endl;
        }
        curr = curr->nextTime;
    }
}

void LinkedList::printBottom(double bottom) const {
    Node *curr = head->nextTime;
    while (curr) {
        if (curr->wd->getTemp() <= bottom) {
            cout << "Timestamp: " << curr->wd->getTime() << " Temperature: " << fToC(curr->wd->getTemp())
                 << " C Windspeed: " << mphToMps(curr->wd->getWind()) << " m/s" << endl << endl;
        }
        curr = curr->nextTime;
    }
}
--------------------------------------------------------------------------------------
linkedlist.h
-------------------------------------
#ifndef LINKEDLIST_H
#define LINKEDLIST_H

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

class Node {
public:
    Node();
    Node(WeatherData *);
    ~Node();
    Node(const Node&);
    WeatherData *wd;
    Node *nextTime;
    Node *nextTemp;
    Node *nextWind;
    bool remove;
    void print();
};

class LinkedList {
public:
    LinkedList();
    ~LinkedList();
    LinkedList(const LinkedList &);

    double determineBottom(int, int, int) const;
    double determineTop(int, int, int) const;

    void generateReport() const;
    void printTop(double) const;
    void printBottom(double) const;
    void prettyPrint() const;
    void uglyPrint(bool) const;

    bool addSorted(Node *&);
    void removeDupes();
    void printSmallReport();

private:
    int size;
    Node *head, *tail;
    bool linkSortedTime(Node *&, Node *&);
    bool linkSortedTemp(Node *&, Node *&);
    bool linkSortedWind(Node *&, Node *&);

    void destroy(Node *);
    bool copy(Node *&, Node *);
};

#endif
------------------------------------------------------------------------------------------------------
weatherdata.cpp
--------------------------------------------------
#include "weatherdata.h"

WeatherData::WeatherData() : time(0), temp(0), wind(0){};

WeatherData::WeatherData(int _time, double _temp, double _wind) : time(_time), temp(_temp), wind(_wind){};

//WeatherData::~WeatherData(){};

//    void WeatherData::setTime(int _time) {
//        time = _time;
//    }
//
//    void WeatherData::setTemp(int _temp) {
//        temp = _temp;
//    }
//    void WeatherData::setWind(int _wind) {
//        wind = _wind;
//    };

    int WeatherData::getTime() const {
        return time;
    }
  
    double WeatherData::getTemp() const {
        return temp;
    }
  
    double WeatherData::getWind() const {
        return wind;
    }

//WeatherData& WeatherData::operator=(const WeatherData &rhs) {
//   if(this == &rhs) {
//        return *this;
//    }
//    this->time = rhs.time;
//    temp = rhs.temp;
//    wind = rhs.wind;
//   return *this;
//}
------------------------------------------------------------------------------------------------------
weatherdata.h
-------------------------------------------------
#ifndef WEATHERDATA_H
#define WEATHERDATA_H

class WeatherData {
public:
    WeatherData();
    WeatherData(int, double, double);
    // WeatherData(const WeatherData& copyData);
//    ~WeatherData();

//    void setTime(int);
//    void setTemp(int);
//    void setWind(int);

    int getTime() const;
    double getTemp() const;
    double getWind() const;
  
//   WeatherData& operator = (const WeatherData &rhs);

private:
    int time;
    double temp;
    double wind;

};
#endif

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