#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, and
 * you'll be famous.
 */

//DO NOT ALTER THE PERCENTAGES
#define PERCENT_MIDTERM1 0.16
#define PERCENT_MIDTERM2 0.21
#define PERCENT_FINAL 0.25
#define PERCENT_LABS 0.12 //.03 of this is lab attendance, per the syllabus
#define PERCENT_PROJECTS 0.21
#define PERCENT_PARTICIPATION 0.05

//ALTER THESE NUMBERS TO REFLECT NUMBER OF GRADES YOU HAVE NOW
#define NUM_LABS 12 //labs 0-11


/*
 * 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
    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.14); //only two so far
    total += midterm1 * PERCENT_MIDTERM1;
    total += midterm2 * PERCENT_MIDTERM2;
    total += participation * PERCENT_PARTICIPATION;

    //final, project 3 not in this part
    outOf = PERCENT_LABS + 0.14 + PERCENT_MIDTERM1 + PERCENT_MIDTERM2 + PERCENT_PARTICIPATION;
    
    //printf("Amount of class grade so far: %lf\n", outOf);

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

    total += projects[2] * 0.07; //include third project
    total += final * PERCENT_FINAL;

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

    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;
}
