Hi! This is for c++. Thanks 1.Build a function called calculate_percent() with t
ID: 3922037 • Letter: H
Question
Hi! This is for c++. Thanks
1.Build a function called calculate_percent() with the following properties:
Takes 2 floating-point numbers called "score" and "max_score"
Returns a floating point number which is percentage of score and max_score.'
Do not use a global variable, and do not use printf/scanf inside this function
2.Build a function called getAvg()that returns the average of three numbers
Takes 3 floating-point numbers
Returns the average of three numbers.
Do not use a global variable, and do not use printf/scanf inside this function
3.Build a function called getGradeLetter():
Takes a floating-point number containing the percentage
Returns a char which is the letter grade of the percentage.
Do not use a global variable, and do not use printf/scanf inside this function
4.Build a function called print_line()
Takes a character that will be used to print a line
Takes the number of times to print the character
For example, if we call print_line('*', 10), it should print :
********** (Prints * ten times).
Note that when you call this function, you need to provide a char in single quotes.
Explanation / Answer
float calculate_percent(float score,float max_score)
{
return (score/max_score)*100;
}
float getAvg(float n1,float n2,float n3)
{
return (n1+n2+n3)/3.0;
}
char getGradeLetter(float precent)
{
char grade;
if(percent>=90)
grade = 'S';
else if(percent>=80)
grade = 'A';
else if(percent>=70)
grade = 'B';
else if(percent>=60)
grade = 'C';
else if(percent>=50)
grade = 'D';
else if(percent>=40)
grade = 'E';
else
grade = 'F';
return grade;
}
void print_line(char chr,int times)
{
for(int i=0;i<times;i++)
cout << chr;
cout << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.