Tuesday, 27 November 2012

Student Marklist in Console Application

using System;
using System.Collections.Generic;
using System.Text;

namespace stud
{
class student
{
int id,m1,m2,m3,tot,avg;
string name,res,grade;
public void get()
{
Console.WriteLine("Enter the student ID");
id=int.Parse(Console.ReadLine());
Console.WriteLine("Enter the student name");
name=Console.ReadLine();
Console.WriteLine("Enter the Mark1,Mark2,Mark3");
m1=int.Parse(Console.ReadLine());
m2=int.Parse(Console.ReadLine());
m3=int.Parse(Console.ReadLine());
}
public void cal()
{
tot = m1 + m2 + m3;
avg = tot / 3;
if(m1>=45 && m2>=45 && m3>=45)
{
res="pass";
if(avg>=85 && avg<=100)
{
grade="A";
}
else if(avg<=84 && avg>=70)
{
grade="B";
}
else
{
grade="C";
}
}
else
{
res="Fail";
grade="-";
}
}


public void display()
{

Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", id, name, m1, m2, m3, tot, avg,res,grade);
}
}
class stude
{

static void Main(string[] args)
{
int i, n;
student[] s=new student[20];
Console.WriteLine("Enter the no of students");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
s[i] = new student();
s[i].get();
s[i].cal();

}
Console.WriteLine("ID\tNAME\tM1\tM2\tM3\tTOTAL\tAVG\tRESULT\tGRADE");
for (i = 1; i <= n; i++)
{
s[i].display();
}
}
}
}

No comments:

Post a Comment