Загрузка данных


#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;

class STUDENT
{
private:
    char FIO[80];
    int Group;
    int Marks[4];

public:
    bool ReadFromFile(ifstream &in)
    {
        char Mas[50];
        if (in.eof()) return false;

        in.getline(Mas, '\n');
        if (in.eof()) return false;
        strcpy(FIO, Mas);

        in.getline(Mas, '\n');
        Group = atoi(Mas);

        for (int j = 0; j < 4; j++)
        {
            in.getline(Mas, '\n');
            Marks[j] = atoi(Mas);
        }
        return true;
    }

    double AverageMark() const
    {
        double sum = 0;
        for (int j = 0; j < 4; j++)
            sum += Marks[j];
        return sum / 4.0;
    }

    bool HasHighAverage() const { return AverageMark() > 4.0; }

    void Print() const
    {
        cout << FIO << "  группа " << Group
             << "  (средний балл = " << AverageMark() << ")" << endl;
    }
};

int main()
{
    const int N = 10;
    STUDENT students[N];
    int count = 0;

    ifstream in_data("data.txt");
    if (!in_data.is_open())
    {
        cout << "Не удалось открыть файл data.txt" << endl;
        return 1;
    }

    while (count < N && students[count].ReadFromFile(in_data))
        count++;

    in_data.close();

    int found = 0;
    cout << "Студенты со средним баллом выше 4.0:\n";
    for (int i = 0; i < count; i++)
    {
        if (students[i].HasHighAverage())
        {
            students[i].Print();
            found++;
        }
    }

    if (found == 0)
        cout << "Таких студентов нет." << endl;

    return 0;
}