// Arup Guha
// 9/26/2011
// Written in COP 3223H to show the use of input and output files.
// Takes a file with grades of students (weighted 10%,20%,30%,40%)
// and prints out each student's average to a file.
#include <stdio.h>

int main() {

    FILE* ifp;
    FILE* ofp;

    // Open both files.
    ifp = fopen("grades.txt", "r");
    ofp = fopen("class.txt", "w");

    int numstudents;
    fscanf(ifp, "%d", &numstudents);

    // Go through each student.
    int stud_num;
    for (stud_num=1; stud_num<=numstudents; stud_num++) {

        // Calculate and print out their grade.
        int g1, g2, g3, g4;
        fscanf(ifp, "%d%d%d%d", &g1, &g2, &g3, &g4);

        double avg = .1*g1 + .2*g2 + .3*g3 + .4*g4;
        fprintf(ofp, "Student %d: %.2lf\n", stud_num, avg);

    }

    fclose(ofp);
    fclose(ifp);
    return 0;
}
