public GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();
            float           sum   = 0f;

            foreach (float d in grades)
            {
                sum += d;
                stats.HighestGrade = Math.Max(d, stats.HighestGrade);
                stats.LowestGrade  = Math.Min(d, stats.LowestGrade);
            }

            stats.AverageGrade = sum / grades.Count;

            return(stats);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //Working with other references
            //Using the Speech Synthesizer (Speak method)

            SpeechSynthesizer synth = new SpeechSynthesizer();


            //Now with another voice
            synth.SelectVoice("Microsoft Zira Desktop");

            //First using default voice
            synth.Speak("Hello this is the grade book program");

            //Instantiate the grade book class - creating the
            //the GradeBook object represented by book
            GradeBook book = new GradeBook();

            book.NameChanged += OnNameChanged2;
            book.NameChanged += OnNameChanged;
            book.NameChanged += OnNameChanged2;

            //Add some random grades
            book.AddGrade(91);
            //Explicitly convert double 89.5 to float by adding f
            book.AddGrade(89.5f);
            book.AddGrade(76);

            book.Name = "Welcome to Zach's Gradebook"; //set
            Console.WriteLine(book.Name);              //get

            //Get the stats and write out results to screen
            GradeStatistics stats = book.ComputeStatistics();

            //Console.WriteLine("Average Grade: " + stats.AverageGrade);
            //Console.WriteLine("Highest Grade: " + stats.HighestGrade);
            //Console.WriteLine("Lowest Grade: " + stats.LowestGrade);

            WriteResult("Average Grade", stats.AverageGrade);
            WriteResult("Lowest Grade", stats.LowestGrade);
            WriteResult("Highest Grade", (int)stats.HighestGrade);

            book.Name = "Gradebook finished computing stats.";

            Console.WriteLine("Press any key to exit program.");
            Console.ReadKey();
        }
Esempio n. 3
0
        public GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();
            float           sum   = 0;

            foreach (float grade in grades)
            {
                sum += grade;
            }
            if (grades.Count > 0)
            {
                stats.AverageGrade = sum / grades.Count;
                stats.HighestGrade = grades.Max();
                stats.LowestGrade  = grades.Min();
            }
            return(stats);
        }
        public override GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();
            float           sum   = 0;

            //Iterates through each item in the list exactly once
            foreach (float grade in grades)
            {
                //compare each item with the current high
                stats.HighestGrade = Math.Max(grade, stats.HighestGrade);
                //compare each item with the current low
                stats.LowestGrade = Math.Min(grade, stats.LowestGrade);
                sum += grade;
            }
            stats.AverageGrade = sum / grades.Count;
            return(stats);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Gradebook book = new Gradebook();

            book.AddGrade(91);
            book.AddGrade(89.5f);
            book.AddGrade(75);

            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.HighestGrade);
            Console.WriteLine(stats.Lowestgrade);

            ///Gradebook book2 = new Gradebook();
            ///book2.grades = book.grades.ToList<float>();
            ///book2.AddGrade(75);
        }
Esempio n. 6
0
        public override GradeStatistics ComputeStatistics()
        {
            Console.WriteLine("GradeBook::ComputeStatistics");
            GradeStatistics stats = new GradeStatistics();

            float sum = 0;

            foreach (float grade in grades)
            {
                stats.HighestGrade = Math.Max(grade, stats.HighestGrade);
                stats.LowestGrade  = Math.Min(grade, stats.LowestGrade);
                sum += grade;
            }

            stats.AverageGrade = sum / grades.Count;

            return(stats);
        }
Esempio n. 7
0
        public override GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();

            float sum = 0;

            foreach (float grade in Grades)
            {
                stats.HighestGrade = Math.Max(grade, stats.HighestGrade);
                stats.LowestGrade  = Math.Min(grade, stats.LowestGrade);
                sum += grade;
            }

            stats.AverageGrade = sum / Grades.Count;


            return(stats);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();

            synth.Speak("Welcome to the grade book application.");

            GradesBook book = new GradesBook();

            book.AddGrade(91);
            book.AddGrade(89.5f);
            book.AddGrade(75);


            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine("Average Grade: " + stats.AverageGrade);
            Console.WriteLine("Highest Grade: " + stats.HighestGrade);
            Console.WriteLine("Lowest Grade: " + stats.LowestGrade);
            synth.Speak("Here are the statistics for the grade book.");
        }
Esempio n. 9
0
        public override GradeStatistics ComputeStats()
        {
            Console.WriteLine("GradeBook::ComputeStats");

            GradeStatistics stats = new GradeStatistics();

            foreach (float grade in grades)
            {
                if (stats.MinGrade > grade)
                {
                    stats.MinGrade = grade;
                }
                if (stats.MaxGrade < grade)
                {
                    stats.MaxGrade = grade;
                }
                stats.AvgGrade = stats.AvgGrade + grade;
            }
            stats.AvgGrade = stats.AvgGrade / grades.Count;

            return(stats);
        }
Esempio n. 10
0
        public GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();

            double sum = 0;

            foreach (float grade in grades)
            {
                sum += grade;
                stats.HighestGrade = Math.Max(grade, stats.HighestGrade);
                stats.LowestGrade  = Math.Min(grade, stats.LowestGrade);
            }
            if (grades.Count != 0)
            {
                stats.AverageGrade = sum / grades.Count;
            }
            else
            {
                Console.WriteLine("Please enter some grades first!");
            }

            return(stats);
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            GradeBook book = new GradeBook();

            book.AddGrade(91);
            book.AddGrade(89.5);
            book.AddGrade(75);
            int userInput = 0;

            while (userInput != 1)
            {
                Console.WriteLine("Please enter a grade: ");
                book.AddGrade(Convert.ToDouble(Console.ReadLine()));
                Console.WriteLine("1. Finished Entering Grades. ");
                Console.WriteLine("2. Enter Another Grade");
                Console.WriteLine("Please enter 1 if you would like to continue: ");
                userInput = Convert.ToInt32(Console.ReadLine());
            }
            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine("Average Grade: " + Math.Round(stats.AverageGrade, 1));
            Console.WriteLine("Highest Grade: " + stats.HighestGrade);
            Console.WriteLine("Lowest Grade: " + stats.LowestGrade);
        }