https://docs.google.com/document/d/1H8-kF2jE0MuSrao__M93YroymuTdUKxdNlAeak5MHOk/edit
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void beolvasas(vector<double> &x);
void beolvasas_file(vector<double> &x);
void fel1(const vector<double> hom, double &atlag);
void fel3(const vector<double> hom, int &leghidegebbnap);
void fel7(const vector<double> hom, bool &van, int &ind);
void ellkiiras(const vector<double> &hom);
int main()
{
//double hom[MAXN];
vector<double> hom;
//beolvasas(hom);
beolvasas_file(hom);
ellkiiras(hom);
double atlag;
fel1(hom, atlag);
cout << "Atlaghom= " << atlag << endl;
int leghidegebbnap;
fel3(hom, leghidegebbnap);
cout << "Leghidegebbnap= " << leghidegebbnap << endl;
bool van;
int ind;
fel7(hom, van, ind);
if (van)
{
cout << "= a szomszedjaval: " << ind << endl;
}
else
{
cout << "Nincs = a szomszedjaval" << endl;
}
return 0;
}
void beolvasas(vector<double> &x)
{
int n;
cout << "n=";
cin >> n;
x.resize(n);
for (int i=0; i<n; ++i)
{
cout << i << ". hom: ";
cin >> x[i];
}
}
void beolvasas_file(vector<double> &x)
{
double sv;
//ifstream f("be.txt");
ifstream f;
string fajlnev;
bool hiba;
do
{
cout << "Fajlnev: ";
cin >> fajlnev;
f.open(fajlnev.c_str());
hiba=f.fail();
if (hiba)
{
cout << "Nem jo fajlnev" << endl;
}
}
while(hiba);
/*while (!f.eof())
{
f >> sv;
if (f.good())
{
x.push_back(sv);
}
}*/
f >> sv;
while (!f.eof())
{
x.push_back(sv);
f >> sv;
}
f.close();
}
void ellkiiras(const vector<double> &hom)
{
for (int i=0; i<hom.size(); ++i)
{
cout << i << ".: " << hom[i] << endl;
}
}
void fel1(const vector<double> hom, double &atlag)
{
double s=0;
int n=hom.size();
for (int i=0; i<n; ++i)
{
s+=hom[i];
}
atlag=s/n;
}
void fel3(const vector<double> hom, int &leghidegebbnap)
{
double max=hom[0];
leghidegebbnap=0;
for (int i=0; i<hom.size(); ++i)
{
if (hom[i]<max)
{
leghidegebbnap=i;
max=hom[i];
}
}
}
void fel7(const vector<double> hom, bool &van, int &ind)
{
ind=0;
while (ind<hom.size() && hom[ind]!=hom[ind+1])
{
++ind;
}
van=ind<hom.size();
}