public GradeStatistics ComputeStatistics() { GradeStatistics stat = new GradeStatistics(); float sum = 0; foreach (float grade in grades) { sum = sum + grade; stat.AverageGrade = sum / grades.Count(); stat.HighestGrade = Math.Max(grade, stat.HighestGrade); stat.LowestGrade = Math.Min(grade, stat.LowestGrade); } return(stat); asfasfsfsafs }
private static void WriteResults(IGradeTracker book) { foreach (float grade in book) { Console.WriteLine(grade); } GradeStatistics stats = book.ComputeStatistics(); WriteResult("Average grade: ", stats.AverageGrade); WriteResult("Highest grade: ", (int)stats.HighestGrade); WriteResult("Lowest grade: ", stats.LowestGrade); WriteResult(stats.Description, stats.LetterGrade); Console.ReadLine(); }
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); }
private static void WriteResults(IGradeTracker book) { GradeStatistics stats = book.ComputeStatistics(); foreach (float grade in book) { Console.WriteLine(grade); } Console.Write(book.Name); WriteResult("Average", stats.AverageGrade); WriteResult("Highest", (int)stats.HighestGrade); WriteResult("Lowest", stats.LowestGrade); WriteResult("Grade", stats.LetterGrade); WriteResult("Grade Description", stats.Description); }
static void Main(string[] args) { GradeStatistics stat = new GradeStatistics(); SpeechSynthesizer sync = new SpeechSynthesizer(); sync.Speak("hello, my name is Uyen"); GradeBook book = new GradeBook(); book.AddGrade(91); book.AddGrade(89.5f); stat = book.ComputeStatistics(); Console.WriteLine(stat.AverageGrade); Console.WriteLine(stat.HighestGrade); Console.WriteLine(stat.AverageGrade); }
public override GradeStatistics ComputeStatistics() { GradeStatistics stats = new GradeStatistics(); if (ThrowAwayLowest) { float sum = 0; foreach (var grade in grades) { stats.highestGrade = Math.Max(grade, stats.highestGrade); stats.lowestGrade = Math.Min(grade, stats.lowestGrade); sum += grade; stats.averageGrade = sum / grades.Count; // TODO : add DivideByZeros } } return(stats); }
static void WriteResults(IGradeTracker book) { // Because GradeBook.ComputeStatistics has virtual keyword anything that inherits this can override it. // We created a new ThrowAwayGradeBook object named book and called book.ComputeStatistics. // Since ThrowAwayGradeBook.ComputeStatistics uses the override keyword we can override the virtual // method of the GradeBook and call the method we really want. GradeStatistics stats = book.ComputeStatistics(); foreach (float grade in book) { Console.WriteLine(grade); } WriteResult("Average", stats.AverageGrade); WriteResult("Highest", stats.HighestGrade); WriteResult("Lowest", stats.LowestGrade); WriteResult(stats.Description, stats.LetterGrade); }
/// <summary> /// Computes the statitistics for the gradebook /// This includes Highest, Lowest and Average Grades /// </summary> /// <returns></returns> 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); }
static void Main(string[] args) { //Create new instance of gradebook GradeBook book = new GradeBook(); //Add some grades book.AddGrades(10); book.AddGrades(20.5f); book.AddGrades(17.5f); //Do Calculations GradeStatistics stats = book.ComputeStatistics(); Console.WriteLine("Average grade: " + stats.AverageGrade); Console.WriteLine("Minimum grade: " + stats.MinimumGrade); Console.WriteLine("Maximum grade: " + stats.MaximumGrade); Console.ReadKey(); }
//Statistics public GradeStatistics ComputeStatistics() { //create new instance of grade statistics GradeStatistics stats = new GradeStatistics(); float sum = 0; foreach (float grade in grades) { sum += grade; stats.MinimumGrade = Math.Min(grade, stats.MinimumGrade); stats.MaximumGrade = Math.Max(grade, stats.MaximumGrade); } stats.AverageGrade = sum / grades.Count; return(stats); }
public GradeStatistics ComputeStatistics() { GradeStatistics stats = new GradeStatistics(); double sum = 0; int c = 0; foreach (double grade in grades) { sum = sum + grade; c++; if (grade > stats.MaxGrade) { stats.MaxGrade = grade; } stats.MinGrade = Math.Min(grade, stats.MinGrade); } stats.AvgGrade = sum / grades.Count; return(stats); }
static void Main(string[] args) { SpeechSynthesizer synth = new SpeechSynthesizer(); synth.Speak("Hello, This is the grade book program"); 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); }
public override GradeStatistics ComputeStatistics() { Console.WriteLine("GradeBook statistics method"); GradeStatistics stats = new GradeStatistics(); var sum = 0f; foreach (var grade in _grades) { // Compare and replace grades in the List<T> // Base comparison of 0 for highest grade to ensure replacement in init // Base comparison of float.MaxValue grade to ensure replacement in init stats.HighestGrade = Math.Max(grade, stats.HighestGrade); stats.LowestGrade = Math.Min(grade, stats.LowestGrade); sum += grade; } stats.AverageGrade = (float)Math.Round(sum / _grades.Count); return(stats); }
public GradeStatistics ComputeStatistics() { GradeStatistics statistics = new GradeStatistics(); float sum = 0; foreach (float grade in grades) { //if(grade > statistics.highestGrade) //{ // statistics.highestGrade = grade; //} statistics.highestGrade = Math.Max(grade, statistics.highestGrade); statistics.lowestGrade = Math.Min(grade, statistics.lowestGrade); sum += grade; } statistics.averageGrade = sum / grades.Count; return(statistics); }
public GradeStatistics ComputeStatistics() { GradeStatistics stats = new GradeStatistics(); // whats the highest grade i have seen so far float sum = 0; foreach (float grade in grades) { //one way, also math //if(grade>stats.HighestGrade) //{ // stats.HighestGrade = grade; //} stats.HighestGrade = Math.Max(grade, stats.HighestGrade); stats.LowestGrade = Math.Min(grade, stats.LowestGrade); //sum = sum + grade; sum += grade; } stats.AverageGrade = sum / grades.Count; return(stats); }