C# Student Grading System
I have given here C# source code for student grading system which accepts the mark as input and assigns ranking from A+ to F.
Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace NP
{
class StudentGrade
{
static bool ReadInteger(out int n)
{
string input = System.Console.ReadLine();
n = 0;
try
{
n = Convert.ToInt32(input);
return true;
}
catch (System.Exception ex)
{
System.Console.WriteLine("Error in the input format\n\n");
return false;
}
}
static void Main(string[] args)
{
System.Console.WriteLine("Program for simple student grading logic.");
const int MAX_STUDENTS = 10;
int [] arrMark = new int[MAX_STUDENTS];
string grade = "";
for (int i = 0; i < MAX_STUDENTS; i++)
{
System.Console.Write("Enter {0} Student Mark: ", i + 1);
ReadInteger(out arrMark[i]);
}
System.Console.Write("\n\nNo\tMark\tGrade\n");
for (int i = 0; i < MAX_STUDENTS; i++)
{
if(arrMark[i] > 100)
grade = "Error";
else if(arrMark[i] > 90)
grade = "A+";
else if(arrMark[i] > 70)
grade = "B+";
else if(arrMark[i] > 50)
grade = "C+";
else if(arrMark[i] > 30)
grade = "C";
else
grade = "F";
System.Console.Write("{0}\t{1}\t{2}\n", i + 1, arrMark[i], grade);
}
}
}
}
Output
Enter 1 Student Mark: 65
Enter 2 Student Mark: 76
Enter 3 Student Mark: 89
Enter 4 Student Mark: 95
Enter 5 Student Mark: 20
Enter 6 Student Mark: 45
Enter 7 Student Mark: 55
Enter 8 Student Mark: 67
Enter 9 Student Mark: 89
Enter 10 Student Mark: 29
No Mark Grade
1 65 C+
2 76 B+
3 89 B+
4 95 A+
5 20 F
6 45 C
7 55 C+
8 67 C+
9 89 B+
10 29 F
Press any key to continue . . .
|