evage

Untitled

Nov 19th, 2021 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. int findMaxElement(vector<int> ar) {
  8.     int maxEl = *max_element(ar.begin(), ar.end());
  9.     return maxEl;
  10. }
  11. float findMaxElement(vector<float> ar) {
  12.     float maxEl = *max_element(ar.begin(), ar.end());
  13.     return maxEl;
  14. }
  15. double findMaxElement(vector<double> ar) {
  16.     double maxEl = *max_element(ar.begin(), ar.end());
  17.     return maxEl;
  18. }
  19. int main() {
  20.     ofstream out_file;
  21.     ifstream in_file;
  22.  
  23.     string ofile, ifile;
  24.     cout << "Enter source file directory. Example: \"C:\\file.txt\"\n";
  25.     cin >> ifile;
  26.  
  27.     in_file.open(ifile, ifstream::in);
  28.     if (!in_file.is_open())
  29.     {
  30.         cout << "No such file directory";
  31.         return -1;
  32.     }
  33.  
  34.     cout << "Enter destiny file directory. Example: \"C:\\file.txt\"\n";
  35.     cin >> ofile;
  36.  
  37.     out_file.open(ofile, ifstream::out);
  38.     if (!out_file.is_open())
  39.     {
  40.         cout << "No such file directory";
  41.         return -1;
  42.     }
  43.  
  44.     vector<double> data;
  45.     double temp;
  46.     while ((in_file >> temp))
  47.         data.push_back(temp);
  48.  
  49.     double ans = findMaxElement(data);
  50.     out_file << ans;
  51.  
  52.     out_file.close(); in_file.close();
  53. }
Add Comment
Please, Sign In to add comment