12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
#include <iostream> #include <iomanip> #include <fstream> using namespace std; double getAvg(double, double, double, double); int main () { double test1; double test2; double test3; double test4; double average; ifstream inData; ofstream outData; inData.open("tests.txt"); outData.open("Lab5a_2_Output.txt"); outData << fixed << showpoint << setprecision(1); outData << "Test 1" << setw(10) << "Test 2" << setw(10) << "Test 3" << setw(10) << "Test 4" << setw(10) << "Average" << endl; while( inData ) { inData >> test1 >> test2 >> test3 >> test4; average = getAvg(test1, test2, test3, test4); outData << test1 << setw(10) << test2 << setw(10) << setw(10) << test3 << setw(10) << test4 << setprecision(2) << setw(10) << average << endl; outData << setprecision(1); } inData.close(); outData.close(); return 0; } double getAvg(double test1, double test2, double test3, double test4) { double lowest = test1; double sum; if (test2 < lowest) lowest = test2; else if(test3 < lowest) lowest = test3; else if(test4 < lowest) lowest = test4; sum = test1 + test2 + test3 + test4; sum = sum - lowest; sum = sum / 3; return sum; }