Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <string>
- #include <cstdlib>
- #include "../Practice/date.h"
- #include "../Practice/time.h"
- #include "../Practice/weatherdata.h"
- using namespace std;
- istream & operator >>( istream & input, Date & D )
- {
- string temp;
- string convertToInt;
- int tempDay;
- int tempMonth;
- int tempYear;
- getline(input, temp);
- stringstream ss(temp);
- getline(ss, convertToInt, '/');
- tempDay = atoi(convertToInt.c_str());
- D.SetDay(tempDay);
- getline(ss, convertToInt, '/');
- tempMonth = atoi(convertToInt.c_str());
- D.SetMonth(tempMonth);
- getline(ss, convertToInt);
- tempYear = atoi(convertToInt.c_str());
- D.SetYear(tempYear);
- return input;
- }
- ostream & operator <<( ostream & os, const Date & D )
- {
- os << D.GetDay() << "/" << D.GetMonth()
- << "/" << D.GetYear();
- return os;
- }
- istream & operator >>( istream & input, Time & T )
- {
- string temp;
- string convertToInt;
- int tempHours;
- int tempMinutes;
- getline(input, temp);
- stringstream ss(temp);
- getline(ss, convertToInt, ':');
- tempHours = atoi(convertToInt.c_str());
- T.SetHours(tempHours);
- getline(ss, convertToInt);
- tempMinutes = atoi(convertToInt.c_str());
- T.SetMinutes(tempMinutes);
- return input;
- }
- ostream & operator <<( ostream & os, const Time & T )
- {
- os << T.GetHours() << ":" << T.GetMinutes();
- return os;
- }
- istream & operator >>( istream & input, WeatherData & W )
- {
- string temp;
- string convertToDouble;
- Date tempDate;
- Time tempTime;
- double tempDP;
- input >> tempDate >> tempTime;
- W.setDate(tempDate);
- W.setTime(tempTime);
- getline(input, temp);
- stringstream ss(temp);
- getline(ss, convertToDouble);
- tempDP = atof(convertToDouble.c_str());
- W.setDP(tempDP);
- return input;
- }
- ostream & operator <<( ostream & os, const WeatherData & W )
- {
- os << W.getDate() << ' ' << W.getTime() << ' ' << W.getDP();
- return os;
- }
- int main()
- {
- ifstream infile( "data.txt" );
- if( !infile ) return -1;
- WeatherData W;
- infile >> W;
- cout << W;
- return 0;
- }
- #ifndef WEATHERDATA_H
- #define WEATHERDATA_H
- #include "date.h"
- #include "time.h"
- class WeatherData
- {
- public:
- WeatherData();
- WeatherData(const Date D, const Time T, double DP);
- void setDate(Date tempDate);
- Date getDate() const;
- void setTime(Time tempTime);
- Time getTime() const;
- void setDP(double tempDP);
- double getDP() const;
- private:
- double DP;
- Date date;
- Time time;
- };
- #endif // WEATHERDATA_H
- #include <iostream>
- #include "WeatherData.h"
- using namespace std;
- WeatherData::WeatherData()
- {
- DP = 0.0;
- }
- WeatherData::WeatherData(const Date D, const Time T, double DP)
- {
- date = D;
- time = T;
- DP = DP;
- }
- void WeatherData::setDate(Date tempDate)
- {
- date = tempDate;
- }
- Date WeatherData::getDate() const
- {
- return date;
- }
- void WeatherData::setTime(Time tempTime)
- {
- time = tempTime;
- }
- Time WeatherData::getTime() const
- {
- return time;
- }
- void WeatherData::setDP(double tempDP)
- {
- DP = tempDP;
- }
- double WeatherData::getDP() const
- {
- return DP;
- }
- #ifndef DATE_H
- #define DATE_H
- #include <iostream>
- #include <string>
- using namespace std;
- class Date {
- public:
- Date();
- Date( int d, int m, int y );
- void SetDay(int d);
- void SetMonth(int m);
- void SetYear(int y);
- int GetDay() const;
- int GetMonth() const;
- int GetYear() const;
- private:
- int day;
- int month;
- int year;
- };
- #endif
- #include "date.h"
- Date::Date()
- {
- day = 0;
- month = 0;
- year = 0;
- }
- Date::Date( int d, int m, int y )
- {
- day = d;
- month = m;
- year = y;
- }
- void Date::SetDay(int d){
- day = d;
- }
- void Date::SetMonth(int m) {
- month = m;
- }
- void Date::SetYear(int y) {
- year = y;
- }
- int Date::GetDay() const {
- return day;
- }
- int Date::GetMonth() const {
- return month;
- }
- int Date::GetYear() const {
- return year;
- }
- #ifndef TIME_H
- #define TIME_H
- #include <iostream>
- #include <string>
- using namespace std;
- class Time {
- public:
- Time();
- Time( int h, int m );
- void SetHours(int h);
- void SetMinutes(int m);
- int GetHours() const;
- int GetMinutes() const;
- private:
- int hours; /// hour of the day - 24 hour format
- int minutes; /// minutes of the hour
- };
- #endif
- #include "time.h"
- Time::Time()
- {
- hours = 0;
- minutes = 0;
- }
- Time::Time( int h, int m )
- {
- hours = h;
- minutes = m;
- }
- void Time::SetHours(int h)
- {
- hours = h;
- }
- void Time::SetMinutes(int m)
- {
- minutes = m;
- }
- int Time::GetHours() const
- {
- return hours;
- }
- int Time::GetMinutes() const
- {
- return minutes;
- }
Add Comment
Please, Sign In to add comment