Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ Program using both if /else if/else and switch Case that determines

ID: 3592583 • Letter: W

Question

Write a C++ Program using both if /else if/else and switch Case that determines a student’s grade. The program will read three types of scores:

Quiz - max 20, mid-term - max 30, and final - max 50) and determine the grade based on the following rules:

- if the average score =90%                             =>      grade = A

-if the average score >= 70% and <90%         =>       grade = B

-if the average score>=50% and <70%           =>      grade = C

-if the average score<50%                               =>       grade = F

Explanation / Answer

#include <iostream>

using namespace std;

int userinput(int maxScore, char scoreType[])
{
int score;
cout<<"Enter the marks scored in "<< scoreType <<" (Max marks : "<< maxScore << ")" << endl;
cin>>score;
if(score>maxScore || score<0)
{
cout<<"Invalid Score Entered" << endl;
score=userinput(maxScore,scoreType);
}
else
{
return score;
}
}

void gradeCalculator(int quizMarks, int midtermMarks, int finalMarks, int maxMarks)
{
int total = quizMarks + midtermMarks + finalMarks;
int avg = total*100;
float percentage = avg/maxMarks;
char Grade;

//Considering average > 90 will get grade A, question stated Average =90 will get A but no rule for Average > 90
if(percentage > 89) {
Grade='A';
}
else if(percentage > 69)
{
Grade='B';
}
else if(percentage > 49)
{
Grade='C';
}
else
{
Grade='F';
}
switch (Grade)
{
case ('A') :
cout<<"Final grafe for student is : "<< Grade << endl;   
break;
  
case ('B') :
cout<<"Final grafe for student is : "<< Grade << endl;
break;
  
case ('C') :
cout<<"Final grafe for student is : "<< Grade << endl;
break;
  
case ('F') :
cout<<"Final grafe for student is : "<< Grade << endl;
break;
}
  
}

int main()
{
int quizScore=0,midScore=0,finalScore=0;
quizScore=userinput(20,"Quiz");
midScore=userinput(30,"Mid-term");
finalScore=userinput(50,"Final");
gradeCalculator(quizScore,midScore,finalScore,100);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote