In: Computer Science
Imagine you are a student enrolled in a College course where the course grade is calculated using a weighted average. (It might not be too hard to imagine.) It’s nearing the midterm of the semester and you want to know what your grade is. Luckily, your professor has provided you with a syllabus, and in that syllabus he or she has listed the formula for calculating your course grade. (This is sounding more familiar all the time.)
Graded Activity Percentage
Exams are 30%
Projects are 30%
Assignments are 15%
Quizzes are 5%
You will notice that the weighted percentages only add up to 80% of the total grade. That’s because the final exam will represent the last 20% of your grade. That said, let’s calculate our current grade with only the grades we have SO FAR, and ignoring the final exam part. You want to write a program that asks you for all of your grades, one graded activity at a time, one grade at a time. (See the SAMPLE RUNS section below.)
You need to write a program that does this making use of the following functions:
void printPrompt(int a)
– This function accepts a single incoming integer (value 1 through 4). Depending on the value of the incoming integer the function prints out the prompt to enter grades of a certain type (quiz grades, assignment grades, exam grades, and project grades) and tells the user to enter -1 to quit. This function is only responsible for printing the prompt and accepts NO user input. It also returns nothing.
double average()
– This function takes no incoming data (no parameters), but it does receive input from the user through cin. The user enters a series of integer grades with a -1 to terminate input. It also calculates the average of all inputs entered. This average is returned as a double.
double weightedAverage(double, double, double, double)
– This function takes in four double values which represent the averages of the four types of graded activity. It calculates and returns the current weighted average, in the form of a double.
void outputAverages(double, double, double, double, double)
– This function accepts five double values: the four graded activity averages calculated before, as well as the overall weighted average. The function prints out the average of each type of grade; quiz average, assignment average, exam average, and project average, as well as the current grade in the course. It has no outgoing data (no return values).
PROVIDED SKELETON CODE:
For this assignment we have provided part of your solution for you. Specifically, we have provided a file where we have listed all the necessary function declarations as well as a main function that makes calls to these functions. DO NOT MODIFY either the function declarations OR the main function.
Your job will be to add the function definitions below the main function. A completed and
fully functional program should result if you correctly define these functions.
SAMPLE RUNS:
Sample Run 1:
Enter your quiz grades (-1 to end input):
100 95 90 85 -1
Enter your assignment grades (-1 to end input):
50 100 100 25 0 -1
Enter your exam grades (-1 to end input):
65 -1
Enter your project grades (-1 to end input):
80 93 75 -1
Your quiz average: 92.5
Your assignment average: 55
Your exam average: 65
Your project average: 82.6667
Your current grade in this course is: 71.4687
SKELETON (DO NOT MODIFY THE MAIN)
#include <iostream>
using namespace std;
//FUNCTION DECLARATIONS - ***DO NOT MODIFY***
/*name: printPrompt
INCOMING: An integer of possible values 1 through 4 indicating a specific graded
activity
OUTGOING: None
*/
void printPrompt(int);
/*name: average
INCOMING: None
OUTGOING: The double average of the integer grades as entered by the user
*/
double average();
/*name: weightedAverage
INCOMING: Four double values representing the averages for the four graded
activities
OUTGOING: The double value representing the weighted average for the course so
far (a.k.a. the current grade)
*/
double weightedAverage(double, double, double, double);
/*name: outputAverages
INCOMING: A double value representing the current grade and four double values
for four graded activity averages
OUTGOING: None
*/
void outputAverages(double, double, double, double, double);
//MAIN FUNCTION - ***DO NOT MODIFY***
int main(){
double quizAvg, assignAvg, examAvg, projAvg, currentGrade;
int count = 1;
while (count<=4){
printPrompt(count);
switch(count){
case 1:
//1 - getting the quiz grades
quizAvg = average();
break;
case 2:
//2 - getting the assignment grades
assignAvg = average();
break;
case 3:
//3 - getting exam grades
examAvg = average();
break;
case 4:
//4 - getting project grades
projAvg = average();
break;
}
count++;
}
//get the current grade, based on the different averages and their weights.
currentGrade = weightedAverage(quizAvg, assignAvg, examAvg, projAvg);
outputAverages(currentGrade, quizAvg, assignAvg, examAvg, projAvg);
}
//END MAIN FUNCTION
//**--YOUR WORK HERE--**
//**PLACE YOUR FUNCTION DEFINITIONS (a.k.a. IMPLEMENTATIONS) BELOW**
Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.
Code:
#include <iostream>
using namespace std;
//FUNCTION DECLARATIONS - ***DO NOT MODIFY***
/*name: printPrompt
INCOMING: An integer of possible values 1 through 4 indicating a specific graded
activity
OUTGOING: None
*/
void printPrompt(int);
/*name: average
INCOMING: None
OUTGOING: The double average of the integer grades as entered by the user
*/
double average();
/*name: weightedAverage
INCOMING: Four double values representing the averages for the four graded
activities
OUTGOING: The double value representing the weighted average for the course so
far (a.k.a. the current grade)
*/
double weightedAverage(double, double, double, double);
/*name: outputAverages
INCOMING: A double value representing the current grade and four double values
for four graded activity averages
OUTGOING: None
*/
void outputAverages(double, double, double, double, double);
//MAIN FUNCTION - ***DO NOT MODIFY***
int main(){
double quizAvg, assignAvg, examAvg, projAvg, currentGrade;
int count = 1;
while (count<=4){
printPrompt(count);
switch(count){
case 1:
//1 - getting the quiz grades
quizAvg = average();
break;
case 2:
//2 - getting the assignment grades
assignAvg = average();
break;
case 3:
//3 - getting exam grades
examAvg = average();
break;
case 4:
//4 - getting project grades
projAvg = average();
break;
}
count++;
}
//get the current grade, based on the different averages and their weights.
currentGrade = weightedAverage(quizAvg, assignAvg, examAvg, projAvg);
outputAverages(currentGrade, quizAvg, assignAvg, examAvg, projAvg);
system("pause");
}
double average(){
double sum=0,count=0,inp;
while(true){
cin>>inp;
if(inp==-1)
break;
count++;
sum=sum+inp;
}
return sum/count;
}
void printPrompt(int choice){
switch (choice)
{
case 1:
cout<<"Enter your quiz grades
(-1 to end input):"<<endl;
break;
case 2:
cout<<"Enter your assignment
grades (-1 to end input):"<<endl;
break;
case 3:
cout<<"Enter your exam grades
(-1 to end input):"<<endl;
break;
case 4:
cout<<"Enter your project
grades (-1 to end input):"<<endl;
break;
default:
cout<<"Invalid
Input"<<endl;
}
}
double weightedAverage(double quizzes, double assignments,
double exams, double projects){
return
((30*exams)+(30*projects)+(15*assignments)+(5*quizzes))/80.0;
}
void outputAverages(double weightedAverage, double quizzes,
double assignments, double exams, double projects)
{
cout<<"Your quiz average:
"<<quizzes<<endl;
cout<<"Your assignment average: "<<assignments<<endl;
cout<<"Your exam average: "<<exams<<endl;
cout<<"Your project average:
"<<projects<<endl;
cout<<"Your current grade in this course is:
"<<weightedAverage<<endl;
}
Output: