Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An object-oriented solution and implement the solution in C++ to solve the problemdescribed below. You will be reusing the Vector, Date, and Time classes as

An object-oriented solution and implement the solution in C++ to solve the problemdescribed below.

You will be reusing the Vector, Date, and Time classes as well as data file reading code from Lab 5. I will provide them below. RELEVANT FILES WILL are below, REMOVE CODES IF NEEDED.

Design an Object Oriented program in C++ that meets the specifications shown below. A suitable menu with an exit option in your main program. When designing the output, imagine yourself as the user of the program. Tthe user interaction to be concise but user friendly on the command line. Do not use GUI interaction.

Sample output formats shown below use made up data for the year 1905.

Menu options are:

1. The average wind speed and average ambient air temperature for a specified month and year. (print on screen only)

Example output format if there is data:

January 1905: 5.5 km/h, 25.5 degrees C

Example output format if there is no data:

March 1905: No Data

2. Average wind speed and average ambient air temperature for each month of a specified year. (print on screen only)

Example output format is: 1905

January: 5.5 km/h, 25.5 degrees C

February: 4.5 km/h, 27.5 degrees C

March: No Data

...

3. Total solar radiation in kWh/m2 for each month of a specified year. (print on screen only)

Example output format is:

1905

January: 196.4 kWh/m2

February: 200.3 kWh/m2

March: No Data

...

4. Average wind speed (km/h), average ambient air temperature and total solar radiation in kWh/m2 for each month of a specified year. (write to a file called "WindTempSolar.csv")

Output Format:

Year

Month,Average Wind Speed, Average Ambient Temperature, Solar Radiation

Example output format is:

1905

January,5.5,25.5,196.4

February,4.5,27.5,200.3

...

Year is printed on the first line and the subsequent lines list the month and the average wind speed, average ambient air temperature and the total solar radiation for each month. The values are comma separated.

For menu item 4: If data is not available for any month, do not output the month. In the example, March 1905 has no data. Nothing is output for March. If the entire year's data is not available, output just the year on the first line and the message "No Data" on the second line.

5. Exit the program.

The user specifies the year and/or month. Your program asks for these on the command line and the user types in the required values and presses the "Enter" key. Date and month entries on the command line must be numeric. For example, the user types in the value 1 and not the

string January or Jan to represent the first month of the year.

Although there a number of data columns in the data file, you will only use columns with labels WAST (date and time), S (Wind Speed), SR (Solar Radiation) and T (Ambient air temperature).

Convert units carefully as the output units are not all the same as the units in the data files. For example input column S is in m/s but the output needed is km/h. The units for solar radiation in the input data file and the output are also not the same.

Processing:

Your program loads the data first from the data folder.

The program for assignment 1 will read only one input data file from the data folder. Do not read data files from anywhere else other than this folder.

After loading the data into the required data structures (see below), your program displays the menu to the user. The required data structures (see below) must be used for menu items 1 to 4.

Make sure the design is modular to cater for future iterations of the assignment requirements.

DATE.CPP

#include "Date.h" Date::Date() // Default Constructor { d_day = 0; d_month = 0; d_year = 0; } Date::Date(int day, int month, int year) // Parameter Constructor { d_day = day; d_month = month; d_year = year; } Date::~Date() { } // Getter and Setter void Date::setDay(int day) { d_day = day; } int Date::getDay() const { return d_day; } void Date::setMonth(int month) { d_month = month; } int Date::getMonth() const { return d_month; } void Date::setYear(int year) { d_year = year; } int Date::getYear() const { return d_year; } void Date::setFullDate(int day, int month, int year) { d_day = day; d_month = month; d_year = year; } // Input Statements istream & operator >> (istream & input, Date & dateObject) { string day,month,year; getline(input,day,'/'); getline(input,month,'/'); getline(input,year); dateObject.setDay(stoi(day)); dateObject.setMonth(stoi(month)); dateObject.setYear(stoi(year)); return input; } // Output Statements ostream & operator << (ostream & os, const Date & dateObject) { os << "Date : " << dateObject.getDay() << "/" << dateObject.getMonth() << "/" << dateObject.getYear() << endl; return os; } 

