-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStudent_Database.cs
More file actions
62 lines (59 loc) · 1.83 KB
/
Student_Database.cs
File metadata and controls
62 lines (59 loc) · 1.83 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
using System;
using System.Collections.Generic;
namespace studentDatabase
{
class student
{
public int id { get; set; }
public string name { get; set; }
public int marks { get; set; }
public string course { get; set; }
}
class Student_Database
{
static void Main(string[] args)
{
List<student> stud = new List<student>();
int Id, Marks;
string Name, Course;
int n = Convert.ToInt32(Console.ReadLine());
student[] s = new student[n];
for (int i=0; i<n; i++)
{
try
{
Id = Convert.ToInt32(Console.ReadLine());
Marks = Convert.ToInt32(Console.ReadLine());
Name = Console.ReadLine();
Course = Console.ReadLine();
s[i] = new student { id = Id, name = Name, marks = Marks, course = Course };
stud.Add(s[i]);
}
catch(Exception E)
{
Console.WriteLine(E.Message);
break;
}
}
string crse = Console.ReadLine();
Console.WriteLine(showcase(stud, crse));
}
public static string showcase(List<student> stud, string course)
{
int max = 0;
string name = string.Empty ;
foreach(student s in stud)
{
if (s.course == course)
{
if (s.marks > max)
{
max = s.marks;
name = s.name;
}
}
}
return name;
}
}
}