Question: Please fix my code to solve the problem. C++ #include #include #include #include using namespace std; int main () { ifstream ifs(input.txt, ifstream:: in); ofstream

Please fix my code to solve the problem. C++Please fix my code to solve the problem. C++ #include #include #include

#include

#include

#include

#include

using namespace std;

int main () {

ifstream ifs("input.txt", ifstream:: in);

ofstream ofs("output.txt", ofstream::trunc);

double sum = 0;

int count = 0;

ifs.seekg(0, ios::beg);

while(ifs) {

double year;

ifs >> year;

double age = 2018 - year;

sum+= age;

ofs

count++;}

ofs

ifs.close();

ofs.close();

return 0; }

for different Problem 3 [10pt] . You are given a file called input.dat containing data records for different people, listed one per ine. Each record has the following format full name lbirth year. For example, the content of the file may be content of the Ble may be s the following format ru1i James Doe 1978 Lisa Smith|1988 Alex Taylorl 1997 Write a program which reads the file input.txt and produces a file output.txt which contains information about the age of each person from input.txt, followed by a line containing the text "Average age followed by the average age of people in input.txt (which should be output with the precision set to 1). For example, using the input.txt as above, the output.txt should be as follows 40 30 21 Average age: 30.3 Remarks. 1) You may assume that all header files are included. 2) You may assume that the input.dat contains at least one record. 3) To compute the age assume that the current year is 2018. 4) You may continue your solution onto the next page

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!