Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- int findMaxElement(vector<int> ar) {
- int maxEl = *max_element(ar.begin(), ar.end());
- return maxEl;
- }
- float findMaxElement(vector<float> ar) {
- float maxEl = *max_element(ar.begin(), ar.end());
- return maxEl;
- }
- double findMaxElement(vector<double> ar) {
- double maxEl = *max_element(ar.begin(), ar.end());
- return maxEl;
- }
- int main() {
- ofstream out_file;
- ifstream in_file;
- string ofile, ifile;
- cout << "Enter source file directory. Example: \"C:\\file.txt\"\n";
- cin >> ifile;
- in_file.open(ifile, ifstream::in);
- if (!in_file.is_open())
- {
- cout << "No such file directory";
- return -1;
- }
- cout << "Enter destiny file directory. Example: \"C:\\file.txt\"\n";
- cin >> ofile;
- out_file.open(ofile, ifstream::out);
- if (!out_file.is_open())
- {
- cout << "No such file directory";
- return -1;
- }
- vector<double> data;
- double temp;
- while ((in_file >> temp))
- data.push_back(temp);
- double ans = findMaxElement(data);
- out_file << ans;
- out_file.close(); in_file.close();
- }
Add Comment
Please, Sign In to add comment