9 {
10
11 ifstream file;
12 file.open("temperature.txt");
13 if (file.fail()) {
14 cout << "Error in file opening!" << endl;
15 exit(1);
16 }
17 ofstream average_file;
18 average_file.open("average.txt");
19 if ( average_file.fail() ) {
20 cout << "Error in file opening!" << endl;
21 exit(1);
22 }
23 string one_line;
24 average_file << fixed << setprecision(1);
25
26 while(getline(file, one_line)){
27 string date;
28 int count = 0;
29 double sum = 0;
30 istringstream line_stream(one_line);
31 line_stream >> date;
32 double temperature;
33
34 while(line_stream >> temperature){
35 sum += temperature;
36 count++;
37 }
38 double average = sum / count;
39 average_file << date << " " << average << endl;
40 }
41 file.close();
42 average_file.close();
43 return 0;
44}