Created
June 15, 2016 14:22
-
-
Save macrat/b841c82a050265f606fb65f78a6030a7 to your computer and use it in GitHub Desktop.
6月15日のC#勉強会の課題実装例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using CampusSquare; | |
| class Example2 { | |
| public static void Main() { | |
| var grades = new CampusSquare.DummyCampusSquare("record.html").GetGrades(); | |
| Console.WriteLine("GPA: " + ( | |
| (double)grades.Select(x => x.GradeNum * x.CreditNum).Sum() | |
| / | |
| grades.Select(x => x.CreditNum).Sum() | |
| )); | |
| Console.WriteLine("\ngood: "); | |
| foreach(var grade in grades.Where(x => x.GradeNum == grades.Select(y => y.GradeNum).Max())){ | |
| Console.WriteLine(" " + grade.Grade + ": " + grade.Name); | |
| } | |
| Console.WriteLine("\nbad: "); | |
| foreach(var grade in grades.Where(x => x.GradeNum == grades.Select(y => y.GradeNum).Min())){ | |
| Console.WriteLine(" " + grade.Grade + ": " + grade.Name); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using CampusSquare; | |
| class Example1 | |
| { | |
| static void Main(string[] args) | |
| { | |
| var grades = new CampusSquare.DummyCampusSquare("record.html").GetGrades(); | |
| double creditSum = 0, gradeSum = 0; | |
| foreach (IGrade grade in grades) | |
| { | |
| creditSum += grade.CreditNum; | |
| gradeSum += grade.CreditNum * grade.GradeNum; | |
| } | |
| double gpa = gradeSum / creditSum; | |
| Console.WriteLine("GPA:\t{0}", gpa); | |
| int max = 0, min = 4; | |
| foreach (IGrade grade in grades) | |
| { | |
| max = Math.Max(max, grade.GradeNum); | |
| min = Math.Min(min, grade.GradeNum); | |
| } | |
| Console.WriteLine("\ngood:"); | |
| foreach (IGrade grade in grades) | |
| { | |
| if (grade.GradeNum == max) | |
| { | |
| Console.WriteLine("\t{0}:{1}", grade.Grade, grade.Name); | |
| } | |
| } | |
| Console.WriteLine("\nbad:"); | |
| foreach (IGrade grade in grades) | |
| { | |
| if (grade.GradeNum == min) | |
| { | |
| Console.WriteLine("\t{0}:{1}", grade.Grade, grade.Name); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment