Guest User

Untitled

a guest
Apr 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include <cstdlib>
  6. #include "../Practice/date.h"
  7. #include "../Practice/time.h"
  8. #include "../Practice/weatherdata.h"
  9.  
  10. using namespace std;
  11.  
  12. istream & operator >>( istream & input, Date & D )
  13. {
  14. string temp;
  15. string convertToInt;
  16. int tempDay;
  17. int tempMonth;
  18. int tempYear;
  19.  
  20. getline(input, temp);
  21. stringstream ss(temp);
  22. getline(ss, convertToInt, '/');
  23. tempDay = atoi(convertToInt.c_str());
  24. D.SetDay(tempDay);
  25. getline(ss, convertToInt, '/');
  26. tempMonth = atoi(convertToInt.c_str());
  27. D.SetMonth(tempMonth);
  28. getline(ss, convertToInt);
  29. tempYear = atoi(convertToInt.c_str());
  30. D.SetYear(tempYear);
  31.  
  32. return input;
  33. }
  34.  
  35. ostream & operator <<( ostream & os, const Date & D )
  36. {
  37.  
  38. os << D.GetDay() << "/" << D.GetMonth()
  39. << "/" << D.GetYear();
  40.  
  41. return os;
  42. }
  43.  
  44. istream & operator >>( istream & input, Time & T )
  45. {
  46. string temp;
  47. string convertToInt;
  48. int tempHours;
  49. int tempMinutes;
  50.  
  51. getline(input, temp);
  52. stringstream ss(temp);
  53. getline(ss, convertToInt, ':');
  54. tempHours = atoi(convertToInt.c_str());
  55. T.SetHours(tempHours);
  56. getline(ss, convertToInt);
  57. tempMinutes = atoi(convertToInt.c_str());
  58. T.SetMinutes(tempMinutes);
  59.  
  60. return input;
  61. }
  62.  
  63. ostream & operator <<( ostream & os, const Time & T )
  64. {
  65.  
  66. os << T.GetHours() << ":" << T.GetMinutes();
  67.  
  68. return os;
  69. }
  70.  
  71. istream & operator >>( istream & input, WeatherData & W )
  72. {
  73. string temp;
  74. string convertToDouble;
  75. Date tempDate;
  76. Time tempTime;
  77. double tempDP;
  78.  
  79. input >> tempDate >> tempTime;
  80. W.setDate(tempDate);
  81. W.setTime(tempTime);
  82. getline(input, temp);
  83. stringstream ss(temp);
  84. getline(ss, convertToDouble);
  85. tempDP = atof(convertToDouble.c_str());
  86. W.setDP(tempDP);
  87.  
  88. return input;
  89. }
  90.  
  91. ostream & operator <<( ostream & os, const WeatherData & W )
  92. {
  93.  
  94. os << W.getDate() << ' ' << W.getTime() << ' ' << W.getDP();
  95.  
  96. return os;
  97. }
  98.  
  99. int main()
  100. {
  101. ifstream infile( "data.txt" );
  102. if( !infile ) return -1;
  103.  
  104. WeatherData W;
  105.  
  106. infile >> W;
  107.  
  108. cout << W;
  109.  
  110. return 0;
  111. }
  112.  
  113. #ifndef WEATHERDATA_H
  114. #define WEATHERDATA_H
  115.  
  116. #include "date.h"
  117. #include "time.h"
  118.  
  119. class WeatherData
  120. {
  121. public:
  122. WeatherData();
  123. WeatherData(const Date D, const Time T, double DP);
  124.  
  125. void setDate(Date tempDate);
  126. Date getDate() const;
  127.  
  128. void setTime(Time tempTime);
  129. Time getTime() const;
  130.  
  131. void setDP(double tempDP);
  132. double getDP() const;
  133.  
  134. private:
  135. double DP;
  136. Date date;
  137. Time time;
  138.  
  139. };
  140.  
  141. #endif // WEATHERDATA_H
  142.  
  143. #include <iostream>
  144. #include "WeatherData.h"
  145.  
  146. using namespace std;
  147.  
  148. WeatherData::WeatherData()
  149. {
  150. DP = 0.0;
  151. }
  152.  
  153. WeatherData::WeatherData(const Date D, const Time T, double DP)
  154. {
  155. date = D;
  156. time = T;
  157. DP = DP;
  158. }
  159.  
  160. void WeatherData::setDate(Date tempDate)
  161. {
  162. date = tempDate;
  163. }
  164.  
  165. Date WeatherData::getDate() const
  166. {
  167. return date;
  168. }
  169.  
  170. void WeatherData::setTime(Time tempTime)
  171. {
  172. time = tempTime;
  173. }
  174.  
  175. Time WeatherData::getTime() const
  176. {
  177. return time;
  178. }
  179.  
  180. void WeatherData::setDP(double tempDP)
  181. {
  182. DP = tempDP;
  183. }
  184.  
  185. double WeatherData::getDP() const
  186. {
  187. return DP;
  188. }
  189.  
  190. #ifndef DATE_H
  191. #define DATE_H
  192.  
  193. #include <iostream>
  194. #include <string>
  195.  
  196. using namespace std;
  197.  
  198. class Date {
  199. public:
  200.  
  201. Date();
  202. Date( int d, int m, int y );
  203. void SetDay(int d);
  204. void SetMonth(int m);
  205. void SetYear(int y);
  206. int GetDay() const;
  207. int GetMonth() const;
  208. int GetYear() const;
  209.  
  210. private:
  211. int day;
  212. int month;
  213. int year;
  214. };
  215.  
  216. #endif
  217.  
  218. #include "date.h"
  219.  
  220. Date::Date()
  221. {
  222. day = 0;
  223. month = 0;
  224. year = 0;
  225. }
  226.  
  227. Date::Date( int d, int m, int y )
  228. {
  229. day = d;
  230. month = m;
  231. year = y;
  232. }
  233.  
  234. void Date::SetDay(int d){
  235. day = d;
  236. }
  237.  
  238. void Date::SetMonth(int m) {
  239. month = m;
  240. }
  241.  
  242. void Date::SetYear(int y) {
  243. year = y;
  244. }
  245.  
  246. int Date::GetDay() const {
  247. return day;
  248. }
  249.  
  250. int Date::GetMonth() const {
  251. return month;
  252. }
  253.  
  254. int Date::GetYear() const {
  255. return year;
  256. }
  257.  
  258. #ifndef TIME_H
  259. #define TIME_H
  260.  
  261. #include <iostream>
  262. #include <string>
  263.  
  264. using namespace std;
  265.  
  266. class Time {
  267. public:
  268.  
  269. Time();
  270. Time( int h, int m );
  271. void SetHours(int h);
  272. void SetMinutes(int m);
  273. int GetHours() const;
  274. int GetMinutes() const;
  275.  
  276. private:
  277. int hours; /// hour of the day - 24 hour format
  278. int minutes; /// minutes of the hour
  279. };
  280.  
  281. #endif
  282.  
  283. #include "time.h"
  284.  
  285. Time::Time()
  286. {
  287. hours = 0;
  288. minutes = 0;
  289. }
  290.  
  291. Time::Time( int h, int m )
  292. {
  293. hours = h;
  294. minutes = m;
  295. }
  296.  
  297. void Time::SetHours(int h)
  298. {
  299. hours = h;
  300. }
  301.  
  302. void Time::SetMinutes(int m)
  303. {
  304. minutes = m;
  305. }
  306.  
  307. int Time::GetHours() const
  308. {
  309. return hours;
  310. }
  311.  
  312. int Time::GetMinutes() const
  313. {
  314. return minutes;
  315. }
Add Comment
Please, Sign In to add comment