#include <stdio.h>
/* Terry Harvey  CISC 105 Section: 00  TA: Tina Weymouth */

/*
 * This program computes your approximate semester grade based on the
 * percentages from the syllabus. Assume there will be no curve;
 * typically my 105 classes have little or no curve, and grade
 * divisions come at 90, 80, etc.  
 *
 * I bet you can write a nicer version of this program that would read
 * your grades from a file and count them as it reads. If you write a
 * nice one, send it to me and I'll have other classes use it.
 */

//DO NOT ALTER THE PERCENTAGES
#define PERCENT_MIDTERM1 0.15
#define PERCENT_MIDTERM2 0.20
#define PERCENT_FINAL 0.25
#define PERCENT_LABS 0.12 //.03 of this is lab attendance, per the syllabus
#define PERCENT_PROJECTS 0.20
#define PERCENT_PARTICIPATION 0.08 //see syllabus

//ALTER THESE NUMBERS TO REFLECT NUMBER OF GRADES YOU HAVE NOW
#define NUM_PROJECTS 3
#define NUM_LABS 12 


/*
 * Calculates the contribution of a single kind of assignment. Pass
 * parameters: array of grades, num grades = size, factor is the
 * percentage that this type of assignment counts in the final grade.
 */
double calculateContribution(double grades[], int size, double factor);

int main(){

    ///PUT YOUR GRADES HERE, THEN CHANGE SIZE ABOVE
    double labs[] = {100,100,100,100,100,100,100,100,100,100,100,100};
    double midterm1 = 100;
    double midterm2 = 100;
    double projects[] = {100,100,100};//{51.4, 67.3};
    double final = 100;
    double participation = 100;
    double outOf;

    double total = 0;
    total += calculateContribution(labs, NUM_LABS, PERCENT_LABS);
    total += calculateContribution(projects, 2 , 0.13); //only two so far
    total += midterm1 * PERCENT_MIDTERM1;
    total += midterm2 * PERCENT_MIDTERM2;

    //final, project 3 not in this part
    outOf = PERCENT_LABS + 0.13 + PERCENT_MIDTERM1 + PERCENT_MIDTERM2;
    
    printf("Approximate grade BEFORE project 3 and final, out of %d: %4.2lf\n", (int)(100*outOf), total/outOf);

    total = 0;
    total += calculateContribution(labs, NUM_LABS, PERCENT_LABS);
    total += calculateContribution(projects, NUM_PROJECTS, PERCENT_PROJECTS); 
    total += midterm1 * PERCENT_MIDTERM1;
    total += midterm2 * PERCENT_MIDTERM2;
    total += final * PERCENT_FINAL;
    total += participation * PERCENT_PARTICIPATION;

    outOf = PERCENT_LABS + PERCENT_MIDTERM1 + PERCENT_MIDTERM2 + 
        PERCENT_FINAL + PERCENT_PROJECTS + PERCENT_PARTICIPATION;

    printf("Approximate grade after project 3 and final, out of %d: %4.2lf\n", 100, total/outOf);

    return 0;
}

/*
 * Calculates the contribution of a single kind of assignment. Pass
 * parameters: array of grades, num grades = size, factor is the
 * percentage that this type of assignment counts in the final grade.
 */
double calculateContribution(double grades[], int size, double factor){
    int i;
    double sum = 0;
    for (i = 0; i < size; i++){
        sum += grades[i];
    }

    return sum / size * factor;
}
