bogdan_obukhovskii

Untitled

Feb 28th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. void sort(string*& cityArr, double*& teArr, string*& SS, int size)
  8. {
  9. for (int i = 0; i < size - 1; i++)
  10. {
  11. for (int j = 0; j < size - 1; j++)
  12. {
  13. if (SS[j] == "F")
  14. {
  15. teArr[j] = (teArr[j] / 1, 8 + 32);
  16. SS[j] = "C";
  17. }
  18. if (teArr[j] > teArr[j + 1])
  19. {
  20. double tempValue = teArr[j];
  21. teArr[j] = teArr[j + 1];
  22. teArr[j + 1] = tempValue;
  23.  
  24. string tempString = cityArr[j];
  25. cityArr[j] = cityArr[j + 1];
  26. cityArr[j + 1] = tempString;
  27. }
  28. }
  29. }
  30.  
  31. cout << endl << endl << "******После сортировки******" << endl;
  32. for (int i = 0; i < size; i++)
  33. {
  34. cout << "Город: " << cityArr[i] << " : ";
  35. if (teArr[i] >= 0)
  36. {
  37. cout << "+" << teArr[i];
  38. }
  39. else
  40. {
  41. cout << teArr[i];
  42. }
  43. cout << "°C" << endl;
  44. }
  45.  
  46. }
  47.  
  48. string* resizeArray(string* arr, int size)
  49. {
  50. string* tempArr = arr;
  51. arr = new string[size + 1];
  52. for (int i = 0; i < size; i++)
  53. {
  54. arr[i] = tempArr[i];
  55. }
  56.  
  57. return arr;
  58. }
  59.  
  60. double* resizeArray(double* arr, int size)
  61. {
  62. double* tempArr = arr;
  63. arr = new double[size + 1];
  64. for (int i = 0; i < size; i++)
  65. {
  66. arr[i] = tempArr[i];
  67. }
  68.  
  69. return arr;
  70. }
  71.  
  72. int main()
  73. {
  74. setlocale(0, "ru");
  75.  
  76. string path = "Mas.txt";
  77. ifstream file;
  78.  
  79. file.open(path);
  80. if (!file.is_open())
  81. {
  82. cout << "Файл не найден" << endl;
  83. return 0;
  84. }
  85. else
  86. {
  87. cout << "Файл успешно открыт" << endl << endl;
  88. }
  89.  
  90. string gorod;
  91. string temperatura;
  92. string S;
  93. int countRow = 0;
  94.  
  95. string* cityArr = new string[1];
  96. double* teArr = new double[1];
  97. string* SS = new string[1];
  98.  
  99. while (!file.eof())
  100. {
  101. file >> gorod;
  102. file >> temperatura;
  103. file >> S;
  104.  
  105. cityArr[countRow] = gorod;
  106. teArr[countRow] = stod(temperatura);
  107. SS[countRow] = S;
  108.  
  109. cityArr = resizeArray(cityArr, countRow + 1);
  110. teArr = resizeArray(teArr, countRow + 1);
  111. SS = resizeArray(SS, countRow + 1);
  112.  
  113. cout << "Город: " << cityArr[countRow] << " : " << teArr[countRow] << " " << SS[countRow] << endl;
  114.  
  115. countRow++;
  116. }
  117.  
  118. sort(cityArr, teArr, SS, countRow);
  119.  
  120. file.close();
  121. system("pause");
  122. return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment