コード例 #1
0
ファイル: Program.cs プロジェクト: JNM-2T17/CSC617M
        static void addStudent()
        {
            Console.Clear();
            Console.Write("Please enter name: ");
            String name = Console.ReadLine();
            Console.Write("Please enter ID: ");
            String id = Console.ReadLine();
            Console.Write("Please enter gender: ");
            String gender = Console.ReadLine();
            Student s = new Student(name, id, gender);

            foreach (string str in gradebooks)
            {
                s.addGrade(new Grade(str));
            }
            students.Add(s);
        }
コード例 #2
0
ファイル: FileIO.cs プロジェクト: JNM-2T17/CSC617M
        public static List<Student> readFromFile()
        {
            List<Student> students = new List<Student>();
            try
            {
                using (StreamReader sr = new StreamReader("Gradebook.txt"))
                {
                    int nStudents = Int32.Parse(sr.ReadLine());
                    int nCourses = Int32.Parse(sr.ReadLine());
                    List<string> courses = new List<string>();

                    for (int i = 0; i < nCourses; i++)
                    {
                        courses.Add(sr.ReadLine());
                    }

                    for (int i = 0; i < nStudents; i++)
                    {
                        Student s = new Student(sr.ReadLine(), sr.ReadLine(), sr.ReadLine());
                        foreach (string course in courses)
                        {
                            Grade g = new Grade(course);
                            g.ExerciseScore = Double.Parse(sr.ReadLine());
                            g.ExamScore = Double.Parse(sr.ReadLine());
                            g.FinalsScore = Double.Parse(sr.ReadLine());
                            g.FinalGrade = Double.Parse(sr.ReadLine());
                            s.addGrade(g);
                        }
                        students.Add(s);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            return students;
        }