Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Первый файл с мейном, назвать как хотите
- --------------------
- #include "Tree.h"
- int
- main (void)
- {
- double MaxEl;
- int FirstMax, LastMax;
- int i = MyFunc ("Input.txt", &MaxEl, &FirstMax, &LastMax);
- cout << MaxEl << " " << FirstMax << " " << LastMax << "\n";
- cout << i << "/n";
- return 0;
- }
- --------------------
- Аш-файн,назвать Tree.h
- --------------------
- #ifndef TREE_H_
- #define TREE_H_
- #include <fstream>
- #include <string>
- #include <iostream>
- int
- MyFunc (string Name, double * x, int * z, int * y );
- #endif
- --------------------
- Файл с функцией, назвать как хотите
- --------------------
- #include "Tree.h"
- using namespace std;
- int MyFunc (string Name, double * x, int *z, int *y)
- {
- ifstream file (Name);
- double Buf, Max;
- int n, m, len = 0;
- while (!file.eof())
- {
- if ( file >> Buf)
- {
- len ++;
- if (len == 1 )
- {
- Max = Buf;
- n = 1;
- m = 1;
- }
- else
- {
- if (Buf > Max)
- {
- n = len;
- m = len;
- Max = Buf;
- }
- else if (Buf == Max)
- {
- m = len;
- }
- }
- }
- else
- {
- file.close();
- return 2;//проблемы с числом
- }
- }
- if (len == 0)
- {
- file.close();
- return 1;//пустая посл
- }
- file.close();
- *x = Max;
- *z = n;
- *y = m;
- return 0;
- }
- --------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement