#define daneTestowe
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program
{
class Program
{
static void Main(string[] args)
{
int n, ile2 = 0, ile5 = 0, j = 0, iluGorszych = 0;
double sr, sk = 0, suma2 = 0, war;
string[] tabNazwisk;
double[] tabOcen;
Console.WriteLine("Program liczy średnią ocen");
//dane testowe
#if (daneTestowe)
tabOcen
= new double[] { 2.0,
4.5,
5.0,
2.0,
3.5,
4.5,
2.0,
4.0,
5.0,
3.0 };
tabNazwisk
= new string[] { "Stachowiak",
"Kot",
"Kabat",
"Dolata",
"Krajewska",
"Pawłowska",
"Lis",
"Krawczyk",
"Nowak",
"Berkut" };
n = tabNazwisk.Length;
if (n != tabOcen.Length)
Console.WriteLine("źle!");
#endif
//dane testowe
//dane z konsoli
#if (!daneTestowe)
Console.WriteLine("Wpisz ile uczniów:");
while (!int.TryParse(Console.ReadLine(), out n) && n < 1)
Console.WriteLine("Błędna wartość podaj jeszcze raz:");
tabNazwisk
= new string[n
];
#endif
double suma = 0;
#region
for (int i = 1; i <= n; i++)
{
//dane z konsoli
#if (!daneTestowe)
Console.Write("Podaj nazwisko: ");
tabNazwisk[i - 1] = Console.ReadLine();
Console.WriteLine("Podaj ocene ucznia");
double oc;
Console.Write("Ocena: ", i);
while (!double.TryParse(Console.ReadLine(), out oc) ||
//oc < 2 || oc > 5)
// /* jest źle*/ (oc !=2 && oc !=3 && oc !=3.5 && oc !=4 && oc !=4.5 && oc !=5)
/*jest dobrze*/ !(oc == 2 || oc == 3 || oc == 3.5 || oc == 4 || oc == 4.5 || oc ==5)
)
Console.WriteLine("Błędna wartość, podaj jeszcze raz: ");
tabOcen[i - 1] = oc;
#endif
//dane testowe
#if (daneTestowe)
double oc = tabOcen[i - 1];
#endif
//koniec
suma = suma + oc;
suma2 = (oc * oc) + suma2;
if (oc == 2) ile2++;
if (oc == 5) ile5++;
if (oc != 5 && oc != 2)
sk = oc + sk;
j++;
}
#endregion
sr = suma / n;
foreach (var oc in tabOcen)
if (oc < sr)
iluGorszych++;
war = (suma2 / n) - (sr * sr);
Console.WriteLine("Średnia ocen to: {0}, a wariancja= {1:F1}", sr, war);
Console.WriteLine(" Ilość dwójek to {0}, ilość piątek to {1}, a ocen poniżej średniej: {2}", ile2, ile5, iluGorszych);
if (j != 0)
Console.WriteLine("Średnia srednich to: {0:F2}", sk / j);
//poczatek formatowania
string formatUO = " |{0,2}|{1,-22}|{2,5:F1}| ";
string naglUO = string.Format(formatUO, "Nr", "Nazwisko i imię", "Ocena");
string kreskaUO
= new string('=', naglUO
.Length);
/*
for ( int a=0; a<naglUO.Length/2; a++)
Console.WriteLine("/");
*/
//koniec
Console.WriteLine("n *** Lista z oceniami ndst *** ");
Console.WriteLine(naglUO + "n" + kreskaUO);
for (int i = 0; i < n; i++)
if (tabOcen[i] == 2)
Console.WriteLine(" |{0,2}|{1,-22}|{2,5:F1}| ", i+1, tabNazwisk[i], tabOcen[i]);
Console.WriteLine(kreskaUO);
Console.WriteLine("n *** Lista z oceniami bdb *** ");
Console.WriteLine(naglUO + "n" + kreskaUO);
for (int i = 0; i < n; i++)
if (tabOcen[i] == 5)
Console.WriteLine(" |{0,2}|{1,-22}|{2,5:F1}| ", i + 1, tabNazwisk[i], tabOcen[i]);
Console.WriteLine(kreskaUO);
Console.WriteLine("n *** Lista z oceniami poniżej sredniej *** ");
Console.WriteLine(naglUO + "n" + kreskaUO);
for (int i = 0; i < n; i++)
if (tabOcen[i] < sr)
Console.WriteLine(" |{0,2}|{1,-22}|{2,5:F1}| ", i + 1, tabNazwisk[i], tabOcen[i]);
Console.WriteLine(kreskaUO, "n");
Console.WriteLine(" Wciśnij dowolny klawisz...");
Console.ReadKey();
}
}
}