This is a student class example, where a Student class is written which accepts the Student Name and Marks as input. Depending on the marks, it will calculate the Average and assigns a Grade.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StudentInfo
{
class Program
{
static void Main(string[] args)
{
Student stu = new Student();
Console.Write("Enter
Student's Name : ");
stu.name = Console.ReadLine();
Console.Write("Enter
marks in subject 1 : ");
stu.subject1marks = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter
marks in subject 2 : ");
stu.subject2marks = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter
marks in subject 3 : ");
stu.subject3marks = Convert.ToInt32(Console.ReadLine());
Console.Write("Average
: ");
Console.Write(stu.marksAverage(stu.subject1marks,
stu.subject2marks, stu.subject3marks));
Console.Write("\nGrade : ");
Console.WriteLine(stu.finalGrade(stu.marksAverage(stu.subject1marks,
stu.subject2marks, stu.subject3marks)));
Console.ReadLine();
}
}
class Student
{
public string name;
public int
subject1marks;
public int
subject2marks;
public int
subject3marks;
public double
average;
public string grade;
public double
marksAverage(int subject1marks, int subject2marks, int
subject3marks)
{
average = (subject1marks + subject2marks + subject3marks) / 3;
return(average);
}
public string
finalGrade(double average)
{
if (average >= 90)
{
grade = "A";
}
else if ((average
>= 80) & (average < 90))
{
grade = "B";
}
else if ((average
> 70) & (average < 80))
{
grade = "C";
}
else
grade = "Fail";
return (grade);
}
}
}
Output :
No comments:
Post a Comment