Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void sort(string*& cityArr, double*& teArr, string*& SS, int size)
- {
- for (int i = 0; i < size - 1; i++)
- {
- for (int j = 0; j < size - 1; j++)
- {
- if (SS[j] == "F")
- {
- teArr[j] = (teArr[j] / 1, 8 + 32);
- SS[j] = "C";
- }
- if (teArr[j] > teArr[j + 1])
- {
- double tempValue = teArr[j];
- teArr[j] = teArr[j + 1];
- teArr[j + 1] = tempValue;
- string tempString = cityArr[j];
- cityArr[j] = cityArr[j + 1];
- cityArr[j + 1] = tempString;
- }
- }
- }
- cout << endl << endl << "******После сортировки******" << endl;
- for (int i = 0; i < size; i++)
- {
- cout << "Город: " << cityArr[i] << " : ";
- if (teArr[i] >= 0)
- {
- cout << "+" << teArr[i];
- }
- else
- {
- cout << teArr[i];
- }
- cout << "°C" << endl;
- }
- }
- string* resizeArray(string* arr, int size)
- {
- string* tempArr = arr;
- arr = new string[size + 1];
- for (int i = 0; i < size; i++)
- {
- arr[i] = tempArr[i];
- }
- return arr;
- }
- double* resizeArray(double* arr, int size)
- {
- double* tempArr = arr;
- arr = new double[size + 1];
- for (int i = 0; i < size; i++)
- {
- arr[i] = tempArr[i];
- }
- return arr;
- }
- int main()
- {
- setlocale(0, "ru");
- string path = "Mas.txt";
- ifstream file;
- file.open(path);
- if (!file.is_open())
- {
- cout << "Файл не найден" << endl;
- return 0;
- }
- else
- {
- cout << "Файл успешно открыт" << endl << endl;
- }
- string gorod;
- string temperatura;
- string S;
- int countRow = 0;
- string* cityArr = new string[1];
- double* teArr = new double[1];
- string* SS = new string[1];
- while (!file.eof())
- {
- file >> gorod;
- file >> temperatura;
- file >> S;
- cityArr[countRow] = gorod;
- teArr[countRow] = stod(temperatura);
- SS[countRow] = S;
- cityArr = resizeArray(cityArr, countRow + 1);
- teArr = resizeArray(teArr, countRow + 1);
- SS = resizeArray(SS, countRow + 1);
- cout << "Город: " << cityArr[countRow] << " : " << teArr[countRow] << " " << SS[countRow] << endl;
- countRow++;
- }
- sort(cityArr, teArr, SS, countRow);
- file.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment