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
|
#include <fstream>
#include <iostream>
using namespace std;
void ProcessARow(int id,int A1,int A2,int A3,int& max, int& min, float& avg);
int main()
{
ifstream fin;
fin.open("data.txt");
int id, A1, A2, A3, max, min;
float avg;
cout << "Std-Id \tA1 \tA2 \tA3 \tMin \tMax \tAvg\n";
cout << "--------------------S------------------------------\n";
while (fin >> id >> A1 >> A2 >> A3)
{
ProcessARow(id, A1, A2, A3, max, min, avg);
}
}
void ProcessARow(int id, int A1, int A2, int A3, int &max, int &min, float &avg)
{
int max = A1;
int min = A1;
if (A2 > max)
max = A2;
if (A3 > max)
max = A3;
if (A2 < min)
min = A2;
if (A3 < min)
min = A3;
avg = (A1 + A2 + A3) / 3.0;
cout << id << "\t" << A1 << "\t" << A2 << "\t" << A3 << "\t" << min << "\t" << max << "\t" << avg << endl;
return;
system("pause");
}
|