Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <string>
- using namespace std;
- //Функция для разделения строки на массив
- vector<double> mySplit(string s)
- {
- string delimiter = " ";
- size_t pos = 0;
- string token;
- vector<double> output;
- while ((pos = s.find(delimiter)) != string::npos)
- {
- token = s.substr(0, pos);
- //cout << token << endl;
- output.push_back(stod(token));
- s.erase(0, pos + delimiter.length());
- }
- output.push_back(stod(s));
- return output;
- }
- int main ()
- {
- //Входной файл
- string inputFileName;
- cout << "inputFileName>";
- cin >> inputFileName;
- //Выходной файл
- string outputFileName;
- cout << "outputFileName>";
- cin >> outputFileName;
- //Получаем данные из файла
- ifstream inFile(inputFileName);
- if (!inFile.is_open())
- {
- cout << "Не удалось открыть входной файл" << endl;
- return 0;
- }
- string buf; //Буфферная строка
- size_t itCount = 0; //Счётчик итераций
- vector<vector<double>> arr;
- while (getline(inFile, buf))
- {
- if (itCount)
- arr.push_back(mySplit(buf));
- itCount++;
- }
- inFile.close();
- //Выводим данные в файл
- ofstream outFile;
- outFile.open(outputFileName);
- if (!outFile.is_open())
- {
- cout << "Не удалось открыть выходной файл" << endl;
- return 0;
- }
- outFile << "x sinx cosx tgx ctgx" << endl;
- for (size_t i = 0; i < arr.size(); i++)
- {
- //Выводим исходные данные
- outFile << arr[i][0] << " " << arr[i][1] << " " << arr[i][2] << " ";
- //Выводим синус
- if ((int)arr[i][0] % 90 == 0)
- outFile << "- ";
- else
- outFile << arr[i][1]/arr[i][2] << " ";
- //Выводим косинус
- if ((int)arr[i][0] % 180 == 0)
- outFile << "-";
- else
- outFile << arr[i][2]/arr[i][1];
- outFile << endl;
- }
- outFile.close();
- return 0;
- }
Advertisement
RAW Paste Data
Copied
Advertisement