In: Computer Science
Write a program that determines a student’s grade. The program
will read three types of scores
(quiz, mid-term, and final scores) 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
Using Switch Statement
Need to code to be simple to understand. No pointers should be used
Required Program in C ++ -->
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int quiz, miterm, final; //declare variables
cin>>quiz; //read quiz marks
cin>>miterm; //read miterm marks
cin>>final; //read final marks
float average =(quiz+miterm+final)/3; //find the average of the
three
int x = average/10; //store the value of average when divided by 10
in integer format
switch(x){ //switch for x
case 0:
case 1:
case 2:
case 3:
case 4: cout<<"Grade = F"; //if case 0,1,2,3,4 then display
F
break; //break
case 5:
case 6: cout<<"Grade = C"; //if case 5,6 then display C
break; //break
case 7:
case 8: cout<<"Grade = B"; //if case 7,8 then display B
break; //break
case 9:
case 10: cout<<"Grade = A"; //if case 9,10 then display
A
break; //break
default:cout<<"Please Enter correct marks"; //if any other,
then ask the user to enter correct values
}
return 0;
}
if marks are -> 50, 100, 50 -> then its average will be 200/3 = 66.67
and when 66.67 is divided by 10, its integer value will be 6, and then case 6 will be executed which will display C.