#include #include #include using namespace std; int main() { ifstream in("animals.txt"); if (in.fail()) { cout << "Can't open animals.txt\n"; exit(1); } ofstream out("gorillas.txt"); if (out.fail()) { cout << "Can't open gorillas.txt\n"; exit(1); } double totlwt = 0.0; int totlnum = 0; double slowg = 9999999999.9; while (true) { int time; string species, dir; double weight, speed; in >> time >> species >> dir >> weight >> speed; if (in.fail()) break; if (species == "gorilla") out << time << " " << species << " " << dir << " " << weight << " " << speed << "\n"; if (species == "lion") { totlwt += weight; totlnum += 1; } if (species == "gorilla" && dir == "E" && time >= 0 && time <= 1200 && speed < slowg) slowg = speed; } in.close(); out.close(); if (totlnum != 0) cout << "Average lion weight " << totlwt / totlnum << "\n"; else cout << "Average lion weight 0.0\n"; cout << "Slowest ... " << slowg << " mph\n"; }