-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIRA4thAugust.cs
More file actions
116 lines (105 loc) · 3.61 KB
/
IRA4thAugust.cs
File metadata and controls
116 lines (105 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Linq;
namespace IRA4thAug
{
class IRA4thAugust
{
static void Main(string[] args)
{
StudentManager manager = new StudentManager();
manager.students.Add(new Student("Ravi", 17, 8, new int[4]{ 12, 30, 45, 60 }));
manager.students.Add(new Student("Ram", 18, 8, new int[4] { 15, 33, 45, 60 }));
manager.students.Add(new Student("Shyam", 16, 7, new int[4] { 12, 35, 45, 60 }));
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
int age = Convert.ToInt32(Console.ReadLine());
List<Student> Agelist = manager.FindAge(age);
if(Agelist == null)
{
Console.WriteLine("No students found");
}
else
{
foreach(var s in Agelist)
{
Console.WriteLine($"{s.rollNo}, {s.name} from grade {s.grade}");
}
}
break;
case 2:
int grade = Convert.ToInt32(Console.ReadLine());
List<Student> GetTop = manager.TopStudents(grade);
if(GetTop == null)
{
Console.WriteLine("No students found");
}
else
{
foreach(var s in GetTop)
{
Console.WriteLine($"{s.rollNo}, {s.name}, Average score:{s.Average}");
}
}
break;
}
}
}
class Student
{
public static int No = 1001;
public int rollNo { get; set; }
public string name { get; set; }
public int age { get; set; }
public int grade { get; set; }
public int[] Scores { get; set; }
public double Average { get; set; }
public Student(string nme, int ag, int gde, int[] scre)
{
rollNo = No;
name = nme;
age = ag;
grade = gde;
Scores = scre;
Average = scre.Average();
No++;
}
}
class StudentManager
{
public List<Student> students = new List<Student>();
public List<Student> FindAge(int age)
{
var CheckAge = students.Any(s => s.age == age);
if (CheckAge)
{
IEnumerable<Student> GetStudentsQuery = from s in students
where s.age == age
select s;
return GetStudentsQuery.ToList(); ;
}
else
{
return null;
}
}
public List<Student> TopStudents(int grade)
{
var CheckGrade = students.Any(s => s.grade == grade);
if (CheckGrade)
{
var GetStudentsQuery = (from s in students
where s.grade == grade
orderby s.Average descending
select s).Take(2);
return GetStudentsQuery.ToList();
}
else
{
return null;
}
}
}
}