mercredi 21 octobre 2020

How do I find the average of the whole class?

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct Students
{
    char name[30];
    char first_name[30];
    int n1;
    int n2;
    int n3;
}student list[10];

    int n;
void reading_student_list()
{
    int i;
    ifstream f("in.txt");
    f>>n;
    for(i=0;i<n;i++)
    {
        f>>student_list[i].name;
        f>>student_list[i].first_name;
        f>>student_list[i].n1;
        f>>student_list[i].n2;
        f>>student_list[i].n3;
    }
    f.close();
}
void showing_student_list()
{
    int i;
    ofstream g("out.txt");
    g<<"\n Student list: ";
    for(i=0;i<n;i++)
    {
        g<<"\n\n";
        g<<student_list[i].name<<" ";
        g<<student_list[i].first_name<<" ";
        g<<student_list[i].n1<<" ";
        g<<student_list[i].n2<<" ";
        g<<student_list[i].n3<<" ";
        g<<endl<<"Average: "<<float(student_list[i].n1+student_list[i].n2+student_list[i].n3)/3;
    }
    cout<<"\n Open file out.txt";
    g.close();
}
    int main()
    {
        reading_student_list();
        showing_student_list();
    }

I did the average for the grades per student, but I can't figure out how to find the average for the whole class.

After doing the average for the whole class, I can figure out the students that have their average below average of the class and the highest average of the class.

Aucun commentaire:

Enregistrer un commentaire