Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. static int newsID = 1;
  7. static int weatherID = 1;
  8.  
  9. class Region {
  10. private:
  11. string city;
  12. int ID;
  13. public:
  14. Region() {}
  15. Region(int _ID, string _city) {
  16. ID = _ID;
  17. city = _city;
  18. }
  19. #pragma region getters
  20. int getID() { return ID; }
  21. string getCity() { return city; }
  22. #pragma endregion
  23. };
  24. class News {
  25. private:
  26. int cityID;
  27. int NewsID;
  28. string title;
  29. string newsText;
  30. public:
  31.  
  32. News() {}
  33. News(int _cityID, string _title, string _newsText) {
  34. NewsID = newsID;
  35. cityID = _cityID;
  36. title = _title;
  37. newsText = _newsText;
  38. newsID++;
  39. }
  40. #pragma region getters
  41. int getCityID() { return cityID; }
  42. int getNewsID() { return NewsID; }
  43. string getNewsTitle() { return title; }
  44. void readNews() {
  45. cout << title << endl << endl << newsText << endl;
  46. }
  47. #pragma endregion
  48. };
  49. class Weather {
  50. private:
  51. int WeatherID;
  52. int cityID;
  53. string title;
  54. string forecast;
  55. public:
  56. Weather() {}
  57. Weather(int _cityID, string _title, string _forecast) {
  58. WeatherID = weatherID;
  59. cityID = _cityID;
  60. title = _title;
  61. forecast = _forecast;
  62. weatherID++;
  63. }
  64. #pragma region getters
  65. int getCityID() { return cityID; }
  66. int getWeatherID() { return WeatherID; }
  67. string getTitle() { return title; }
  68. string getForecast() { return forecast; }
  69. void printForecast(Region region) {
  70. cout << "Weather in " << region.getCity() << " will be " << forecast << endl;
  71. }
  72. #pragma endregion
  73. };
  74.  
  75. void menu(vector<Region> regions, vector<News> news, vector<Weather> weathers);
  76. void GetAllCitiesNewsAndWeathers(vector<Region> regions, vector<News> news, vector<Weather> weathers);
  77. void GetAllNews(vector<News> news);
  78. void GetAllWeathers(vector<Region> regions, vector<Weather> weathers);
  79. void GetNewsByCity(vector<News> news, Region temp);
  80. void GetWeatherByCity(vector<Weather> weathers, Region temp);
  81. void print(string text);
  82.  
  83. int main() {
  84. vector<Region> Regions{
  85. *new Region(1, "Tbilisi"),
  86. *new Region(2, "Batumi"),
  87. *new Region(3, "Gori"),
  88. *new Region(4, "Qutaisi")
  89. };
  90.  
  91. vector<Weather> Weathers{
  92. *new Weather(1,"Tbilisis amindi", "38 gradusi"),
  93. *new Weather(2,"Bautmi amindi", "41 gradusi"),
  94. *new Weather(3,"Gori amindi", "15 gradusi"),
  95. *new Weather(4,"Qutaisi amindi", "39 gradusi")
  96. };
  97. vector<News> news{
  98. *new News(1,"Archevnebi","Meris archevnebi iwkeba 12 oqtombers"),
  99. * new News(1,"R2","ERROR"),
  100. * new News(2,"Archevnebi","Meris archevnebi iwkeba 12 oqtombers"),
  101. * new News(2,"temp","Meris archevnebi iwkeba 12 oqtombers"),
  102. * new News(3,"Archevnebi","Meris archevnebi iwkeba 12 oqtombers"),
  103. * new News(3,"temp","Meris archevnebi iwkeba 12 oqtombers"),
  104. * new News(4,"Archevnebi","Meris archevnebi iwkeba 12 oqtombers"),
  105. * new News(4,"temp","Meris archevnebi iwkeba 12 oqtombers")
  106. };
  107.  
  108. menu(Regions, news, Weathers);
  109.  
  110.  
  111.  
  112. std::cin.get();
  113. std::cin.get();
  114. return 0;
  115. }
  116.  
  117. void menu(vector<Region> regions, vector<News> news, vector<Weather> weathers)
  118. {
  119. system("cls");
  120. print("1) Check news and weathers by Regions");
  121. print("2) Check all news");
  122. print("3) Check all weathers");
  123. int choose;
  124. std::cin >> choose;
  125. switch (choose)
  126. {
  127. case 1:
  128. GetAllCitiesNewsAndWeathers(regions, news, weathers);
  129. break;
  130. case 2:
  131. GetAllNews(news);
  132. break;
  133. case 3:
  134. GetAllWeathers(regions, weathers);
  135. break;
  136. default:
  137. break;
  138. }
  139. }
  140.  
  141. void GetAllCitiesNewsAndWeathers(vector<Region> regions, vector<News> news, vector<Weather> weathers)
  142. {
  143. system("cls");
  144. int ID;
  145. int infoType;
  146. Region instance;
  147. for (auto item : regions)
  148. {
  149. cout << item.getID() << ") " << item.getCity() << endl;
  150. }
  151.  
  152. print("Enter ID of city: ");
  153. std::cin >> ID;
  154. for (auto item : regions)
  155. {
  156. if (ID == item.getID()) {
  157. instance = item;
  158. }
  159. }
  160. system("cls");
  161. print("1) Check news for the city");
  162. print("2) Check weather for the city");
  163. std::cin >> infoType;
  164.  
  165. switch (infoType)
  166. {
  167. case 1:
  168. GetNewsByCity(news, instance);
  169. break;
  170. case 2:
  171. GetWeatherByCity(weathers, instance);
  172. break;
  173. default:
  174. break;
  175. }
  176. }
  177.  
  178. void GetAllNews(vector<News> news)
  179. {
  180. system("cls");
  181. int index;
  182. for (auto item : news)
  183. {
  184. cout << item.getNewsID() << ") " << item.getNewsTitle()<< endl;
  185. }
  186. print("Enter the index of news you are interested in : ");
  187. std::cin >> index;
  188. for (auto item : news)
  189. {
  190. if (item.getNewsID() == index)
  191. {
  192. item.readNews();
  193. }
  194. }
  195. }
  196.  
  197. void GetAllWeathers(vector<Region> regions, vector<Weather> weathers)
  198. {
  199. system("cls");
  200. int index;
  201. Weather wInstance;
  202. Region rInstance;
  203. for (auto item : weathers)
  204. {
  205. cout << item.getWeatherID() << ") " << item.getTitle();
  206. }
  207. print("Enter the index of weather you are interested in : ");
  208. std::cin >> index;
  209.  
  210. for (auto item : weathers)
  211. {
  212. if (item.getWeatherID() == index) {
  213. wInstance = item;
  214. }
  215. }
  216. for (auto item : regions)
  217. {
  218. if (item.getID() == wInstance.getCityID()) {
  219. rInstance = item;
  220. }
  221. }
  222. wInstance.printForecast(rInstance);
  223. }
  224.  
  225. void GetNewsByCity(vector<News> news, Region temp)
  226. {
  227. system("cls");
  228. int newsID;
  229.  
  230. for (auto item : news)
  231. {
  232. if (item.getCityID() == temp.getID()) {
  233. cout << item.getNewsID() << ") " << item.getNewsTitle()<< endl;
  234. }
  235. }
  236. print("Enter the index of news you are interested in: ");
  237. std::cin >> newsID;
  238.  
  239. for (auto item : news)
  240. {
  241. if (item.getNewsID() == newsID) {
  242. item.readNews();
  243. }
  244. }
  245. }
  246.  
  247. void GetWeatherByCity(vector<Weather> weathers, Region temp)
  248. {
  249. system("cls");
  250. int newsID;
  251.  
  252. for (auto item : weathers)
  253. {
  254. if (item.getCityID() == temp.getID()) {
  255. cout << item.getWeatherID() << ") " << item.getTitle() << endl;
  256. }
  257. }
  258. print("Enter the index of news you are interested in: ");
  259. std::cin >> newsID;
  260.  
  261. for (auto item : weathers)
  262. {
  263. if (item.getWeatherID() == newsID) {
  264. item.printForecast(temp);
  265. }
  266. }
  267. }
  268.  
  269. void print(string text)
  270. {
  271. cout << text << endl;
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement