Code:
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <cmath>
#include<fstream>
double Homework ( double homework); // fuction for homework weight
double Midterm ( double midterm); // function for midterm weight
double Final ( double final); // function for final test weight
//function to calculate final grade
double CalcGrade (double homework, double midterm, double final, double totalScore, char grade);
//function to print
int Print( double homework, double midterm, double final, double totalScore, char grade);
int main()
{
//local delcarations
double homework;
double midterm;
double final;
double totalScore;
char grade;
//informs the user what this program does
printf("This program will calculate the final grade after homework\n");
printf("midterm, and final test grades are inputed in.\n");
system("cls"); //clears screen
//function calls
Homework(homework);
Midterm(midterm);
Final(final);
CalcGrade ( homework, midterm, final,totalScore, grade);
Print(homework, midterm, final, totalScore, grade);
system("pause"); //holds screen for dev C++
return 0;
} //end of main
/////////////////////////////HOMEWORK////////////
double Homework (double homework)
{
system("cls");
//function delcarations
int x ;
int i ;
double sum;
double homeworkMaxPts ;
// homework ;
//prompts users for input, and how to terminate
printf("Enter the homework assignment grades: \nEnter < 999 > to stop.\n");
do //loop to collect input for homework grades
{
scanf("%d", &x);
if ( x <900) //termination of loop
sum += x; // calculated total amount of points
}while ( x < 900);
//prompts user to input maxmum score for each assignment
printf("Enter the max points for each assignemnt: \n");
printf("Enter < 999 > to stop\n ");
//loop to collect imput for maximun points possible for homework
do
{
scanf("%d", &i);
if ( i < 900) //loop termination
homeworkMaxPts += i; // calculates total amount of points
}while ( i < 900);
//calculates the total weight of homework
homework =(sum*50/homeworkMaxPts);
system("pause");
return homework; // returns weighted homeword
} //end of homework
// Function to determine weight of midterm tests
double Midterm ( double midterm)
{
system("cls"); // clear screen
//declarations
int a=0;
int i=1;
double sum;
int x =1;
double midMaxPts = 0;
int b=0;
//midterm =0;
// prompts user to input midterm grades
printf("Enter the midterm grades: \n");
//loop to calculate total midterm points
while(i<=3)
{
scanf("%d", &a);
sum +=a;
i++;
}//end of while
//prompts user to imput maximun amount of points possible
printf("\nEnter the max points for midterm grades: \n");
//loop to calculate total possible points
while ( x <=3)
{
scanf("%d", &b);
midMaxPts += b;
x++;
}//end of while
system("cls"); //clear screen
midterm = (sum*20/midMaxPts); //calculate midterm weights
system("pause");
return midterm; //return midterm
} //end of midterm
//Final test function
double Final ( double final)
{
system("cls"); //clear screen
//declarations
int final1, final2;
int finalSum = 0;
int points1, points2;
double finalMaxpts = 0;
final = 0;
//prompts user to input the two final grades
printf("Enter the final grades: \n" );
scanf("%d %d", &final1, &final2);
//prompts user to input the maximum points for finals
printf("Enter the max points possible for each grade: \n");
scanf("%d %d", &points1, &points2);
finalSum = final1 + final2; //calculates total points made
finalMaxpts = points1 + points2; //calculates total points possible
final = (finalSum*30/finalMaxpts); //calculates weight of final
system("cls");
system("pause");
return final; // returns final weight
} //end final function
// grade calculation function
double CalcGrade (double homework, double midterm, double final, double totalScore, char grade)
{
//calculate final overall grade
totalScore = homework + midterm + final;
//to calculate the letter grade
if (totalScore >= 90)
grade = 'A';
else if ( totalScore >= 80)
grade = 'B';
else if ( totalScore >= 70)
grade = 'C';
else if ( totalScore >= 60)
grade = 'D';
else
grade = 'F';
system("pause");
return grade; //return grade
}
// print function
int Print( double homework, double midterm, double final, double totalScore, char grade)
{
// prints out all grades
printf("\n\nFinal exam score was %2.2f\n", final);
printf("Midterm exam score was %2.2f\n", midterm);
printf("Homework assignments score were %2.2f\n", final);
printf("------------------------------------------\n\n");
printf("Total score is %2.2f\n", totalScore);
printf("Grade for the class is %c\n\n\n", grade);
system("pause");
return 0;
} //