Пример #1
0
        public override Statistics ComputeStatistics()
        /* Computes the average, lowest and highest grade from grades.*/
        {
            var res = new Statistics();

            foreach (var grade in grades)
            {
                res.AddToStat(grade);
            }
            //  Could also do:

            /*var index = 0;
             * while (index < grades.Count)
             * {
             *  res.highestGrade = Math.Max(grades[index], res.highestGrade);
             *  res.lowestGrade = Math.Min(grades[index], res.lowestGrade);
             *  res.averageGrade += grades[index];
             *  index += 1;
             * }
             * for(var index = 0; index < grades.Count; index += 1)
             * {
             *  res.highestGrade = Math.Max(grades[index], res.highestGrade);
             *  res.lowestGrade = Math.Min(grades[index], res.lowestGrade);
             *  res.averageGrade += grades[index];
             * }*/
            // jumping statements that can be used in loops: break, continue;



            return(res);
        }
Пример #2
0
        public override Statistics ComputeStatistics()
        {
            var    result       = new Statistics();
            string DiskBookFile = @"DiskBook.txt";

            using (StreamReader sr = File.OpenText(DiskBookFile))
            {
                var line = sr.ReadLine();
                while (line != null)
                {
                    var grade = double.Parse(line);
                    result.AddToStat(grade);
                    line = sr.ReadLine();
                }
            }
            return(result);
        }