static void Main(string[] args) { // clean up the output file File.WriteAllText("Result.txt", String.Empty); List <Course> courses = InOut.ReadCourseData("Course.txt"); List <Student> students = InOut.ReadStudentData("Student.txt"); StudyPlan studyPlan = new StudyPlan(courses); InOut.Print(students, "Result.txt", "Pradiniai duomenys:\nStudentai:"); InOut.Print(studyPlan, "Result.txt", "Kursai:"); List <Course> studentChoices = new List <Course>(); // temporary list List <Course> tmp = new List <Course>(); foreach (Student stud in students) { tmp.Clear(); for (int i = 0; i < studyPlan.GetCount(); i++) { Course c = studyPlan.GetEntry(i); if (c.Credits == stud.Credits) { tmp.Add(c); } } Course highest = tmp[0]; for (int i = 1; i < tmp.Count; i++) { if (highest >= tmp[i]) { highest = tmp[i]; } } Course choice = studyPlan.GetEntry(studyPlan.MaxHoursIndex(highest)); studentChoices.Add(studyPlan.GetEntry(studyPlan.MaxHoursIndex(highest))); tmp.Clear(); tmp.Add(choice); studyPlan.AddChoice(tmp); } InOut.Print(studentChoices, students, "Result.txt", "\nAtrinkti moduliai:\n"); }
public static void Print(StudyPlan allCourses, string fileName, string header) { List <string> output = new List <string>(); output.Add(header); foreach (Course course in allCourses.Courses) { output.Add(course.ToString()); } output.Add(String.Format("\nVidutinis valandų kiekis: {0:000.00}\n", allCourses.Average())); File.AppendAllLines(fileName, output.ToArray(), Encoding.UTF8); }