Odpowiedź:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string imie, nazwisko;
double srednia;
fstream odczyt;
odczyt.open("zad01.txt" ,ios::in);
if (odczyt.good() == false)
{
cout << "Nie zlokalizowano pliku" << endl;
exit(0);
}
string l;
int nr_l=1;
int s1, s2, s3;
while (getline(odczyt,l))
{
switch (nr_l)
{
case 1: imie = l; break;
case 2: nazwisko = l; break;
case 3: s1 = atoi(l.c_str()); break;
case 4: s2 = atoi(l.c_str()); break;
case 5: s3 = atoi(l.c_str()); break;
}
nr_l++;
}
odczyt.close();
cout << imie << endl;
cout << nazwisko << endl;
cout << ((s1 + s2 + s3) / 3.0);
}
Wyjaśnienie: