Advertisement
Primitiv0

Final Average Grade

Sep 20th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace listado_notas_promediadas
  5. {
  6.  
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             String strNombre, strNota;
  12.             Double dblNota = 0;
  13.             bool blDetermine = false;
  14.             Dictionary<string, Array> di = new Dictionary<string, Array>();
  15.             Console.WriteLine("Calcula el promedio de notas de 11 Estudiantes! \n\n");
  16.             for(int i=1;i<12;i++){
  17.                 Console.WriteLine("Introduzca la información del estudiante "+i+"");      
  18.                     Console.Write("Nombre: ");
  19.                     strNombre = Console.ReadLine();
  20.                     double[] nota_mes = new double[4];
  21.                     for (int j = 0; j < 4; j++)
  22.                     {
  23.                         Console.Write("Introduzca la nota " + (j+1) + " de "+strNombre+": ");
  24.                         strNota = Console.ReadLine();
  25.                         blDetermine = Double.TryParse(strNota, out dblNota);
  26.                         if (blDetermine == false)
  27.                         {
  28.                             Console.WriteLine("\n\nFavor de escribir un valor correcto!  Ej: 85");
  29.                         }
  30.                         nota_mes[j] = dblNota;        
  31.                     }
  32.                     di.Add(strNombre, nota_mes);
  33.             }
  34.                 foreach (var d in di)
  35.                 {
  36.                 Console.WriteLine();
  37.                     Console.WriteLine($"el promedio cuatrimestral de notas de {d.Key} es:  {PromedioNota(d.Value)}");
  38.                     Console.WriteLine($"{d.Key} obtuvo una -> " + Promedio(PromedioNota(d.Value)));
  39.                 }
  40.             }
  41.  
  42.         static Double[] ObetenerPromedioNotas(Dictionary<string,Array> di) {
  43.             double[] result=new double[4];
  44.             double sum=0;
  45.             for (int i = 0; i <4; i++) {
  46.                 double[] de = new double[di.Count];
  47.                 int j = 0;
  48.                 foreach (double[] s in di.Values) {
  49.                     de[j]= s[i];
  50.                     j++;
  51.                 }
  52.                 for (int k = 0; k < de.Length; k++) {
  53.                     sum += de[k];
  54.                 }
  55.                result[i] = sum / di.Count;
  56.                 sum = 0;
  57.             }
  58.                 return result;
  59.             }
  60.             static double PromedioNota(Array Notames)
  61.             {
  62.             double sum=0;
  63.             foreach (double a in Notames) {
  64.                 sum+=a;
  65.             }
  66.             return sum / 4;
  67.             }
  68.             static string Promedio(double avg)
  69.             {
  70.                 if (avg >= 90 && avg <= 100)
  71.                 {
  72.                     return "A";
  73.                 }
  74.                 else if (avg >= 80 && avg <= 89)
  75.                 {
  76.                     return "B";
  77.                 }
  78.                 else if (avg >= 70 && avg <= 79)
  79.                 {
  80.                     return "C";
  81.                 }
  82.                 else if (avg >= 60 && avg <= 69)
  83.                 {
  84.                     return "D";
  85.                 }
  86.  
  87.                 else if (avg >= 0 && avg <= 59)
  88.                 {
  89.                     return "F";
  90.                 }
  91.             return "None";
  92.             }
  93.         }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement