我有一份学生名单和一份成绩单。我想根据输入的id添加学生分数,然后查看记录。我没有正确实施它。有人可以告诉我如何正确地做到这一点吗?这是我想要实现的输出:1)添加学生 2)添加标记:将要求用户输入 id 并根据 id 如果存在,则将根据该 id 存储标记。3)查看分数:查看学生ID和他的分数
class Student
{
public Student(string name, string surname, string dob, string address)
{
this.Name = name;
this.Surname = surname;
this.DOB = dob;
this.Address = address;
}
public List<Marks> studentId = new List<Marks>();
public List<Marks> Mathematics = new List<Marks>();
public List<Marks> English = new List<Marks>();
public List<Marks> Maltese = new List<Marks>();
public List<Marks> ReligiousStudies = new List<Marks>();
public List<Marks> SocialStudies = new List<Marks>();
public string Name { get; set; }
public string Surname { get; set; }
public string DOB { get; set; }
public string Addr { get; set; }
public string Id { get; set; }
public Student(string s)
{
string[] splitted = s.Split(',');
name = splitted[0];
surname = splitted[1];
dob = splitted[2];
address = splitted[3];
id = splitted[4];
}
public void AddMarks(string id, int hyexam, int anexam)
{
if (Id.Equals(id))
{
studentId.Add(new Marks(id));
Mathematics.Add(new Marks(hyexam, anexam));
English.Add(new Marks(hyexam, anexam));
Maltese.Add(new Marks(hyexam, anexam));
ReligiousStudies.Add(new Marks(hyexam, anexam));
SocialStudies.Add(new Marks(hyexam, anexam));
}
else
{
Console.WriteLine("id not found");
}
}
public void StudMarks()
{
foreach (Marks mrk in studentId)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in Mathematics)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in English)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in Maltese)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in ReligiousStudies)
{
Console.WriteLine(mrk);
}
}
}
}
public class ClassYear
{
private const string filestud = "C:\\Users\\Maria\\Desktop\\Students\\stud.txt";
public string Year { get; set; }
public List<Student> mystudent=new List <Student> ();
public List<Student> MyStud
{
get { return mystudent; }
}
public void Addstudent(string name,string surname,string dob, string addr)
{
mystudent.Add(new Student(name,surname,dob,addr));
}
private void LoadFromFile()
{
try
{
string s;
StreamReader myFile = File.OpenText(filestud);
while ((s = myFile.ReadLine()) != null)
{
Student st = new Student(s);
mystudent.Add(st);
}
myFile.Close();
}
catch (Exception e)
{
Console.WriteLine("There was a file handling problem");
}
}
private void DumpToFile()
{
try
{
StreamWriter myFile = File.CreateText(filestud);
foreach (Student s in mystudent)
{
myFile.WriteLine(s.ToString());
}
myFile.Close();
}
catch (Exception e)
{
Console.WriteLine("There was a file handling problem");
}
}
private int SearchItem(int search)
{
int found = -1;
if (mystudent != null)
{
foreach (Student st in mystudent)
{
found++;
if (Student.Equals(search,st)) {
break;
}
}
}
return found;
}
private void Delete(int index)
{
SearchItem(index);
mystudent.RemoveAt(index);
foreach (Student st in mystudent) {
Console.WriteLine(st);
}
}
private void EditItem(int index)
{
Student stud = new Student();
SearchItem(index);
mystudent[index] = stud;
Console.WriteLine("current record is" + index);
Console.WriteLine("enter new record:");
stud.Name = Console.ReadLine();
stud.Surname = Console.ReadLine();
stud.Addr = Console.ReadLine();
stud.Id = Console.ReadLine();
foreach (Student st in mystudent)
{
Console.WriteLine(st);
}
}
private void ViewStudents()
{
foreach (Student st in mystudent)
{
Console.WriteLine(st);
}
}
}
}
public class Marks
{
public int HYEXAM { get; private set; }
public int ANEXAM { get; private set; }
public string Id { get; private set; }
public Marks(int hyexam, int anexam)
{
this.HYEXAM = hyexam;
this.ANEXAM = anexam;
}
public Marks(string id)
{
this.Id = id;
}
public double OverallExam()
{
return (0.4 * HEYXAM) + (0.6 * ANEXAM);
}
}
}