Facebook
From kaja, 6 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 253
  1. #define daneTestowe
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Program
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int ileaut, ileTańszych = 0,x;
  15.          
  16.             double sr, suma2 = 0, war;
  17.             string[] tabMarek;
  18.             double[] tabCen;
  19.            
  20.             Console.WriteLine("KOMIS SAMOCHODOWY");
  21.             //dane testowe
  22. #if (daneTestowe)
  23.             tabCen = new double[] { 12000,4500,9000,7800,520000,2648,370000,900000,4200,10000 };
  24.             tabMarek = new string[] { "Opel", "Ford", "BMW", "Audi", "Lambo", "Opel", "Porshe", "Ferrari", "Citroen", "Mercedes" };
  25.             ileaut = tabMarek.Length;
  26.             if (ileaut != tabCen.Length)
  27.                 Console.WriteLine("źle!");
  28. #endif
  29.             //dane testowe
  30.  
  31.             //dane z konsoli
  32.  
  33. #if (!daneTestowe)
  34.             Console.WriteLine("Wpisz ile aut:");
  35.             while (!int.TryParse(Console.ReadLine(), out ileaut) && ileaut <= 0)
  36.                 Console.WriteLine("Błędna wartość podaj jeszcze raz:");
  37.  
  38.             tabCen = new double[ileaut];
  39.             tabMarek= new string[ileaut];
  40. #endif
  41.             double suma = 0;
  42.  
  43.             #region
  44.             for (int i = 1; i <= ileaut; i++)
  45.             {
  46.                 //dane z konsoli
  47. #if (!daneTestowe)
  48.     Console.Write("Podaj marke: ");
  49.                 tabMarek[i - 1] = Console.ReadLine();
  50.  
  51.                 Console.WriteLine("Podaj cene auta");
  52.                 double ce;
  53.                 Console.Write("Cena: ", i);
  54.                 while (!double.TryParse(Console.ReadLine(), out ce) ||ce < 0)
  55.                  
  56.                        Console.WriteLine("Błędna wartość, podaj jeszcze raz: ");
  57.                 tabCen[i - 1] = ce;
  58. #endif
  59.                 //dane testowe
  60. #if (daneTestowe)
  61.                 double ce = tabCen[i - 1];
  62.  
  63. #endif
  64.                 //koniec
  65.                 suma = suma + ce;
  66.                 suma2 = (ce * ce) + suma2;
  67.                
  68.  
  69.             }
  70.             #endregion
  71.             sr = suma / ileaut;
  72.             foreach (var oc in tabCen)
  73.                 if (oc < sr)
  74.                     ileTańszych++;
  75.  
  76.             war = (suma2 / ileaut) - (sr * sr);
  77.  
  78.  
  79.             Console.WriteLine("Średnia cena to: {0:F2}, a wariancja= {1:F1}", sr, war);
  80.             Console.WriteLine(" Ilość cen poniżej średniej: {0}", ileTańszych);
  81.  
  82.             //poczatek formatowania
  83.             string formatUO = " |{0,2}|{1,-22}|{2,10:F1}| ";
  84.             string naglUO = string.Format(formatUO, "Nr", "   Nazwisko i imię", "  Ocena   ");
  85.             string kreskaUO = new string('=', naglUO.Length);
  86.          
  87.             /*
  88.              for ( int a=0; a<naglUO.Length/2; a++)
  89.              Console.WriteLine("/\");
  90.               */
  91.             //koniec
  92.  
  93.          
  94.             Console.WriteLine("\n *** Lista aut poniżej sredniej ceny *** ");
  95.             Console.WriteLine(naglUO + "\n" + kreskaUO);
  96.             for (int i = 0; i < ileaut; i++)
  97.                 if (tabCen[i] < sr)
  98.                     Console.WriteLine(formatUO, i + 1, tabMarek[i], tabCen[i]);
  99.             Console.WriteLine(kreskaUO, "\n");
  100.  
  101.             Console.WriteLine("\n *** Lista aut powyżej sredniej ceny *** ");
  102.             Console.WriteLine(naglUO + "\n" + kreskaUO);
  103.             for (int i = 0; i < ileaut; i++)
  104.                 if (tabCen[i] > sr)
  105.                     Console.WriteLine(formatUO, i + 1, tabMarek[i], tabCen[i]);
  106.             Console.WriteLine(kreskaUO, "\n");
  107.  
  108.             Console.WriteLine("Jaka Marka Cię interesuje?");
  109.             string szuk = Console.ReadLine();
  110.             Console.WriteLine(" \n *** Lista pojazdów: {0}, szuk");
  111.             Console.WriteLine(naglUO + "\n" + kreskaUO);
  112.             for (int i = 0; i < ileaut; i++)
  113.                 if (tabMarek[i] == szuk)
  114.                     Console.WriteLine(formatUO, i + 1, tabMarek[i], tabCen[i]);
  115.             Console.WriteLine(kreskaUO, "\n");
  116.  
  117.  
  118.  
  119.             //x=Console.ReadLine();
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.             Console.WriteLine(" Wciśnij dowolny klawisz...");
  129.             Console.ReadKey();
  130.  
  131.         }
  132.     }
  133. }
  134.