#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 ileaut, ileTańszych = 0,x;
double sr, suma2 = 0, war;
string[] tabMarek;
double[] tabCen;
Console.WriteLine("KOMIS SAMOCHODOWY");
//dane testowe
#if (daneTestowe)
tabCen
= new double[] { 12000,
4500,
9000,
7800,
520000,
2648,
370000,
900000,
4200,
10000 };
tabMarek
= new string[] { "Opel",
"Ford",
"BMW",
"Audi",
"Lambo",
"Opel",
"Porshe",
"Ferrari",
"Citroen",
"Mercedes" };
ileaut = tabMarek.Length;
if (ileaut != tabCen.Length)
Console.WriteLine("źle!");
#endif
//dane testowe
//dane z konsoli
#if (!daneTestowe)
Console.WriteLine("Wpisz ile aut:");
while (!int.TryParse(Console.ReadLine(), out ileaut) && ileaut <= 0)
Console.WriteLine("Błędna wartość podaj jeszcze raz:");
tabCen
= new double[ileaut
];
tabMarek
= new string[ileaut
];
#endif
double suma = 0;
#region
for (int i = 1; i <= ileaut; i++)
{
//dane z konsoli
#if (!daneTestowe)
Console.Write("Podaj marke: ");
tabMarek[i - 1] = Console.ReadLine();
Console.WriteLine("Podaj cene auta");
double ce;
Console.Write("Cena: ", i);
while (!double.TryParse(Console.ReadLine(), out ce) ||ce < 0)
Console.WriteLine("Błędna wartość, podaj jeszcze raz: ");
tabCen[i - 1] = ce;
#endif
//dane testowe
#if (daneTestowe)
double ce = tabCen[i - 1];
#endif
//koniec
suma = suma + ce;
suma2 = (ce * ce) + suma2;
}
#endregion
sr = suma / ileaut;
foreach (var oc in tabCen)
if (oc < sr)
ileTańszych++;
war = (suma2 / ileaut) - (sr * sr);
Console.WriteLine("Średnia cena to: {0:F2}, a wariancja= {1:F1}", sr, war);
Console.WriteLine(" Ilość cen poniżej średniej: {0}", ileTańszych);
//poczatek formatowania
string formatUO = " |{0,2}|{1,-22}|{2,10: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 aut poniżej sredniej ceny *** ");
Console.WriteLine(naglUO + "\n" + kreskaUO);
for (int i = 0; i < ileaut; i++)
if (tabCen[i] < sr)
Console.WriteLine(formatUO, i + 1, tabMarek[i], tabCen[i]);
Console.WriteLine(kreskaUO, "\n");
Console.WriteLine("\n *** Lista aut powyżej sredniej ceny *** ");
Console.WriteLine(naglUO + "\n" + kreskaUO);
for (int i = 0; i < ileaut; i++)
if (tabCen[i] > sr)
Console.WriteLine(formatUO, i + 1, tabMarek[i], tabCen[i]);
Console.WriteLine(kreskaUO, "\n");
Console.WriteLine("Jaka Marka Cię interesuje?");
string szuk = Console.ReadLine();
Console.WriteLine(" \n *** Lista pojazdów: {0}, szuk");
Console.WriteLine(naglUO + "\n" + kreskaUO);
for (int i = 0; i < ileaut; i++)
if (tabMarek[i] == szuk)
Console.WriteLine(formatUO, i + 1, tabMarek[i], tabCen[i]);
Console.WriteLine(kreskaUO, "\n");
//x=Console.ReadLine();
Console.WriteLine(" Wciśnij dowolny klawisz...");
Console.ReadKey();
}
}
}