Using the knowledge gained from assignment 6-1, write a program which calculates
ID: 647282 • Letter: U
Question
Using the knowledge gained from assignment 6-1, write a program which calculates your semester grade. Note that there are/will be 23 assignment grades. Also remember that 90% attendance equals 100% of the grade. Also, 85% of the textbook completion equals 100% of the grade. You must use your function getLabGrades and also write and use a function called getAssignmentGrades. You will call getAssignmentGrades like you did getLabGrades:
double assignments = getAssignmentGrades();
My question is above and here is just Problem 6-1 only as a reference:
Note that not every function has to have parameters. For example, you have been creating the function main since the beginning, and it is a function without parameters. Using this information, write a function called getLabGrades that prompts the user for each assignment grade (there are 5). Remember that each lab is worth 120 points. Use the following code in main to call it:
int main() {
double labs = getLabGrades();
cout << "Your lab grade is: " << labs << endl;
return 0;
}
Explanation / Answer
#include <iostream>
using namespace std;
double getAssignmentGrades(){
int num, max;
cout << "Number of assignments: ";
cin >> num;
cout << "Maximum number of points per each assignment: ";
cin >> max;
double sum = 0, temp;
for (int i = 0; i < num; ++i){
cout << "Number of points received for assignment " << (i + 1) << ": ";
cin >> temp;
sum += temp;
}
sum /= num;
return (sum / max) * 100;
}
double getLabGrades(){
int num, max;
cout << "Number of labs: ";
cin >> num;
cout << "Maximum number of points per each lab: ";
cin >> max;
double sum = 0, temp;
for (int i = 0; i < num; ++i){
cout << "Number of points received for lab " << (i + 1) << ": ";
cin >> temp;
sum += temp;
}
sum /= num;
return (sum / max) * 100;
}
int main(){
double labs = getLabGrades();
cout << "Your lab grade is: " << labs << endl;
double assignments = getAssignmentGrades();
cout << "Your assignment grade is: " << assignments << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.