Write a program that calculates a student\'s GPA based on 2test and 3 homework s
ID: 647704 • Letter: W
Question
Write a program that calculates a student's GPA based on 2test and 3 homework scores. Your program should have two functions: void getScore() and void calcAverage() void getScore()- asks the user for a test and homework scores, stores it in a variable and validates it (between 0-100) void calcAverage()- should calculate and display the average of the score as well as the test and assignment scores. The GPA of the student should be calculated using the following formula. All scores should be entered as grade out of 100 possible points.Explanation / Answer
#include<iostream>
using namespace std;
void getScore(int test[], int homework[]){
for(int i = 1; i<= 2; i ++){
cout << "Test" << i << " : ";
cin >> test[i-1];
while(test[i-1] <0 || test[i-1] > 100){
cout << "Invalid Score Enter again : ";
cin >> test[i-1];
}
}
for(int i = 1; i<= 3; i ++){
cout << "HW" << i << " : ";
cin >> homework[i-1];
while(homework[i-1] <0 || homework[i-1] > 100){
cout << "Invalid Score Enter again : ";
cin >> homework[i-1];
}
}
}
void calcAverage(double &testAverage, double &homeworkAverage, int test[], int homework[]){
int sum = 0;
for(int i = 0; i< 2; i++){
sum += test[i];
}
testAverage = sum/2;
sum = 0;
for(int i = 0; i< 3; i++){
sum += homework[i];
}
homeworkAverage = sum/3;
cout << "Average of test score : " << testAverage << endl;
cout << "Average of homework scores : " << homeworkAverage << endl;
double GPA = 0.75*testAverage + 0.25*homeworkAverage;
cout << "GPA of the student id : " << GPA << endl;
}
int main(){
int test[2],homework[3];
double testAverage,homeworkAverage;
getScore(test,homework);
calcAverage(testAverage, homeworkAverage,test,homework);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.