DATE.H

#ifndef DATE_H #define DATE_H #include #include /** * @class Date * @brief Date Class is created to store the day, month and year * @author Tan Hong Rui Freeman * @version 01 * @date 23/02/2021 Freeman Tan, Started * */ using namespace std; class Date { public: Date(); // default constructor /** * @brief Default Constructor for Date * @details An default constructor that is empty */ Date(int day, int month, int year); // Parameters constructor /** * @brief Parameter Constructor for Date * @details An parameter constructor that is use to create or name the objects by variables. */ ~Date(); // Setter Variables void setDay(int day); /** * @brief setter for the Day * @param day represents private d_day * @post day is changed */ void setMonth(int month); /** * @brief setter for the Month * @param month represents private d_month * @post month is changed */ void setYear(int year); /** * @brief setter for the Year * @param year represents private d_year * @post year is changed */ void setFullDate(int day, int month, int year); // Getter Variables int getDay() const; /** * @brief getter for the Day * @pre d_day object must be initialised * @return the Day */ int getMonth() const; /** * @brief getter for the Month * @pre d_month object must be initialised * @return the Month */ int getYear() const; /** * @brief getter for the Year * @pre d_year object must be initialised * @return the Year */ private: int d_day; int d_month; int d_year; }; ostream & operator << (ostream & os, const Date & dateObject); /** * @brief an overload output operator. Use to output the object or result * @param ostream is reference to OS. That is use for the output stream using the #include  header * @param dateObject is just a object variable name that we created for Date.CPP ostream operator. */ istream & operator >> (istream & input, Date & dateObject); /** * @brief an overload input operator. Use to get input from the user or files * @param istream is reference to input. That is use for the input stream using the #include  header * @param dateObject is just a object variable name that we created for Date.CPP istream operator. */ #endif // DATE_H 

TIME.CPP

#include  #include "Time.h" // Default Constructor Time::Time() { hour = 0; minute = 0; } // Parameter Constructor Time::Time(int hr, int minu) { hour = hr; minute = minu; } // Setter void Time::setHour(int hr) { hour = hr; } void Time::setMinute(int minu) { minute = minu; } void Time::setFullTime(int hr, int minu) { hour = hr; minute = minu; } // Getter int Time::getHour() const { return hour; } int Time::getMinute() const { return minute; } // Input Statements istream & operator >> (istream & input, Time & timeObject) { string hour,minute; getline(input,hour,':'); getline(input,minute); timeObject.setHour(stoi(hour)); timeObject.setMinute(stoi(minute)); //timeObject.setFullTime(stoi(time)); return input; } ostream & operator << (ostream & os, const Time & timeObject) { os << timeObject.getHour() << ":" << timeObject.getMinute() << endl;  return os; } 

TIME.H

#ifndef TIME_H #define TIME_H #include  using namespace std; class Time { public: Time(); Time(int hr, int minu); void setHour(int hr); void setMinute(int minu); void setFullTime(int hr, int minu); int getHour() const; int getMinute() const; private: int hour; int minute; }; ostream & operator << (ostream & os, const Time & timeObject); istream & operator >> (istream & input, Time & timeObject); #endif // TIME_H 

WINDLOG.CPP

#include "WindLog.h" WindLog::WindLog() { dateObj = Date(0,0,0); timeObj = Time(0,0); speed = 0; } WindLog::WindLog(Date d, Time t, float speeds) { dateObj = d; timeObj = t; speed =speeds; } void WindLog::setDate(Date d) { dateObj = d; } void WindLog::setTime(Time t) { timeObj = t; } void WindLog::setSpeed(float speeds) { speed = speeds; } Date WindLog::getDate() const { return dateObj; } Time WindLog::getTime() const { return timeObj; } float WindLog::getSpeed() const { return speed; } ostream& operator << (ostream& os, const WindLog& windlogObj) { os<< windlogObj.getDate() << " " << windlogObj.getTime() << " " << windlogObj.getSpeed(); return os; } istream& operator >> (istream& input, WindLog& windlogObj) { Date d; Time t; string speed; input >> d; windlogObj.setDate(d);  input >> t; windlogObj.setTime(t); getline(input,speed); windlogObj.setSpeed(stof(speed)); return input; } 

WINDLOG.H

#ifndef WINDLOG_H #define WINDLOG_H #include  #include "Date.h" #include "Time.h" #include "Vector.h" // your Template Vector class from this lab using namespace std; class WindLog { public: WindLog(); WindLog(Date d, Time t, float speeds); void setDate(Date d); void setTime(Time t); void setSpeed(float speeds); Date getDate() const; Time getTime() const; float getSpeed() const; private: Date dateObj; Time timeObj; float speed; }; /** * @brief Overload output operator. * To print object * * @param ostream& osObject, WindlogType& timeObj * @return ostream&. */ ostream& operator << (ostream& os, const WindLog& windlogObj); /** * @brief Overload input operator. * To input value into object * * @param istream& osObject, WindlogType& timeObj * @return istream&. */ istream& operator >> (istream& input, WindLog& windlogObj); #endif // WINDLOGTYPE_H 

MAIN.CPP

#include  #include  #include "WindLog.h" using namespace std; int main() { ifstream infile( "data/MetData_Mar01-2014-Mar01-2015-ALL.csv" ); if( !infile ) { return -1; } else { WindLog windObj; infile >> windObj; cout<<"Outputting Results in \"output.txt\" "<< endl; ofstream ofile( "output.txt" ); ofile << windObj << "Date: " << windObj.getDate() << " " << "Time: " << windObj.getTime() << " " << "Speed: " << windObj.getSpeed(); return 0; } } 

VECTOR.H

#ifndef Vector_H #define Vector_H //----------------------------- // Includes #include  #include  #include  #include  #include  using namespace std; template  class Vector { public: Vector();// default constructor Vector(int n); // parameter constructor ~Vector();//destructor //Functions // void create(int n); void push_back(const T& i); void pop_back(); void print() const; void resize(int newsize); int size() const; int capSize() const; T& at(int i); //Array Functions bool isEmpty() const; bool isFull() const; private: T *list; int m_capacity; int m_size; }; // implementation in the .h file template  Vector::Vector() // Default constructor { } template  Vector::Vector(int n) // parameter constructor { // create(2); list = new T[n]; //Array of size n m_size = n; m_capacity = 0; } template  Vector::~Vector() //destructor {   delete[]list; } /* template  void Vector::create(int n) { list = new T[n]; //Array of size n m_size = n; m_capacity = 0; } */ template  void Vector::push_back(const T& i) { if (m_capacity >= m_size) { resize(m_size * 2); //increase the array size } list[m_capacity] = i; m_capacity++; //increase the m_capacity to keep track } template  void Vector::pop_back() { m_capacity--; } template  void Vector::print() const { for (int i = 0; i < m_capacity; i++) { cout << list[i] << " "; cout << endl; } } template  int Vector::size() const { return m_capacity; } template  void Vector::resize(int newSize) { T *newList = new T[newSize]; T *newListPointer = newList; T *oldListPointer = list; //copy data from old array to new array while (oldListPointer != (list + m_capacity)) //while not yet at a blank position { *(newListPointer) = *(oldListPointer); //copy the value to the new position newListPointer++; //shift the pointer oldListPointer++; } m_size = newSize; //throw away old Array delete[] list; list = newList; } template  int Vector::capSize() const { return m_size; } template  T& Vector::at(int i) { if ((i >= 0) && (i bool Vector::isEmpty() const { return (m_capacity == 0); } template  bool Vector::isFull() const { return (m_capacity == m_size); } #endif // Vector_H 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions