1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
//
const char duom[] = "d.txt";
const char rez[] = "r.txt";
const int size = 30;
//
void skaityti(int U[], int &n);
void spausdinti(double klvid, double mvid, double vvid, int v, int m);
void vidurkis(int U[], int &n, double &klvid, double &mvid, double &vvid, int &v, int &m);
//
int main()
{
int U[size], n, klsum, klmsum, klvsum, v = 0, m = 0;
double klvid = 0, mvid = 0, vvid = 0;
skaityti(U, n);
vidurkis(U, n, klvid, mvid, vvid, v, m);
spausdinti(klvid, mvid, vvid, v, m);
return 0;
}
//
void skaityti(int U[], int &n)
{
ifstream in(duom);
in >> n;
for(int i = 0; i != n; i++)
{
in >> U[i];
}
in.close();
}
//
void vidurkis(int U[], int &n, double &klvid, double &mvid, double &vvid, int &v, int &m)
{
int klsum = 0, klmsum = 0, klvsum = 0;
klvid, mvid, vvid, m, v;
for(int i = 0; i != n; i++)
{
klsum += abs(U[i]);
if(U[i] > 0)
{
klmsum += U[i];
m++;
}
else
{
v++;
klvsum += abs(U[i]);
}
}
klvid = (double)klsum / n;
mvid = (double)klmsum / m;
vvid = (double)klvsum / v;
}
//
void spausdinti(double klvid, double mvid, double vvid, int v, int m)
{
ofstream out(rez);
out << "Klases vidutinis ugis yra: " << fixed << setprecision(1) << klvid << endl;
out << "Klases merginu vidutinis ugis yra: " << fixed << setprecision(2) << mvid << endl;
out << "Klases vaikinu vidutinis ugis yra: " << fixed << setprecision(2) << vvid << endl;
if(v > 7 && vvid >= 175) out << "Vaikinu komanda galima sudaryti" << endl;
else out << "Vaikinu komandos negalima sudaryti" << endl;
if(m > 7 && mvid >= 175) out << "Merginu komanda galima sudaryti" << endl;
else out << "Merginu komandos negalima sudaryti" << endl;
out.close();
}
| |