In: Computer Science
Problem: Grading Function
#Write a function called getScore() that does not take any parameter. Inside the function, it asks the user to input scores for 3 items (Each of the items is out of 100). The final score is calculated by 20% of item1 + 30% of item2 + 50% of item3. After calculating the final score, the function returns it to the caller. The scores are floating-point numbers.
#Write another function called getLetterGrade() that takes a float parameter and returns the letter grade based on the number passed to it as an actual parameter.
#Write the main function to test your program.
Call the getScore() function from the main function and after getting the final score from the getScore function, you should call the getLetterGrade() function to get the Grade for that score. Then print the letter grade returned by the getLetterGrade() function.
Here is the scale of the letter grade:
A [>=90]
B [80 – 90)
C [70 – 80)
D[ 60 – 70)
F [<60]
#include<iostream>
using namespace std;
float getScore(){
float i1,i2,i3;
cout<<"Enter 3 scores: ";
cin>>i1>>i2>>i3;
float total = i1 * 0.2 + i2 * 0.3 + i3 * 0.5;
return total;
}
char getLetterGrade(float f){
if(f>=90)
return 'A';
if(f>=80)
return 'B';
if(f>=70)
return 'C';
if(f>=60)
return 'D';
return 'F';
}
int main(){
float total=getScore();
cout<<"Grade:
"<<getLetterGrade(total);
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me