The source code to print the description of the specified grade in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
// Program to read grade of the student from the keyboard
// and print appropriate description of grade.
using System;
class GradeDemo
{
public static void Main()
{
char student_grade;
Console.Write("Enter the student grade: ");
student_grade = Convert.ToChar(Console.ReadLine());
switch (student_grade)
{
case 'A':
Console.WriteLine("Excellent");
break;
case 'B':
Console.WriteLine("Very Good");
break;
case 'C':
Console.WriteLine("Good");
break;
case 'D':
Console.WriteLine("Keep it up");
break;
case 'E':
Console.WriteLine("Poor");
break;
case 'F':
Console.WriteLine("Very Poor");
break;
default:
Console.WriteLine("Invalid GRADE");
break;
}
}
}
Output:
Enter the student grade: C
Good
Press any key to continue . . .
Explanation:
In the above program, we created a GradeDemo class that contains the Main() method. Here we created the variable student_grade of character type.
Console.Write("Enter the student grade: ");
student_grade = Convert.ToChar(Console.ReadLine());
In the above statements we took grade as input using ReadLine() method and then convert it into single character using ToChar() method, because ReadLine() method takes string as a input.
After that, we matched input grade using switch-case and print the appropriate description on the console screen.
Program:
The source code to print the description of the specified grade in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a GradeDemo class that contains the Main() method. Here we created the variable student_grade of character type.
In the above statements we took grade as input using ReadLine() method and then convert it into single character using ToChar() method, because ReadLine() method takes string as a input.
After that, we matched input grade using switch-case and print the appropriate description on the console screen.