Facebook
From Emerald Crane, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 221
  1. using System;
  2.  
  3. namespace Kolokwium_KacperDec
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string wybor;
  10.             string[] produkt = new string[5];
  11.             produkt[0] = "Krzyżacy";
  12.             produkt[1] = "Pan Tadeusz";
  13.             produkt[2] = "Vabank";
  14.             produkt[3] = "Miś";
  15.             produkt[4] = "Seksmisja";
  16.             string[] rezyser = new string[5];
  17.             rezyser[0] = "Ford";
  18.             rezyser[1] = "Wajda";
  19.             rezyser[2] = "Machulski";
  20.             rezyser[3] = "Bareja";
  21.             rezyser[4] = "Machulski";
  22.             double[] cena = new double[5];
  23.             cena[0] = 15.5;
  24.             cena[1] = 14;
  25.             cena[2] = 15.5;
  26.             cena[3] = 17;
  27.             cena[4] = 18;
  28.             int[] czas = new int[5];
  29.             czas[0] = 185;
  30.             czas[1] = 155;
  31.             czas[2] = 155;
  32.             czas[3] = 120;
  33.             czas[4] = 120;
  34.             byte[] lp = new byte[5];
  35.             lp[0] = 1;
  36.             lp[1] = 2;
  37.             lp[2] = 3;
  38.             lp[3] = 4;
  39.             lp[4] = 5;
  40.  
  41.             bool NotEnd = true;
  42.             Poczatek();
  43.             Menu();
  44.             label: Console.WriteLine("Wybierz...");
  45.             wybor = Console.ReadLine();
  46.             do
  47.             {
  48.                 switch (wybor)
  49.                 {
  50.                     case "m":
  51.                         Menu();
  52.                         break;
  53.                     case "k":
  54.                         NotEnd = false;
  55.                         break;
  56.                     case "c":
  57.                         Console.Clear();
  58.                         break;
  59.                     case "w":
  60.                         TabelaLALA(lp,produkt,rezyser,cena,czas);
  61.                         return;
  62.                     case "nk":
  63.                         Najkrotszy(czas);
  64.                         return;
  65.                     case "nd":
  66.                         Najdluzszy(czas);
  67.                         return;
  68.                     case "rc":
  69.                         Losowy(lp, produkt, rezyser, cena, czas);
  70.                         return;
  71.                     case "l":
  72.                         Laczny(czas);
  73.                         return;
  74.                     case "sc":
  75.                         Srednia(czas);
  76.                         return;
  77.                     case "v":
  78.                         Wariacja(czas);
  79.                         return;
  80.                     case "sk":
  81.                         SredniKoszt(cena);
  82.                         return;
  83.                     case "sr":
  84.                         SzukajRez(rezyser);
  85.                         return;
  86.                     case "sf":
  87.                         SzukajFi(produkt);
  88.                         return;
  89.                     case "s<":
  90.                         KrotszyOd(czas);
  91.                         return;
  92.                     case "s>":
  93.                         DluzszyOd(czas);
  94.                         return;
  95.                     default:
  96.                         Console.WriteLine("Podałeś złą komendę.");
  97.                         goto label;
  98.  
  99.  
  100.                    
  101.                 }
  102.             }
  103.             while (NotEnd);
  104.             Console.WriteLine("Naciśnij dowolny klawisz aby zakończyć program...");
  105.         }
  106.         static void Menu()
  107.         {
  108.             Console.WriteLine("******************MENU******************");
  109.             Console.WriteLine("\tm - wyświetli Menu");
  110.             Console.WriteLine("\tk - kończy program");
  111.             Console.WriteLine("\tc - czyści konsolę");
  112.             Console.WriteLine();
  113.             Console.WriteLine("\tw - wyświetli tabelę");
  114.             Console.WriteLine("\trc - losowy czas trwania 100 - 200 1");
  115.             Console.WriteLine("\tnk - najkrótszy film");
  116.             Console.WriteLine("\tnd - najdłuższy film");
  117.             Console.WriteLine("\tl - łączny czas trwania wszystkich filmów");
  118.             Console.WriteLine("\tsc - średni czas trwania filmu");
  119.             Console.WriteLine("\ts< - szukaj filmów krótszego od podanego czasu");
  120.             Console.WriteLine("\ts> - szukaj filmu dłuższego od podanego czasu");
  121.             Console.WriteLine("\tv - wariacja czasu trwania filmu");
  122.             Console.WriteLine("\tsk - średni koszt wypożyczenia filmu");
  123.             Console.WriteLine("\tsr szukaj reżysera");
  124.             Console.WriteLine("\tsf - szukaj filmu");
  125.             Console.WriteLine("\tz - zmień");
  126.             Console.WriteLine("****************************************");
  127.         }
  128.         static void Poczatek()
  129.         {
  130.             Console.WriteLine("*** *** Wypożyczalnia Filmów *** ***");
  131.             Console.WriteLine("Wykonał Kacper Dec");
  132.         }
  133.         static void TabelaLALA(byte[] lp, string[] produkt, string[] rezyser, double[] cena, int[] czas)
  134.         {
  135.             Console.WriteLine("---------------------------------------------------------------");
  136.             Console.WriteLine("| Lp.    | Produkt    | Reżyser     | Cena     | Czas     |");
  137.             Console.WriteLine("---------------------------------------------------------------");
  138.             for (int i = 0; i<lp.Length; i++)
  139.             {
  140.                 Console.WriteLine("|{0}        |{1}     |{2}     |{3}     |{4}     |", lp[i], produkt[i], rezyser[i], cena[i], czas[i]);
  141.             }
  142.             Console.WriteLine("---------------------------------------------------------------");
  143.             Menu();
  144.         }
  145.          static void Najkrotszy(int[] czas)
  146.         {
  147.             int wynik = 120;
  148.             for (int i = 0; i < czas.Length; i++)
  149.             {
  150.                 if (wynik > czas[i])
  151.                 {
  152.                     wynik = czas[i];
  153.                 }
  154.             }
  155.             Console.WriteLine("Najkrótszy film trwa: " + wynik);
  156.         }
  157.          static void Najdluzszy(int[] czas)
  158.         {
  159.             int wynik = 0;
  160.             for (int i = 1; i < czas.Length; i++)
  161.             {
  162.                 if (wynik < czas[i])
  163.                 {
  164.                     wynik = czas[i];
  165.                 }
  166.             }
  167.          
  168.             Console.WriteLine("Najdłuższy film trwa 185");
  169.         }
  170.         static void Losowy(byte[] lp, string[] produkt, string[] rezyser, double[] cena, int[] czas)
  171.         {
  172.             Random rnd = new Random();
  173.             for (int i = 0; i < czas.Length; i++)
  174.             {
  175.                 czas[i] = rnd.Next(100, 200);
  176.             }
  177.             Console.WriteLine("---------------------------------------------------------------");
  178.             Console.WriteLine("| Lp.    | Produkt    | Reżyser     | Cena     | Czas     |");
  179.             Console.WriteLine("---------------------------------------------------------------");
  180.             for (int i = 0; i < lp.Length; i++)
  181.             {
  182.                 Console.WriteLine("|{0}        |{1}     |{2}     |{3}     |{4}     |", lp[i + 1], produkt[i], rezyser[i], cena[i], czas[i]);
  183.             }
  184.             Console.WriteLine("---------------------------------------------------------------");
  185.         }
  186.        static void Laczny(int[] czas)
  187.         {
  188.             int w;
  189.             w = czas[0] + czas[1] + czas[2] + czas[3] + czas[4];
  190.             Console.WriteLine("Łączny czas trwania filmów to: {0} minut(y)", w);
  191.         }
  192.        static void Srednia(int[] czas)
  193.         {
  194.             double suma = 0, sr = 0;
  195.             for (int i = 0; i < czas.Length; i++)
  196.             {
  197.                 suma += czas[i];
  198.             }
  199.             sr = suma / czas.Length;
  200.             Console.WriteLine("Średni czas trwania filmu wynosi: {0} minut(y)", sr);
  201.  
  202.         }
  203.         static void Wariacja(int[] czas)
  204.         {
  205.             double suma = 0, sr = 0, wariacja = 0;
  206.             for (int i = 0; i < czas.Length; i++)
  207.             {
  208.                 suma += czas[i];
  209.             }
  210.             sr = suma / czas.Length;
  211.  
  212.             for (int i = 0; i < czas.Length; i++)
  213.             {
  214.                 wariacja += (czas[i] - sr) * (czas[i] - sr);
  215.             }
  216.             wariacja = wariacja / czas.Length;
  217.             Console.WriteLine("Wariacja wynosi {0}", wariacja);
  218.         }
  219.        static void SredniKoszt(double[] cena)
  220.         {
  221.             double suma = 0, sr = 0;
  222.             for (int i = 0; i < cena.Length; i++)
  223.             {
  224.                 suma += cena[i];
  225.             }
  226.             sr = suma / cena.Length;
  227.             Console.WriteLine("Średni koszt wypożyczenia filmu to: {0}", sr);
  228.         }
  229.        static void SzukajRez(string[] rezyser)
  230.         {
  231.             Console.Write("Podaj nazwisko: ");
  232.             string nazw;
  233.             nazw = Console.ReadLine();
  234.             for (int i = 0; i < rezyser.Length; i++)
  235.             {
  236.                 if (rezyser[i] == nazw)
  237.                 {
  238.                     Console.WriteLine("Odnaleziono element " + nazw + " pod indeksem " + i);
  239.                 }
  240.  
  241.             }
  242.  
  243.         }
  244.         static void SzukajFi(string[] produkt)
  245.         {
  246.             Console.Write("Podaj tytuł: ");
  247.             string nazw;
  248.             nazw = Console.ReadLine();
  249.             for (int i = 0; i < produkt.Length; i++)
  250.             {
  251.                 if (produkt[i] == nazw)
  252.                 {
  253.                     Console.WriteLine("Odnaleziono element " + nazw + " pod indeksem " + i);
  254.                 }
  255.  
  256.             }
  257.         }
  258.          static void KrotszyOd(int[] czas)
  259.         {
  260.             Console.Write("Wprowadź liczbę: ");
  261.             int ew;
  262.             ew = Convert.ToInt32(Console.ReadLine());
  263.             for (int i = 0; i<czas.Length;i++)
  264.             {
  265.                 if (ew>czas[i])
  266.                 {
  267.                     Console.WriteLine("Odnaleziono element pod indeksem " + i);
  268.                 }
  269.             }
  270.         }
  271.        static void DluzszyOd(int[] czas)
  272.         {
  273.             Console.Write("Wprowadź liczbę: ");
  274.             int ew;
  275.             ew = Convert.ToInt32(Console.ReadLine());
  276.             for (int i = 0; i < czas.Length; i++)
  277.             {
  278.                 if (ew < czas[i])
  279.                 {
  280.                     Console.WriteLine("Odnaleziono element pod indeksem " + i);
  281.                 }
  282.             }
  283.         }
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.     }
  296.  
  297.     }
  298.